function getHolidayData($holiday_id) { return SemesterHoliday::find($holiday_id); }
/** * Returns if a given date is a holiday. * * @param int $time Timestamp to check * @param bool $check_vacation_only Defines whether to check only vacation * times or against all holidays * @return mixed false if no holiday was found, an array with the name and * the "col" value of the holiday otherwise */ public static function isHoliday($time, $check_vacation_only = true) { // Check all defined vaciation times foreach (SemesterHoliday::getAll() as $val) { if ($val->beginn <= $time && $val->ende >= $time) { return array('name' => $val->name, 'col' => 3); } } // Check all other holidays if (!$check_vacation_only) { return holiday($time); $holiday_entry = holiday($time); } // Nothing found return false; }
/** * This method deletes a holiday or a bundle of holidays. * * @param string $id Id of the holiday (or 'bulk' for a bulk operation) */ public function delete_action($id) { $ids = $id === 'bulk' ? Request::optionArray('ids') : array($id); if (count($ids)) { $holidays = SemesterHoliday::findMany($ids); foreach ($holidays as $holiday) { $holiday->delete(); } PageLayout::postMessage(MessageBox::success(_('Die Ferien wurden erfolgreich gelöscht'))); } $this->redirect('admin/holidays'); }
/** * generate single date objects for one cycle and one semester, existing dates are merged in * * @param string cycle id * @param int timestamp of semester start * @param int timestamp of semester end * @param int alternative timestamp to start from * @param int correction calculation, if the semester does not start on monday (number of days?) * @return array returns an array of two arrays of SingleDate objects: 'dates' => all new and surviving dates, 'dates_to_delete' => obsolete dates */ public function createSemesterTerminSlots($sem_begin, $sem_end, $startAfterTimeStamp, $corr) { $dates = array(); $dates_to_delete = array(); // The currently existing singledates for the by metadate_id denoted regular time-entry //$existingSingleDates =& $this->cycles[$metadate_id]->getSingleDates(); $existingSingleDates =& $this->getAllDates(); $start_woche = $this->week_offset; $end_woche = $this->end_offset; $turnus = $this->cycle; // HolidayData is used to decide wether a date is during a holiday an should be created as an ex_termin. // Additionally, it is used to show which type of holiday we've got. $holiday = new HolidayData(); // This variable is used to check if a given singledate shall be created in a bi-weekly seminar. if ($start_woche == -1) { $start_woche = 0; } $week = 0; // get the first presence date after sem_begin $day_of_week = date('l', strtotime('Sunday + ' . $this->weekday . ' days')); $stamp = strtotime('this ' . $day_of_week, $sem_begin); if ($end_woche) { $end_woche -= 1; if ($end_woche < 0) { $end_woche = 0; } $sem_end = strtotime(sprintf('+%u weeks %s', $end_woche, strftime('%d.%m.%Y', $stamp))); } $start = explode(':', $this->start_time); $start_time = mktime((int) $start[0], (int) $start[1], 0, date("n", $stamp), date("j", $stamp), date("Y", $stamp)); // Year $end = explode(':', $this->end_time); $end_time = mktime((int) $end[0], (int) $end[1], 0, date("n", $stamp), date("j", $stamp), date("Y", $stamp)); // Year // loop through all possible singledates for this regular time-entry do { // if dateExists is true, the singledate will not be created. Default is of course to create the singledate $dateExists = false; // do not create singledates, if they are earlier then the chosen start-week if ($start_woche > $week) { $dateExists = true; } // bi-weekly check if ($turnus > 0 && $week - $start_woche > 0 && ($week - $start_woche) % ($turnus + 1)) { $dateExists = true; } /* * We only create dates, which do not already exist, so we do not overwrite existing dates. * * Additionally, we delete singledates which are not needed any more (bi-weekly, changed start-week, etc.) */ $date_values['range_id'] = $this->seminar_id; $date_values['autor_id'] = $GLOBALS['user']->id; $date_values['metadate_id'] = $this->metadate_id; foreach ($existingSingleDates as $key => $val) { // take only the singledate into account, that maps the current timepoint if ($start_time > $startAfterTimeStamp && $val->date == $start_time && $val->end_time == $end_time) { // bi-weekly check if ($turnus > 0 && $week - $start_woche > 0 && ($week - $start_woche) % ($turnus + 1)) { $dates_to_delete[$key] = $val; unset($existingSingleDates[$key]); } // delete singledates if they are earlier than the chosen start-week if ($start_woche > $week) { $dates_to_delete[$key] = $val; unset($existingSingleDates[$key]); } $dateExists = true; if (isset($existingSingleDates[$key])) { $dates[$key] = $val; } } } if ($start_time < $startAfterTimeStamp) { $dateExists = true; } if (!$dateExists) { $termin = new CourseDate(); $all_holiday = $holiday->getAllHolidays(); // fetch all Holidays foreach ($all_holiday as $val2) { if ($val2["beginn"] <= $start_time && $start_time <= $val2["ende"]) { $termin = new CourseExDate(); break; } } //check for calculatable holidays if ($termin instanceof CourseDate) { $holy_type = SemesterHoliday::isHoliday($start_time, false); if ($holy_type["col"] == 3) { $termin = new CourseExDate(); } } $date_values['date'] = $start_time; $date_values['end_time'] = $end_time; $date_values['date_type'] = 1; $termin->setData($date_values); $dates[] = $termin; } //inc the week, create timestamps for the next singledate $start_time = strtotime('+1 week', $start_time); $end_time = strtotime('+1 week', $end_time); $week++; } while ($end_time < $sem_end); return array('dates' => $dates, 'dates_to_delete' => $dates_to_delete); }