/** * 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 */ function getVirtualSingleDatesForSemester($metadate_id, $sem_begin, $sem_end, $startAfterTimeStamp, $corr) { $dates = array(); $dates_to_delete = array(); // loads the singledates of the by metadate_id denoted regular time-entry into the object $this->readSingleDates($metadate_id); // The currently existing singledates for the by metadate_id denoted regular time-entry $existingSingleDates =& $this->cycles[$metadate_id]->getSingleDates(); $start_woche = $this->cycles[$metadate_id]->week_offset; $end_woche = $this->cycles[$metadate_id]->end_offset; $turnus = $this->cycles[$metadate_id]->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->cycles[$metadate_id]->day . ' 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_time = mktime((int) $this->cycles[$metadate_id]->start_stunde, (int) $this->cycles[$metadate_id]->start_minute, 0, date("n", $stamp), date("j", $stamp), date("Y", $stamp)); // Year $end_time = mktime((int) $this->cycles[$metadate_id]->end_stunde, (int) $this->cycles[$metadate_id]->end_minute, 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.) */ 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 SingleDate(array('seminar_id' => $this->seminar_id)); $all_holiday = $holiday->getAllHolidays(); // fetch all Holidays foreach ($all_holiday as $val2) { if ($val2["beginn"] <= $start_time && $start_time <= $val2["ende"]) { $termin->setExTermin(true); } } //check for calculatable holidays if (!$termin->isExTermin()) { $holy_type = holiday($start_time); if ($holy_type["col"] == 3) { $termin->setExTermin(true); } } // fill the singleDate-Object with data $termin->setMetaDateID($metadate_id); $termin->setTime($start_time, $end_time); $termin->setDateType(1); //best guess $dates[$termin->getTerminID()] = $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); foreach ($existingSingleDates as $id => $val) { foreach (array_keys($dates) as $date) { if ($date != $id) { $dates_to_delete[$id] = $val; unset($existingSingleDates[$id]); } } } return array('dates' => $dates, 'dates_to_delete' => $dates_to_delete); }
function isHoliday() { foreach (HolidayData::GetAllHolidaysArray() as $val) { if ($val['beginn'] <= $this->date && $val['ende'] >= $this->end_time) { $name = $val['name']; } } if (!$name) { $holy_type = holiday($this->date); $name = $holy_type['name']; } if ($name) { return $name; } else { return false; } }
/** * 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); }