|
@@ -96,6 +96,7 @@ abstract class DBObject implements iDisplay
|
|
|
protected $m_aModifiedAtt = array(); // list of (potentially) modified sAttCodes
|
|
|
protected $m_aSynchroData = null; // Set of Synch data related to this object
|
|
|
protected $m_sHighlightCode = null;
|
|
|
+ protected $m_aCallbacks = array();
|
|
|
|
|
|
// Use the MetaModel::NewObject to build an object (do we have to force it?)
|
|
|
public function __construct($aRow = null, $sClassAlias = '', $aAttToLoad = null, $aExtendedDataSpec = null)
|
|
@@ -1584,6 +1585,15 @@ abstract class DBObject implements iDisplay
|
|
|
$oTrigger->DoActivate($this->ToArgs('this'));
|
|
|
}
|
|
|
|
|
|
+ // Callbacks registered with RegisterCallback
|
|
|
+ if (isset($this->m_aCallbacks[self::CALLBACK_AFTERINSERT]))
|
|
|
+ {
|
|
|
+ foreach ($this->m_aCallbacks[self::CALLBACK_AFTERINSERT] as $aCallBackData)
|
|
|
+ {
|
|
|
+ call_user_func_array($aCallBackData['callback'], $aCallBackData['params']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
$this->RecordObjCreation();
|
|
|
|
|
|
return $this->m_iKey;
|
|
@@ -2242,7 +2252,17 @@ abstract class DBObject implements iDisplay
|
|
|
$iStartTime = AttributeDateTime::GetAsUnixSeconds($this->Get($sRefAttCode));
|
|
|
$oStartDate = new DateTime('@'.$iStartTime); // setTimestamp not available in PHP 5.2
|
|
|
$oEndDate = new DateTime(); // now
|
|
|
+
|
|
|
+ if (class_exists('WorkingTimeRecorder'))
|
|
|
+ {
|
|
|
+ $sClass = get_class($this);
|
|
|
+ WorkingTimeRecorder::Start($this, time(), "DBObject-SetElapsedTime-$sAttCode-$sRefAttCode", 'Core:ExplainWTC:ElapsedTime', array("Class:$sClass/Attribute:$sAttCode"));
|
|
|
+ }
|
|
|
$iElapsed = call_user_func($aCallSpec, $this, $oStartDate, $oEndDate);
|
|
|
+ if (class_exists('WorkingTimeRecorder'))
|
|
|
+ {
|
|
|
+ WorkingTimeRecorder::End();
|
|
|
+ }
|
|
|
|
|
|
$this->Set($sAttCode, $iElapsed);
|
|
|
return true;
|
|
@@ -2800,6 +2820,28 @@ abstract class DBObject implements iDisplay
|
|
|
}
|
|
|
$oPage->details($aValues);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ const CALLBACK_AFTERINSERT = 0;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Register a call back that will be called when some internal event happens
|
|
|
+ *
|
|
|
+ * @param $iType string Any of the CALLBACK_x constants
|
|
|
+ * @param $callback callable Call specification like a function name, or array('<class>', '<method>') or array($object, '<method>')
|
|
|
+ * @param $aParameters Array Values that will be passed to the callback, after $this
|
|
|
+ */
|
|
|
+ public function RegisterCallback($iType, $callback, $aParameters = array())
|
|
|
+ {
|
|
|
+ $sCallBackName = '';
|
|
|
+ if (!is_callable($callback, false, $sCallBackName))
|
|
|
+ {
|
|
|
+ throw new Exception('Registering an unknown/protected function or wrong syntax for the call spec: '.$sCallBackName);
|
|
|
+ }
|
|
|
+ $this->m_aCallbacks[$iType][] = array(
|
|
|
+ 'callback' => $callback,
|
|
|
+ 'params' => $aParameters
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
|