Ejemplo n.º 1
0
 /**
  * @return Duration|null
  */
 public static function createFromRequest()
 {
     $dt = Loader::helper('form/date_time');
     $dateStart = $dt->translate('pdStartDate');
     $dateEnd = $dt->translate('pdEndDate');
     if ($dateStart || $dateEnd) {
         // create a Duration object
         $pd = new Duration();
         if ($_REQUEST['pdStartDateAllDayActivate']) {
             $pd->setStartDateAllDay(1);
             $dateStart = date('Y-m-d 00:00:00', strtotime($dateStart));
         } else {
             $pd->setStartDateAllDay(0);
         }
         if ($_REQUEST['pdEndDateAllDayActivate']) {
             $pd->setEndDateAllDay(1);
             $dateEnd = date('Y-m-d 23:59:59', strtotime($dateEnd));
         } else {
             $pd->setEndDateAllDay(0);
         }
         $pd->setStartDate($dateStart);
         $pd->setEndDate($dateEnd);
         if ($_POST['pdRepeatPeriod'] && $_POST['pdRepeat']) {
             if ($_POST['pdRepeatPeriod'] == 'daily') {
                 $pd->setRepeatPeriod(Duration::REPEAT_DAILY);
                 $pd->setRepeatEveryNum($_POST['pdRepeatPeriodDaysEvery']);
             } elseif ($_POST['pdRepeatPeriod'] == 'weekly') {
                 $pd->setRepeatPeriod(Duration::REPEAT_WEEKLY);
                 $pd->setRepeatEveryNum($_POST['pdRepeatPeriodWeeksEvery']);
                 $pd->setRepeatPeriodWeekDays($_POST['pdRepeatPeriodWeeksDays']);
             } elseif ($_POST['pdRepeatPeriod'] == 'monthly') {
                 $pd->setRepeatPeriod(Duration::REPEAT_MONTHLY);
                 $repeat_by = $_POST['pdRepeatPeriodMonthsRepeatBy'];
                 $repeat = self::MONTHLY_REPEAT_WEEKLY;
                 switch ($repeat_by) {
                     case 'week':
                         $repeat = self::MONTHLY_REPEAT_WEEKLY;
                         break;
                     case 'month':
                         $repeat = self::MONTHLY_REPEAT_MONTHLY;
                         break;
                     case 'lastweekday':
                         $repeat = self::MONTHLY_REPEAT_LAST_WEEKDAY;
                         $dotw = $_POST['pdRepeatPeriodMonthsRepeatLastDay'] ?: 0;
                         $pd->setRepeatMonthLastWeekday($dotw);
                         break;
                 }
                 $pd->setRepeatMonthBy($repeat);
                 $pd->setRepeatEveryNum($_POST['pdRepeatPeriodMonthsEvery']);
             }
             $pd->setRepeatPeriodEnd($dt->translate('pdEndRepeatDateSpecific'));
         } else {
             $pd->setRepeatPeriod(Duration::REPEAT_NONE);
         }
         $pd->save();
         return $pd;
     } else {
         unset($pd);
     }
     return null;
 }
Ejemplo n.º 2
0
 public function testGenerateWeekly()
 {
     $repetition = new Duration();
     // Every 2 days
     $repetition->setRepeatPeriod($repetition::REPEAT_WEEKLY);
     $repetition->setRepeatEveryNum(3);
     $repetition->setStartDate('1/10/2015 01:00:00');
     $repetition->setEndDate('1/10/2015 03:00:00');
     // Sunday, Tuesday
     $repetition->setRepeatPeriodWeekDays(array(2, 3, 0));
     $now = strtotime('2/13/2014');
     $occurrences = $repetition->activeRangesBetween($now, strtotime('+5 years', $now));
     $all_active = true;
     foreach ($occurrences as $occurrence) {
         $window = $repetition->getActiveRange($occurrence[0] + 5);
         if (!$window) {
             $all_active = false;
             break;
         }
         if ($window[0] != $occurrence[0] || $window[1] != $occurrence[1]) {
             $all_active = false;
             break;
         }
     }
     $this->assertTrue($all_active, 'EventOccurrenceFactory generated inactive occurrences.');
 }
Ejemplo n.º 3
0
 public static function translateFromRequest()
 {
     $dt = Loader::helper('form/date_time');
     $dateStart = $dt->translate('pdStartDate');
     $dateEnd = $dt->translate('pdEndDate');
     if ($dateStart || $dateEnd) {
         // create a Duration object
         if ($_REQUEST['pdID']) {
             $pd = Duration::getByID($_REQUEST['pdID']);
         } else {
             $pd = new Duration();
         }
         if ($_REQUEST['pdStartDateAllDayActivate']) {
             $pd->setStartDateAllDay(1);
             $dateStart = date('Y-m-d 00:00:00', strtotime($dateStart));
         } else {
             $pd->setStartDateAllDay(0);
         }
         if ($_REQUEST['pdEndDateAllDayActivate']) {
             $pd->setEndDateAllDay(1);
             $dateEnd = date('Y-m-d 23:59:59', strtotime($dateEnd));
         } else {
             $pd->setEndDateAllDay(0);
         }
         $pd->setStartDate($dateStart);
         $pd->setEndDate($dateEnd);
         if ($_POST['pdRepeatPeriod'] && $_POST['pdRepeat']) {
             $pd->setRepeatPeriod($_POST['pdRepeatPeriod']);
             if ($_POST['pdRepeatPeriod'] == 'daily') {
                 $pd->setRepeatEveryNum($_POST['pdRepeatPeriodDaysEvery']);
             } elseif ($_POST['pdRepeatPeriod'] == 'weekly') {
                 $pd->setRepeatEveryNum($_POST['pdRepeatPeriodWeeksEvery']);
                 $pd->setRepeatPeriodWeekDays($_POST['pdRepeatPeriodWeeksDays']);
             } elseif ($_POST['pdRepeatPeriod'] == 'monthly') {
                 $pd->setRepeatMonthBy($_POST['pdRepeatPeriodMonthsRepeatBy']);
                 $pd->setRepeatEveryNum($_POST['pdRepeatPeriodMonthsEvery']);
             }
             $pd->setRepeatPeriodEnd($dt->translate('pdEndRepeatDateSpecific'));
         } else {
             $pd->setRepeatPeriod(false);
         }
         $pd->save();
     } else {
         unset($pd);
     }
     return $pd;
 }