Hook function

From TUTOS

While running TUTOS will call customizable hook functions at various points in time. You can use and run whatever php allows here. The functions will be called with the object as the one and only arguement.

Types of hooks

Currently TUTOS knows about these types of hooks.

presave

Run before saving.

postsave

Run after saving.

postdel

Run after an object is deleted. A good place to inform external objects about the deletion.

check

Called when submitting data to the database. A good chance to bounce back when unsatisfied with users input.

afterread

Called after reading in data from the database.

postinit

Run after initializing an object. Here is a good place to preset data. This hooks are stored in the $tutos['postinit-hooks'][OBJECTTYPENAME] array.

Example

Preset all projectnames with PLEASE USE OFFICIAL PROJECTNUMBER and always set a version number.

To do so add the following lines in config.php

function hook1($obj) {
	$obj->name = 'PLEASE USE OFFICIAL PROJECTNUMBER';
}
$tutos['postinit-hooks']['product'][] = 'hook1';

function hook2($obj) {
	$msg = '';
	if ($obj->version == '') {
		$obj->version = '1';
		$msg = 'automated version correction';
	}
	return $msg;
}
$tutos['presave-hooks']['product'][] = 'hook2';

Notice

This feature started with version after 1.5.20090629 and is still under development (i.e. not all objects and situations are supported)