/** * Stop counting if not already done */ public function Stop($oObject, $oAttDef, $iNow = null) { if (is_null($this->iLastStart)) { // Already stopped return false; } if (is_null($iNow)) { $iNow = time(); } if (class_exists('WorkingTimeRecorder')) { $sClass = get_class($oObject); $sAttCode = $oAttDef->GetCode(); WorkingTimeRecorder::Start($oObject, $iNow, "ormStopWatch-TimeSpent-{$sAttCode}", 'Core:ExplainWTC:StopWatch-TimeSpent', array("Class:{$sClass}/Attribute:{$sAttCode}"), true); } $iElapsed = $this->ComputeDuration($oObject, $oAttDef, $this->iLastStart, $iNow); $this->iTimeSpent = $this->iTimeSpent + $iElapsed; if (class_exists('WorkingTimeRecorder')) { WorkingTimeRecorder::End(); } foreach ($this->aThresholds as $iPercent => &$aThresholdData) { if (!is_null($aThresholdData['deadline']) && $iNow > $aThresholdData['deadline']) { if ($aThresholdData['overrun'] > 0) { // Accumulate from last start $aThresholdData['overrun'] += $iElapsed; } else { // First stop after the deadline has been passed $iOverrun = $this->ComputeDuration($oObject, $oAttDef, $aThresholdData['deadline'], $iNow); $aThresholdData['overrun'] = $iOverrun; } } $aThresholdData['deadline'] = null; } $this->iLastStart = null; $this->iStopped = $iNow; return true; }
/** * Lifecycle action: Set the time elapsed since a reference point */ public function SetElapsedTime($sAttCode, $sRefAttCode, $sWorkingTimeComputer = null) { if (is_null($sWorkingTimeComputer)) { $sWorkingTimeComputer = class_exists('SLAComputation') ? 'SLAComputation' : 'DefaultWorkingTimeComputer'; } $oComputer = new $sWorkingTimeComputer(); $aCallSpec = array($oComputer, 'GetOpenDuration'); if (!is_callable($aCallSpec)) { throw new CoreException("Unknown class/verb '{$sWorkingTimeComputer}/GetOpenDuration'"); } $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; }