Ejemplo n.º 1
0
 /**
  * @return Gpf_Recurrence_Setting
  */
 public static function getRecurrenceSetting(Gpf_Db_RecurrenceSetting $recurrenceSetting)
 {
     switch ($recurrenceSetting->getType()) {
         case Gpf_Db_RecurrenceSetting::TYPE_ONCE:
             return new Gpf_Recurrence_Setting_Once($recurrenceSetting);
         case Gpf_Db_RecurrenceSetting::TYPE_EACH:
             return new Gpf_Recurrence_Setting_Repeating($recurrenceSetting);
         case Gpf_Db_RecurrenceSetting::TYPE_HOUR:
             return new Gpf_Recurrence_Setting_Hour($recurrenceSetting);
         case Gpf_Db_RecurrenceSetting::TYPE_DAY:
             return new Gpf_Recurrence_Setting_Day($recurrenceSetting);
         case Gpf_Db_RecurrenceSetting::TYPE_WEEK:
             return new Gpf_Recurrence_Setting_Week($recurrenceSetting);
         case Gpf_Db_RecurrenceSetting::TYPE_MONTH:
             return new Gpf_Recurrence_Setting_Month($recurrenceSetting);
         case Gpf_Db_RecurrenceSetting::TYPE_YEAR:
             return new Gpf_Recurrence_Setting_Year($recurrenceSetting);
     }
     return null;
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 public function __construct(Gpf_Db_RecurrenceSetting $setting)
 {
     $this->period = $setting->getPeriod();
     $this->frequency = $setting->getFrequency();
 }
 /**
  * @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;
 }