Resetting the value of a check box field for all records

10 posts by 3 authors in: Forums > CMS Builder
Last Post: June 17, 2010   (RSS)

By gkornbluth - November 16, 2009 - edited: November 16, 2009

I’ve created a membership section editor with a check box field that displays a member’s current year payment status.

On January 1 (or another date of their choosing) my client would like to have the value of that field in all records automatically revert to “0"

Short of having them delete the field and then recreate it (which sends shivers up my spine), is there any way to automatically reset the value of a field for all records in the table?

Thanks,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Resetting the value of a check box field for all records

By Dave - November 16, 2009

Hi Jerry,

I can't think of anything built in that could reset a field value like that.

If you are comfortable with MySQL and you have something like phpMyAdmin you can reset the value of a field with this query:

UPDATE cms_tablename SET fieldname = 0

Other ways to do it (especially if you wanted it to happen automatically) would be to make a plugin to do it.

Also, we're working on a "MySQL Console" plugin which will let you run custom MySQL queries from within CMS Builder (for advanced users).
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Resetting the value of a check box field for all records

Thanks Dave,

I was hoping to implement this in a way that the client could not break.

I guess that I'll reset the fields until a better solution appears.


Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [Dave] Resetting the value of a check box field for all records

By gkornbluth - June 12, 2010

Hi Dave,

Now that you've all been working with plugins for a while, I thought I'd revisit this one again.

Thanks,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Resetting the value of a check box field for all records

By carl2 - June 15, 2010

Hi Jerry,

I've had a look into this and I could make a plugin that adds something to the 'Advanced Command' dropdown on the table list page. That way you or your client could manually reset the field. Would that be okay for you?

Carl

Re: [carl] Resetting the value of a check box field for all records

By gkornbluth - June 15, 2010

Thanks Carl,

That would be great as long as it was available to admins only, not editors. Possibly by a "Super Admin" only or a special 2 step process?

It's a pretty powerful command and shouldn't be able to be accessed easily or casually.

Just my paranoia about the "oops" factor.

Best,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Resetting the value of a check box field for all records

By carl2 - June 16, 2010

Hi Jerry,

A 'super-admin' user would be more convoluted and would require changes to your database and so on, though. However I can certainly make it only accessible to admin users.

Alternatively if you really don't want anyone but one user to have access, it could just be a standalone script with some obscure URL. So you or your client would visit /some_script_name.php to perform the update. You could also automate that with a cronjob.

Carl

Re: [carl] Resetting the value of a check box field for all records

By gkornbluth - June 16, 2010

Sounds good.Carl,

I guess I could create a "Super Admin' with the membership module, the same way I've restricted page access based on membership levels.

I'm a little gun shy when it comes to globally changing anything in the database. So I really appreciate your help and look forward to seeing what you come up with.

Best,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Resetting the value of a check box field for all records

By carl2 - June 17, 2010

Hi Jerry,

I've attached a plugin you can use that will add this functionality. You will need to add some information at the top: the table and field name that you want to reset, and the value to reset it to. For example, if you want to set the value of 'paid' to '0' on all records in the 'accounts' table, add this near the top where the comments tell you to:

array( 'tableName' => 'accounts', 'fieldName' => 'paid', 'resetValue' => 0 )

Once you have enabled the plugin, in the 'Advanced Commands' section, there will be the option to set the fields on all records.

Right now it will only make the option available to admins. If you wanted to have a 'super admin', then you could add a checkbox field to your Accounts section called 'super_admin' and change the check on line 27 to

if ( !$CURRENT_USER['super_admin'] ) return;

Let me know if this works for you or if you have any problems getting it to work!

Carl