This manual is deprecated. Please visit https://groupoffice.readthedocs.io for the latest documentation.

Difference between revisions of "Event handling"

From Group-Office Groupware and CRM Documentation
Jump to: navigation, search
Line 30: Line 30:
 
}
 
}
 
</pre>
 
</pre>
 +
 +
After creating new listeners you must reload Group-Office so it will call the initListeners function.

Revision as of 09:47, 9 July 2012

Group-Office fires event on certain actions. You can attach your own functions to do specific actions on these events. To do this create a new module.

eg. modules/myevent.

Inside this folder create the file MyeventModule.php:

class GO_Filesearch_MyeventModule extends GO_Base_Module{	
	
	public static function initListeners() {
		GO_Files_Model_File::model()->addListener('save', 'GO_Myevent_MyeventModule', 'save');
		GO_Files_Model_File::model()->addListener('delete', 'GO_Myevent_MyeventModule', 'delete');
		
		//attaching to a controller works a bit different
		$c = new GO_Core_Controller_Maintenance();
		$c->addListener('someAction', 'GO_Myevent_MyeventModule', 'doSomething');
	}
	
	public static function save(&$file){
		//do something with the file module here		
	}

	public static function delete(&$file){
		//do something with the file module here		
	}

	public static function doSomething(){
		//do something with the file module here		
	}
}

After creating new listeners you must reload Group-Office so it will call the initListeners function.