Modifying behaviour

To have a bit if control over how data is saved to the database, you can use the validation or post processing classes.

To add validation or default values, create a file under local/ named validateclass_tablename.php. As with new forms, there's a template file called validateclass_template that you can use as a starting point.

The class name has to be Validator_tablename, there are four methods, checkContent is called for all types for updates and allows you to add default values and do general checks. isInsertOK, isUpdateOK, and isDeleteOk allows you to return false if you want to prevent any of those operations for any reason. $this->getOldValues() and $this->getNewValues() can be used to get the content of the record before and after it was changed by the user. $this->setValue(fieldname,new value) can be used to update the new values stored to the database. Note, it's not allowed to do any changes to the database in the validate classes. The functions here can be called several times before the record is saved and this can give duplicates in the database.

If you want to update the database, you will have to use the post processing classes. They are called postprocessclass_tablename.php and as usual there is a template file called share/postprocessclass_template.php that can be copied. Your new file has to be called local/postprocessclass_tablename.php and the class defined in it has to be Postprocessor_tablename.

There is only one function in post processing; process. $this->getOldValues() and $this->getNewValues() are available here as well and return the same values as they do in the validation classes. The process function is called after the database is updated, if the operation was an insert and the table contained an auto_increment field the new value will be available in the array returned by the getOldValues() function. Since this is called after the insert/update/delete is done, it's to late to do anything about that, it's very handy to be able to update cached values in other tables, make summaries, or do other things that should be done to keep the database on track. Anything done here could also be done in triggers in the database.