User Tools

Site Tools




Table Methods in the Vortex

To make scripting the Vortex more straightforward there is the possibility to add custom methods to the TableRecord class. The methods are added per Table by using a Methods-class for each table containing custom methods. The methods in this class will be called when calling the method on a TableRecord instance with a reference to the right Table.

Location of the script

All the method classes 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 classes following the right name stanard will be used as per Table methods. The name of the file is not important, however we recommend giving the files logical names like MyTableMethods.php for the file containing methods 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 Method-classes by the class name. The name of the class should be Method[tablename] where tablename is all lowercase. For instance, if we were to create a class for the table MyTable the class would be named Methodmytable.

General methods can be added to all TableRecords by adding them to the Method_general class.

Using custom methods

This is a small example of how to use the custom method functionallity.

This is the implementation of a custom method for the MyTable table:

class Methodmytable {
  public static function testFunction( $arg1, $arg2, &$mytable ) {
    $mytable->set( 'tested', true );
    return sprintf( "testing for $arg1 and $arg2 on %s", $mytable->get( 'myField' ) );

This is the call to the method from somewhere else in some other class.

  $mytable = TableRecordFactory::getTableRecord( 'MyTable', 0 );   // Create a new instance of MyTable TableRecord
  $mytable->set( 'myField', 'abc123' );   // Set the field accordingly
  $retVal = $mytable->testFunction( 'a', 'b' );

After this the $retVal will contain the value “testing for a and b on abc123”.

Note how the &$mytable instance is never sent with the call. The calling instance is automatically appended to the parameter list in all calls.

vortex/scripting/tablemethods.txt · Last modified: 2019/06/28 06:54 by hubbe