/**
  * 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);
 }
Beispiel #2
0
 /**
  * Deletes a date.
  *
  * @param String $termin_id Id of the date
  * @param String $sub_cmd Sub command to be executed
  * @param String $cycle_id Id of the associated cycle
  */
 private function deleteDate($termin_id, $sub_cmd, $cycle_id)
 {
     //cancel cycledate entry
     if ($sub_cmd === 'cancel') {
         $termin = CourseDate::find($termin_id);
         $seminar_id = $termin->range_id;
         $room = $termin->getRoom();
         $termin->cancelDate();
         log_event('SEM_DELETE_SINGLEDATE', $termin_id, $seminar_id, 'Cycle_id: ' . $cycle_id);
         //delete singledate entry
     } else {
         if ($sub_cmd === 'delete') {
             $termin = CourseDate::find($termin_id) ?: CourseExDate::find($termin_id);
             $seminar_id = $termin->range_id;
             $termin_room = $termin->getRoom();
             $termin_date = $termin->getFullname();
             if ($termin->delete()) {
                 log_event("SEM_DELETE_SINGLEDATE", $termin_id, $seminar_id, 'appointment cancelled');
                 if (Request::get('approveDelete')) {
                     if (Config::get()->RESOURCES_ENABLE_EXPERT_SCHEDULE_VIEW) {
                         $this->course->createMessage(sprintf(_('Sie haben den Termin %s gelöscht, dem ein Thema zugeorndet war.' . ' Sie können das Thema in der %sExpertenansicht des Ablaufplans%s einem anderen Termin (z.B. einem Ausweichtermin) zuordnen.'), $termin_date, '<a href="' . URLHelper::getLink('themen.php?cmd=changeViewMode&newFilter=expert') . '">', '</a>'));
                     } elseif ($room) {
                         $this->course->createMessage(sprintf(_('Der Termin %s wurde gelöscht! Die Buchung für den Raum %s wurde gelöscht.'), $termin_date, $termin_room));
                     } else {
                         $this->course->createMessage(sprintf(_('Der Termin %s wurde gelöscht!'), $termin_date));
                     }
                 } else {
                     // no approval needed, delete unquestioned
                     $this->course->createMessage(sprintf(_('Der Termin %s wurde gelöscht!'), $termin_date));
                 }
             }
         }
     }
 }
Beispiel #3
0
 /**
  * Converts a CourseDate Entry to a CourseExDate Entry
  * returns instance of the new CourseExDate or NULL
  *
  * @return Object CourseExDate
  */
 public function cancelDate()
 {
     $date = $this->toArray();
     unset($date['termin_id']);
     $ex_date = new CourseExDate();
     $ex_date->setData($date);
     if ($ex_date->store()) {
         $this->delete();
         return $ex_date;
     }
     return null;
 }