Esempio n. 1
0
 /**
  * @param timestamp $lastTimestamp
  * @return next date timestamp or null if there is no other date
  */
 public function getNextDate($lastTimestamp)
 {
     if ($this->getStartDate() != null && $this->getStartDate() > Gpf_Common_DateUtils::getDateTime(time())) {
         return null;
     }
     if ($this->getEndDate() != null && $this->getEndDate() < Gpf_Common_DateUtils::getDateTime(time())) {
         return null;
     }
     $recurrenceSetting = new Gpf_Db_RecurrenceSetting();
     $recurrenceSetting->setRecurrencePresetId($this->getId());
     $nextDate = 0;
     foreach ($recurrenceSetting->loadCollection() as $recurrenceSetting) {
         $setting = Gpf_Recurrence_Setting_Factory::getRecurrenceSetting($recurrenceSetting);
         $settingNextDate = $setting->getNextDate($lastTimestamp);
         if ($nextDate < $settingNextDate) {
             $nextDate = $settingNextDate;
         }
     }
     if ($nextDate == 0) {
         return null;
     }
     return $nextDate;
 }
 /**
  * @param string $id
  * @param string $name
  * @param string $type
  * @param int $period period in seconds
  * @param int $frequency
  *
  * @return Gpf_Recurrence_Preset
  */
 public function addRecurrencePreset($id, $name, $type = '', $period = '', $frequency = '')
 {
     $preset = new Gpf_Recurrence_Preset();
     $preset->setId($id);
     $preset->setName($name);
     $preset->setType(Gpf_Db_RecurrencePreset::SYSTEM_PRESET);
     $preset->insert();
     if ($type != '') {
         $presetSetting = new Gpf_Db_RecurrenceSetting();
         $presetSetting->setRecurrencePresetId($preset->getId());
         $presetSetting->setType($type);
         $presetSetting->setPeriod($period);
         $presetSetting->setFrequency($frequency);
         $presetSetting->insert();
     }
     return $preset;
 }