コード例 #1
0
 /**
  * Constructor
  *
  * @param   string f default NULL format string
  */
 public function __construct($f = NULL)
 {
     // Add some default formatters
     $this->setFormatter('printf', PrintfFormat::getInstance());
     $this->setFormatter('date', DateFormat::getInstance());
     $this->setFormatter('choice', ChoiceFormat::getInstance());
     $this->setFormatter('number', NumberFormat::getInstance());
     $this->setFormatter('array', ArrayFormat::getInstance());
     $this->setFormatter('hash', HashFormat::getInstance());
     parent::__construct($f);
 }
コード例 #2
0
ファイル: PcTask.php プロジェクト: ntemple/intelli-plancake
 /**
  * Re-arranges due date to the next occurrence on the repetition.
  * IMPORTANT: if the task hasn't got a due date, it uses the today's date
  *
  * @param bool $isInitialAdjustment - whether we want just to compute an initial adjustment
  */
 public function setNextOccurrence($isInitialAdjustment = false)
 {
     $repetition = PcRepetitionPeer::retrieveByPk($this->getRepetitionId());
     if ($repetition->getSpecial() == 'selected_wkdays') {
         $startingPointForDueDateTimestamp = time() > $this->getDueDate('U') ? time() : $this->getDueDate('U');
         $weekdaysSet = DateFormat::fromIntegerToWeekdaysSetForRepetition($this->getRepetitionParam());
         $closestWeekdayInSet = '9999999999';
         // this big to make sure the first attempt of the following loop will set a value
         foreach ($weekdaysSet as $k => $v) {
             if ($v) {
                 $next = $isInitialAdjustment ? '' : 'next';
                 $closestWeekdayInSetTemp = strtotime("{$next} {$k}", $startingPointForDueDateTimestamp);
                 // i.e.: next mon
                 if ($closestWeekdayInSetTemp < $closestWeekdayInSet) {
                     $closestWeekdayInSet = $closestWeekdayInSetTemp;
                 }
             }
         }
         $nextTimestamp = $closestWeekdayInSet;
     } else {
         $rce = $isInitialAdjustment ? $repetition->getInitialComputerExpression() : $repetition->getComputerExpression();
         $param = $repetition->isParamCardinal() ? $this->getRepetitionParam() : PcUtils::getOrdinalFromCardinal($this->getRepetitionParam());
         $rce = str_replace('_X_', $param, $rce);
         //$rce = str_replace('_Xlong_', PcUtils::getOrdinalFromCardinal($this->getRepetitionParam(), false), $rce);
         $todayTimestamp = strtotime('today');
         $dateFormat = DateFormat::getInstance();
         $oldDueDateTimestamp = 0;
         if ($this->getDueDate()) {
             $loggedUser = PcUserPeer::getLoggedInUser();
             $oldDueDateTimestamp = $dateFormat->getTimestamp($this->getDueDate($loggedUser->getDateFormat()));
         } else {
             $oldDueDateTimestamp = $todayTimestamp;
         }
         $nextTimestamp = $oldDueDateTimestamp;
         if (strpos($rce, '_month') === FALSE) {
             if ($isInitialAdjustment) {
                 $nextTimestamp = strtotime($rce, $nextTimestamp);
             } else {
                 // we are in the case we need to apply the computer expression just once or
                 // over and over again
                 do {
                     $nextTimestamp = strtotime($rce, $nextTimestamp);
                 } while ($nextTimestamp < $todayTimestamp || $nextTimestamp <= $oldDueDateTimestamp);
             }
         } else {
             $i = 1;
             $repetitionParam = $this->getRepetitionParam();
             // we are in the case where to deal with months. We have to go through the months
             if ($isInitialAdjustment) {
                 $monthPlus = date('F Y', strtotime('+ 0 months', $oldDueDateTimestamp));
                 $rceWithReplacement = str_replace('_month_', $monthPlus, $rce);
                 $nextTimestamp = strtotime($rceWithReplacement);
                 // comparing just the timestamps was giving some unexpected results
                 if (date('Ymd', $nextTimestamp) < date('Ymd', $oldDueDateTimestamp)) {
                     $monthPlus = date('F Y', strtotime('+ 1 months', $oldDueDateTimestamp));
                     $rceWithReplacement = str_replace('_month_', $monthPlus, $rce);
                     $nextTimestamp = strtotime($rceWithReplacement);
                 }
             } else {
                 do {
                     $oldDueDateTimestamp = $nextTimestamp;
                     $oldDueDateTimestampFirstDayOfMonth = strtotime('first day of this month', $oldDueDateTimestamp);
                     $monthPlus = date('F Y', strtotime('+' . $repetitionParam . 'months', $oldDueDateTimestampFirstDayOfMonth));
                     $rceWithReplacement = str_replace('_month_', $monthPlus, $rce);
                     $nextTimestamp = strtotime($rceWithReplacement);
                     //  {{{ added this code to troubleshoot a PHP max execution error in this loop
                     if ($i > 50) {
                         $watchdog = new PcWatchdog();
                         $watchdog->setType("NEXT RECURRENCE")->setDescription("taskId: {$this->getId()}")->save();
                         $watchdog3 = new PcWatchdog();
                         $watchdog3->setType("NEXT RECURRENCE")->setDescription("monthPlus: {$monthPlus}")->save();
                         $watchdog4 = new PcWatchdog();
                         $watchdog4->setType("NEXT RECURRENCE")->setDescription("rceWithReplacement: {$rceWithReplacement}")->save();
                         $watchdog6 = new PcWatchdog();
                         $watchdog6->setType("NEXT RECURRENCE")->setDescription($nextTimestamp)->save();
                         $watchdog7 = new PcWatchdog();
                         $watchdog7->setType("NEXT RECURRENCE")->setDescription($todayTimestamp)->save();
                         break;
                     }
                     // }}}
                     $i++;
                 } while ($nextTimestamp < $todayTimestamp || $nextTimestamp <= $oldDueDateTimestamp);
             }
         }
     }
     $this->setDueDate(date('Y-m-d', $nextTimestamp), 'Y-m-d');
     $this->save();
 }