示例#1
0
文件: helpers.php 项目: ratbird/hope
 function bookable_rooms_action()
 {
     if (!getGlobalPerms($GLOBALS['user']->id) == 'admin') {
         $resList = new ResourcesUserRoomsList($GLOBALS['user']->id, false, false, false);
         if (!$resList->roomsExist()) {
             throw new AccessDeniedException();
         }
     }
     $select_options = Request::optionArray('rooms');
     $rooms = array_filter($select_options, function ($v) {
         return strlen($v) === 32;
     });
     $events = array();
     $dates = array();
     $timestamps = array();
     if (count(Request::getArray('new_date'))) {
         $new_date = array();
         foreach (Request::getArray('new_date') as $one) {
             if ($one['name'] == 'startDate') {
                 $dmy = explode('.', $one['value']);
                 $new_date['day'] = (int) $dmy[0];
                 $new_date['month'] = (int) $dmy[1];
                 $new_date['year'] = (int) $dmy[2];
             }
             $new_date[$one['name']] = (int) $one['value'];
         }
         if (check_singledate($new_date['day'], $new_date['month'], $new_date['year'], $new_date['start_stunde'], $new_date['start_minute'], $new_date['end_stunde'], $new_date['end_minute'])) {
             $start = mktime($new_date['start_stunde'], $new_date['start_minute'], 0, $new_date['month'], $new_date['day'], $new_date['year']);
             $ende = mktime($new_date['end_stunde'], $new_date['end_minute'], 0, $new_date['month'], $new_date['day'], $new_date['year']);
             $timestamps[] = $start;
             $timestamps[] = $ende;
             $event = new AssignEvent('new_date', $start, $ende, null, null, '');
             $events[$event->getId()] = $event;
         }
     }
     foreach (Request::optionArray('selected_dates') as $one) {
         $date = new SingleDate($one);
         if ($date->getStartTime()) {
             $timestamps[] = $date->getStartTime();
             $timestamps[] = $date->getEndTime();
             $event = new AssignEvent($date->getTerminID(), $date->getStartTime(), $date->getEndTime(), null, null, '');
             $events[$event->getId()] = $event;
             $dates[$date->getTerminID()] = $date;
         }
     }
     if (count($events)) {
         $result = array();
         $checker = new CheckMultipleOverlaps();
         $checker->setTimeRange(min($timestamps), max($timestamps));
         foreach ($rooms as $room) {
             $checker->addResource($room);
         }
         $checker->checkOverlap($events, $result, "assign_id");
         foreach ((array) $result as $room_id => $details) {
             foreach ($details as $termin_id => $conflicts) {
                 if ($termin_id == 'new_date' && Request::option('singleDateID')) {
                     $assign_id = SingleDateDB::getAssignID(Request::option('singleDateID'));
                 } else {
                     $assign_id = SingleDateDB::getAssignID($termin_id);
                 }
                 $filter = function ($a) use($assign_id) {
                     if ($a['assign_id'] && $a['assign_id'] == $assign_id) {
                         return false;
                     }
                     return true;
                 };
                 if (!count(array_filter($conflicts, $filter))) {
                     unset($result[$room_id][$termin_id]);
                 }
             }
         }
         $result = array_filter($result);
         $this->render_json(array_keys($result));
         return;
     }
     $this->render_nothing();
 }
示例#2
0
 /**
  * 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);
 }