====== Table Scripting in the Vortex ====== To customize the behaviour of the Vortex there is the possibility for per Table scripting. Here you can trigger events like beforeSave and afterLoad, but you can also configure and script custom scripts that can be activated by the user via the GUI. This chapter will describe the Table scripting in more detail. ==== Location of the script ==== All the custom scripts are placed in the /script folder in the DBI. All .php files in this path will be included and parsed at load time, and all scripts following the right name stanard will be used as per Table scripts, or as the CommandLine script class. The name of the file is not important, however we recommend giving the files logical names like //MyTableScript.php// for the file containing scripts for //MyTable//. Helper classes can be put in separate files or in the same files as the scripts, they will all be loaded and parsed. ==== Naming the class ==== The Vortex identifies scripts by the class name of the class containing the methods. For per Table scripts the name of the class should be //Script[tablename]// where tablename is all lowercase. For instance, if we were to create scripts for the table //MyTable// the class would be named //Scriptmytable//. To make scripts valid for all tables they can be added to the class //Script_general// which works in the same way as normal per-table scripts. Methods are first sought in the per-table script so general scripts can be overridden on a per-table basis by adding the same method/script to the table specific class. ===== Triggered events ===== The following events will be triggered while running the Vortex. All methods are declared - and run - statically. ==== beforeLoad ==== **Parameters:** &$object, &$cancel\\ This method is called before a TableRecord is loaded from the database. The passed parameters are the $object which is to load and a boolean $cancel which per default is set to false. Here you can do pre-loading processing, and if the $cancel variable is set to true when returning from this method the TableRecord will not load. ==== afterLoad ==== **Parameters:** &$object, &$cancel\\ This method is called after a TableRecord is loaded from the database. The passed parameters are the $object which is to load and a boolean $cancel which per default is set to false. Here you can do post-loading processing, and if the $cancel variable is set to true when returning from this method the TableRecord will not load. ==== beforeSave ==== **Parameters:** &$object, &$cancel\\ This method is called before a TableRecord is saved to the database. The passed parameters are the $object which is to be saved and a boolean $cancel which per default is set to false. Here you can do pre-save processing, and if the $cancel variable is set to true when returning from this method the TableRecord will not be saved. ==== afterSave ==== **Parameters:** &$object, &$cancel\\ This method is called after a TableRecord is saved to the database. The passed parameters are the $object which is to be saved and a boolean $cancel which per default is set to false. Here you can do post-save processing. Since the record has already been saved to the database, setting the $cancel flag will make no difference here. Please use caution when changing parameters in the $object in the afterSave method, since making the TableRecord dirty will cause the Vortex to save the $object again, possibly casuing an endless loop. ==== beforeUpdate ==== **Parameters:** &$field, &$cancel\\ This method is called before a field is updated in the TableRecord. The $field parameter contains the Field that will be changed, and if the $cancel flag is set true when returning the value of the Field will not be updated. ==== afterUpdate ==== **Parameters:** &$field, &$cancel\\ This method is called after a field has been updated in the TableRecord. The $field parameter contains the Field that has been changed. Since the change has already been done, the $cancel flag has no function in this method. ===== Overview ===== To customize the appearance of the details view for the scripted Table, there is a possibility to add an Overview category. This will be shown as a normal category in the details view, will always be open per default and show at the top of the details view.\\ The Vortex checks the Table specific Class for a static method called _overview. If this exists, it calls the method with the parameter //&$object// which is the object for which the overview is to be shown. The _overview method returns pure HTML code, which is shown in the overview category of the details view. class Scriptmytable { public static function _overview( &$myTableRecord ) { return "Some overview here"; } } ===== Table Summary ===== For every table there is the possibility to create a custom summary header showing information about the current table. The summary will be shown in the ShowList view and in the details view for all TableRecords in the table.\\ The Vortex checks the Table specific Class, or the _general class, for a static method called _summary. If the method exists it is called with the parameter //&$table// which is a reference to the current table. The _summary method works in the same way as the _overview and returns HTML code which is shown in the header. class Scriptmytable { public static function _summary( &$table ) { return "MySummary for table " . $table->get( 'name' ) . ""; } } ===== GUI Activated Scripts ===== GUI Activated scripts are represented by an icon in the top section of the ShowList or the Details view. Theese scripts are placed in the same Table specific class as all the other scripts regarding that table. To define the scripts, the variable $SCRIPTS is defined statically in the class as an XML string defining the scripts available for this Table. class Scriptmytable { public static $SCRIPTS = '