/** * Create calendar appointments * @param ilBookingEntry $booking * @return */ protected function createAppointments(ilBookingEntry $booking) { include_once './Services/Calendar/classes/class.ilDateList.php'; $concurrent_dates = new ilDateList(ilDateList::TYPE_DATETIME); $start = clone $this->form->getItemByPostVar('st')->getDate(); for ($i = 0; $i < $this->form->getItemByPostVar('ap')->getValue(); $i++) { $concurrent_dates->add(clone $start); $start->increment(ilDateTime::MINUTE, $this->form->getItemByPostVar('du')->getMinutes()); $start->increment(ilDateTime::HOUR, $this->form->getItemByPostVar('du')->getHours()); #$start = new ilDateTime(,IL_CAL_UNIX); } include_once './Services/Calendar/classes/class.ilCalendarUtil.php'; $def_cat = ilCalendarUtil::initDefaultCalendarByType(ilCalendarCategory::TYPE_CH, $this->getUserId(), $this->lng->txt('cal_ch_personal_ch'), true); // Add calendar appointment for each include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php'; include_once './Services/Calendar/classes/class.ilCalendarEntry.php'; include_once './Services/Calendar/classes/class.ilCalendarRecurrenceCalculator.php'; include_once './Services/Booking/classes/class.ilBookingPeriod.php'; foreach ($concurrent_dates as $dt) { $end = clone $dt; $end->increment(ilDateTime::MINUTE, $this->form->getItemByPostVar('du')->getMinutes()); $end->increment(ilDateTime::HOUR, $this->form->getItemByPostVar('du')->getHours()); $calc = new ilCalendarRecurrenceCalculator(new ilBookingPeriod($dt, $end), $this->form->getItemByPostVar('frequence')->getRecurrence()); // Calculate with one year limit $limit = clone $dt; $limit->increment(ilDAteTime::YEAR, 1); $date_list = $calc->calculateDateList($dt, $limit); foreach ($date_list as $app_start) { $app_end = clone $app_start; $app_end->increment(ilDateTime::MINUTE, $this->form->getItemByPostVar('du')->getMinutes()); $entry = new ilCalendarEntry(); $entry->setContextId($booking->getId()); $entry->setTitle($this->form->getInput('ti')); $entry->setSubtitle("#consultationhour#"); // dynamic, see ilCalendarEntry $entry->setDescription($this->form->getInput('de')); $entry->setLocation($this->form->getInput('lo')); $entry->setStart($app_start); $entry->setEnd($app_end); $entry->setTranslationType(IL_CAL_TRANSLATION_SYSTEM); $entry->save(); $cat_assign = new ilCalendarCategoryAssignments($entry->getEntryId()); $cat_assign->addAssignment($def_cat->getCategoryID()); } } }
/** * Apply limits (count or until) * * @access protected * @param object ilDateList * */ protected function applyLimits(ilDateList $list) { $list->sort(); #echo "list: "; #echo $list; #echo '<br />'; // Check valid dates before starting time foreach ($list->get() as $check_date) { if (ilDateTime::_before($check_date, $this->event->getStart(), IL_CAL_DAY)) { #echo 'Removed: '.$check_date.'<br/>'; $list->remove($check_date); } } #echo 'Until date '.$this->recurrence->getFrequenceUntilDate(); // Check count if given if ($this->recurrence->getFrequenceUntilCount()) { foreach ($list->get() as $res) { // check smaller than since the start time counts as one if (count($this->valid_dates->get()) < $this->recurrence->getFrequenceUntilCount()) { $this->valid_dates->add($res); } else { $this->limit_reached = true; return false; } } return true; } elseif ($this->recurrence->getFrequenceUntilDate()) { #echo 'Until date '.$this->recurrence->getFrequenceUntilDate(); $date = $this->recurrence->getFrequenceUntilDate(); foreach ($list->get() as $res) { #echo 'Check date '.$res; if (ilDateTime::_after($res, $date, IL_CAL_DAY)) { #echo 'Limit reached'; $this->limit_reached = true; return false; } $this->valid_dates->add($res); } return true; } $this->valid_dates->merge($list); return true; }
/** * Build a month day list * * @access public * @param int month * @param int year * @param int weekstart (0 => Sunday,1 => Monday) * @return ilDateList * */ public static function _buildMonthDayList($a_month, $a_year, $weekstart) { include_once 'Services/Calendar/classes/class.ilDateList.php'; $day_list = new ilDateList(ilDateList::TYPE_DATE); $prev_month = $a_month == 1 ? 12 : $a_month - 1; $prev_year = $prev_month == 12 ? $a_year - 1 : $a_year; $next_month = $a_month == 12 ? 1 : $a_month + 1; $next_year = $a_month == 12 ? $a_year + 1 : $a_year; $days_in_month = self::_getMaxDayOfMonth($a_year, $a_month); $days_in_prev_month = self::_getMaxDayOfMonth($a_year, $prev_month); $week_day['year'] = $a_year; $week_day['mon'] = $a_month; $week_day['mday'] = 1; $week_day['hours'] = 0; $week_day['minutes'] = 0; $week_day = new ilDate($week_day, IL_CAL_FKT_GETDATE); $weekday = $week_day->get(IL_CAL_FKT_DATE, 'w'); $first_day_offset = $weekday - $weekstart < 0 ? 6 : $weekday - $weekstart; for ($i = 0; $i < 42; $i++) { if ($i < $first_day_offset) { $day = $days_in_prev_month - $first_day_offset + $i + 1; $day_list->add(new ilDate(gmmktime(0, 0, 0, $prev_month, $days_in_prev_month - $first_day_offset + $i + 1, $prev_year), IL_CAL_UNIX)); } elseif ($i < $days_in_month + $first_day_offset) { $day = $i - $first_day_offset + 1; $day_list->add(new ilDate(gmmktime(0, 0, 0, $a_month, $i - $first_day_offset + 1, $a_year), IL_CAL_UNIX)); } else { $day = $i - $days_in_month - $first_day_offset + 1; $day_list->add(new ilDate(gmmktime(0, 0, 0, $next_month, $i - $days_in_month - $first_day_offset + 1, $next_year), IL_CAL_UNIX)); } if ($i == 34 and ($day < 15 or $day == $days_in_month)) { break; } } return $day_list; }
/** * Merge two lists * * @access public * @param object ilDateList * */ public function merge(ilDateList $other_list) { foreach ($other_list->get() as $new_date) { $this->add($new_date); } }