Skip to content

Instantly share code, notes, and snippets.

@jasondavis
Forked from jmertic/gist:6272437
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasondavis/d39b8fee4f5a2df30041 to your computer and use it in GitHub Desktop.
Save jasondavis/d39b8fee4f5a2df30041 to your computer and use it in GitHub Desktop.
<?php
class FieldChangeHook
{
protected static $fetchedRow = array();
/**
* Called as before_save logic hook to grab the fetched_row values
*/
public function saveFetchedRow($bean, $event, $arguments)
{
if ( !empty($bean->id) ) {
self::$fetchedRow[$bean->id] = $bean->fetched_row;
}
}
/**
* Called as a after_save logic hook to execute the actual business process
*/
public function executeBusinessProcess($bean, $event, $arguments)
{
// call on changed records only
if ( isset(self::$fetchedRow[$bean->id]) && $this->fieldname != self::$fetchedRow[$bean->id]['fieldname'] ) {
//
// execute changed record business process
//
}
// call on new records only
if ( !isset(self::$fetchedRow[$bean->id]) ) {
//
// execute new record business process
//
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment