Exemplo n.º 1
0
 /**
  * Get weekly shedule for a particular day
  *
  * @param $timestamp
  * @return array
  */
 function getSchedule($timestamp)
 {
     if (!$this->zermelo->token) {
         return 403;
     }
     $subjects = (array) json_decode(file_get_contents('lib/Assets/subjects.json'));
     $tz = timezone_open('Europe/Amsterdam');
     $tz_offset = timezone_offset_get($tz, new \DateTime('@' . $timestamp, timezone_open('UTC')));
     $timestamp += $tz_offset + 4;
     $weekstart = $this->getFirstDayOfWeek(date('Y', $timestamp), date('W', $timestamp));
     $weekend = strtotime('this Friday', $weekstart);
     $result = array('week_timestamp' => $weekstart, 'days' => array());
     $curday = $weekstart;
     while ($curday <= $weekend) {
         $curwd = (int) date('w', $curday);
         $result['days'][$curwd] = array('day_title' => $this->dutchDayName($curday), 'day_ofweek' => (int) date('w', $curday), 'items' => array());
         $start = $curday;
         $end = $curday + 86399;
         $data = $this->zermelo->getStudentGrid($start, $end);
         foreach ($data as $item) {
             $item = (object) $item;
             $start = (int) $item->start;
             $vakname = isset($subjects[$item->subjects[0]]) ? $subjects[$item->subjects[0]] : $item->subjects[0];
             $teacher = $item->teachers[0];
             $cancelled = $item->cancelled;
             $moved = $item->moved;
             $teacher = preg_replace('/^.*-\\s*/', '', $teacher);
             if (empty($item->locations)) {
                 $item->locations = array('onbekend');
             }
             $result['days'][$curwd]['items'][] = array('title' => $vakname, 'subtitle' => 'Lokaal ' . $item->locations[0], 'teacher' => strtoupper($teacher), 'cancelled' => $cancelled, 'moved' => $moved, 'start' => $start, 'start_str' => date('H:i', $start + $tz_offset));
         }
         $curday += 86400;
     }
     return $result;
 }
 /**
  * Get weekly shedule for a particular day
  *
  * @param $timestamp
  * @return array
  */
 public function getSchedule($timestamp)
 {
     if (!$this->zermelo->token) {
         return 403;
     }
     $times = array('08:30', '09:30', '11:00', '12:00', '13:30', '14:30', '15:30');
     $break_times = array('10:30', '13:00');
     $subjects = (array) json_decode(file_get_contents('lib/Assets/subjects.json'));
     $tz = timezone_open('Europe/Amsterdam');
     $tz_offset = timezone_offset_get($tz, new \DateTime('@' . $timestamp, timezone_open('UTC')));
     $timestamp += $tz_offset + 4;
     $weekstart = $this->getFirstDayOfWeek(date('Y', $timestamp), date('W', $timestamp));
     $weekend = strtotime('this Friday', $weekstart);
     $result = array('week_timestamp' => $weekstart, 'days' => array());
     $curday = $weekstart;
     while ($curday <= $weekend) {
         $curwd = (int) date('w', $curday);
         $result['days'][$curwd] = array('day_title' => $this->dutchDayName($curday), 'day_ofweek' => (int) date('w', $curday), 'items' => array());
         $start = $curday;
         $end = $curday + 86399;
         $data = $this->zermelo->getStudentGrid($start, $end);
         foreach ($data as $item) {
             $item = (object) $item;
             $start = (int) $item->start;
             $vakname = isset($subjects[$item->subjects[0]]) ? $subjects[$item->subjects[0]] : $item->subjects[0];
             $teacher = isset($item->teachers[0]) ? $item->teachers[0] : "Onbekend";
             $cancelled = $item->cancelled;
             $moved = $item->moved;
             $cancelled = $item->cancelled;
             $changed = $item->modified;
             $changedDesc = isset($item->changeDescription) ? $item->changeDescription : null;
             $teacher = preg_replace('/^.*-\\s*/', '', $teacher);
             if (empty($item->locations)) {
                 $item->locations = array('onbekend');
             }
             $explode = explode("gewijzigd naar ", $changedDesc);
             if (isset($explode[1])) {
                 $changedLocation = explode(".", $explode[1]);
                 $item->locations[0] = str_replace(" ", "", $changedLocation[0]);
             }
             $result['days'][$curwd]['items'][] = array('title' => $vakname, 'subtitle' => 'Lokaal ' . $item->locations[0], 'teacher' => strtoupper($teacher), 'cancelled' => $cancelled, 'moved' => $moved, 'description' => $changedDesc, 'start' => $start, 'start_str' => date('H:i', $start));
         }
         $curday += 86400;
     }
     // Free hours.
     foreach ($result['days'] as $i => $day) {
         $count = count($day['items']);
         $new_items = array();
         if (!$count === 0) {
             $j = 0;
             $last_str = '';
             foreach ($times as $time) {
                 $start_str = $day['items'][$j]['start_str'];
                 // Double entry workaround.
                 while ($start_str == $last_str) {
                     $j++;
                     if ($j == $count) {
                         goto endloop;
                     }
                     $start_str = $day['items'][$j]['start_str'];
                 }
                 if ($time != $start_str) {
                     $timestampStart = isset($day['items'][$j]['start']) ? strtotime(date('d-m-Y', $day['items'][$j]['start']) . ' ' . $time) : null;
                     $free_hour = array('title' => 'Geen les', 'start' => $timestampStart, 'start_str' => $time);
                     $new_items[] = $free_hour;
                     $last_str = '';
                 } else {
                     $new_items[] = $day['items'][$j];
                     $last_str = $start_str;
                     $j++;
                 }
                 if ($j == $count) {
                     break;
                 }
             }
             endloop:
             $result['days'][$i]['items'] = $new_items;
         }
     }
     // Breaks.
     foreach ($result['days'] as $i => $day) {
         $day_items = array();
         $prev_time = '00:00';
         $j = 0;
         foreach ($day['items'] as $item) {
             if ($j < count($break_times) && $prev_time < $break_times[$j] && $item['start_str'] > $break_times[$j]) {
                 $timestampStart = isset($item['start']) ? strtotime(date('d-m-Y', $item['start']) . ' ' . $break_times[$j]) : null;
                 $day_items[] = array('title' => 'Pauze', 'start' => $timestampStart, 'start_str' => $break_times[$j]);
                 $j++;
             }
             $day_items[] = $item;
         }
         $result['days'][$i]['items'] = $day_items;
     }
     return $result;
 }