type = $type; $this->name = $name; $this->periodmax=0; $this->clear_data(); // $this->data = array(); // for ($i=1; $i<=6; $i++) $this->data[$i] = array(); } public function clear_data() { $this->data = array(); for ($i=1; $i<=6; $i++) $this->data[$i] = array(); } /** * * @param int $week The week of timetable */ public function read_db($week) { global $USER, $DB, $CFG; $this->clear_data(); $this->numdayweek = 5 + get_config('timetable', 'saturday'); $this->monday = new \DateTime(); if ($week>0) { $this->monday->add(new \DateInterval("P".($week)."W")); } elseif ($week<0) { $this->monday->sub(new \DateInterval("P".(-$week)."W")); } $dayofweek = $this->monday->format('w'); if ($dayofweek > $this->numdayweek) { $this->monday->add(new \DateInterval("P".(8-$dayofweek)."D")); } elseif ($dayofweek < 1) { $this->monday->add(new \DateInterval("P1D")); } else { $this->monday->sub(new \DateInterval("P".($dayofweek-1)."D")); } $this->week = $this->monday->format("W"); $this->lastday = new \DateTime($this->monday->format('Y-m-d\TH:i:sP')); $this->lastday->add(new \DateInterval("P".($this->numdayweek-1)."D")); //$this->content->text .= $monday->format('d.m') . " - " . $lastday->format('d.m'); $sql = "$this->type = '$this->name' and not (mid(week, $this->week, 1) = '0')"; //$sql = "$this->type = '$this->name' and (mid(week, $this->week, 1) = '1')"; if ($result = $DB->get_records_select('timetable_lesson',$sql)) { foreach ($result as $lesson) { //if (!exists($this->data[$lesson->day][$lesson->period])) $this->data[$lesson->day][$lesson->period] = array(); $this->data[$lesson->day][$lesson->period]['lesson'][] = $lesson; if ($this->periodmax < $lesson->period) $this->periodmax = $lesson->period; } } $day = new \DateTime($this->monday->format('Y-m-d\TH:i:sP')); // TODO CHANGE DATABASE: table substitution: classesa -> classa, classesb -> classb !!! for ($i=0; $i<$this->numdayweek; $i++) { if ($this->type == 'class') { $sql = "date = '".$day->format('Ymd')."' AND ({$this->type}esa LIKE '%{$this->name}%' OR {$this->type}esb LIKE '%{$this->name}%')"; } else { $sql = "date = '".$day->format('Ymd')."' AND ({$this->type}a LIKE '%{$this->name}%' OR {$this->type}b LIKE '%{$this->name}%')"; } if ($result = $DB->get_records_select('timetable_substitution',$sql)) { foreach ($result as $substitution) { $this->data[$i+1][$substitution->period]['substitution'][] = $substitution; if ($this->periodmax < $lesson->period) $this->periodmax = $lesson->period; } } $day->add(new \DateInterval("P1D")); } } /** * Count the number of online users * * @return int */ public function print_navigation($week) { /** * Count the number of online users * * @return int */ $table = new \html_table(); $table->attributes['class'] = 'minicalendar calendartable calendar-controls'; //$table->head = array('','Mo','Di', 'Mi' , 'Do', 'Fr'); $tablerow = new \html_table_row(); if ($week>0) { $tablerow->cells[] = new \html_table_cell('◄'); } else { $tablerow->cells[] = new \html_table_cell(''); } $tablerow->cells[] = new \html_table_cell(''.$this->monday->format('d.m') . " - " . $this->lastday->format('d.m').''); if ($week<2) { $tablerow->cells[] = new \html_table_cell('►'); } else { $tablerow->cells[] = new \html_table_cell(''); } $table->data[] = $tablerow; return \html_writer::table($table); } public function get_caption($week) { $result = ""; if ($week>0) { //$result .= '◄'; $result .= '◄<'; } else { $result .= ' '; //$result .= ''; } $result .= ' | '; $result .= ''; $result .= ''.$this->monday->format('d.m') . " - " . $this->lastday->format('d.m').''; $result .= ""; $result .= ' | '; if ($week<2) { //$result .= '►'; $result .= '►'; } else { $result .= ''; } return $result; } public function print_table($view,$week) { global $DB; //var_dump($this->data[1]); $numperiod = get_config('timetable', 'numperiod'); $numdayweek = 5 + get_config('timetable', 'saturday'); if ($this->periodmax>$numperiod) $numperiod = $this->periodmax; $table = new \html_table(); //$table->attributes['class'] = "minicalendar calendartable generaltable timetable_view_$view"; $table->attributes['class'] = "minicalendar calendartable generaltable timetable_view_$view"; $table->caption = "