Free/Premium User implementation

Hi,

can someone give me hints how to implement a free/premium user in a project?

Let assume a free user can only have 20 entries in a specific database table for which a model is present.

Any suggestions how to do this?

//EDIT:

I know i can make a count on the table to check the existing entries, but are there better ways to achieve this?

Thanks,

corvus

there are more than one way to tackle this problem you can have table structure something like

id

username // varchar

password // varchar

free // boolean true if account type is free

cache_counter // int act as record counter

disabled // boolean in case you wanna disable it

when you create a entry you can update the cacheCounter by 1 and then you also check it user has reached the limit this for free use

yes i know. but with this i have to check everywhere before i insert if the maximum is reached.

i search a way i can put it in a class/behavior/whatever which i use everywhere and this checks all limitations…

but how you gonna keep record of that client has reached the limit it has be in the database let me know if you find something

You should probably create a custom validator class:

http://www.yiiframework.com/wiki/168/create-your-own-validation-rule/

See specifically the section titled Complete approach: extending the CValidator class.

keith you not getting it what i am trying to say in any case you have to do a extra query you cant avoid that