/**
  * 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;
 }
Example #2
0
 /**
  * Get duration (considering only open hours) elapsed bewteen two given DateTimes
  * @param $oObject DBObject The object for which to compute the duration
  * @param $oStartDate DateTime The starting point for the computation (default = now)
  * @param $oEndDate DateTime The ending point for the computation (default = now)
  * @return integer The duration (number of seconds) of open hours elapsed between the two dates
  */
 public function GetOpenDuration($oObject, DateTime $oStartDate, DateTime $oEndDate)
 {
     if (class_exists('WorkingTimeRecorder')) {
         WorkingTimeRecorder::Trace(WorkingTimeRecorder::TRACE_DEBUG, __CLASS__ . '::' . __FUNCTION__);
     }
     //echo "GetOpenDuration - default: ".$oStartDate->format('Y-m-d H:i:s')." to ".$oEndDate->format('Y-m-d H:i:s')."<br/>\n";
     $iDuration = abs($oEndDate->format('U') - $oStartDate->format('U'));
     if (class_exists('WorkingTimeRecorder')) {
         WorkingTimeRecorder::SetValues($oStartDate->format('U'), $oEndDate->format('U'), $iDuration, WorkingTimeRecorder::COMPUTED_DURATION);
     }
     return $iDuration;
 }
 /**
  * Get duration (considering only open hours) elapsed bewteen two given DateTimes
  * @param $oTicket Ticket The ticket for which to compute the duration
  * @param $oStartDate DateTime The starting point for the computation (default = now)
  * @param $oEndDate DateTime The ending point for the computation (default = now)
  * @return integer The duration (number of seconds) of open hours elapsed between the two dates
  */
 public static function GetOpenDuration($oTicket, DateTime $oStartDate, DateTime $oEndDate)
 {
     if (class_exists('WorkingTimeRecorder')) {
         WorkingTimeRecorder::Trace(WorkingTimeRecorder::TRACE_DEBUG, __CLASS__ . '::' . __FUNCTION__);
     }
     return abs($oEndDate->format('U') - $oStartDate->format('U'));
 }
Example #4
0
 /**
  * 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;
 }