/** * 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); }
public function unDeleteSingleDate($date_id, $cycle_id = '') { // logging >>>>>> StudipLog::log("SEM_UNDELETE_SINGLEDATE",$date_id, $this->getId(), 'Cycle_id: '.$cycle_id); NotificationCenter::postNotification("CourseDidChangeSchedule", $this); // logging <<<<<< if ($cycle_id == '') { $termin = new SingleDate($date_id); if (!$termin->isExTermin()) { return false; } $termin->setExTermin(false); $termin->store(); return true; } else { return $this->metadate->unDeleteSingleDate($cycle_id, $date_id, $this->filterStart, $this->filterEnd); } }
/** * load corresponding single dates from database * give timestamps as params to filter by time range * * @param int $start * @param int $end * @return boolean */ function readSingleDates($start = 0, $end = 0) { $this->termine = array(); $termin_data = CycleDataDB::getTermine($this->metadate_id, $start, $end); if ($termin_data) { foreach ($termin_data as $val) { unset($termin); $termin = new SingleDate(); $termin->fillValuesFromArray($val); $termin->setExTermin($val['ex_termin']); $this->termine[$val['termin_id']] = $termin; } return TRUE; } return FALSE; }