type = $type; $this->name = $name; $this->periodmax=0; $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->week = $week; $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) { $this->data[$lesson->day][$lesson->period][] = $lesson; if ($this->periodmax < $lesson->period) $this->periodmax = $lesson->period; } } } /** * Count the number of online users * * @return int */ public function print_table($view) { 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'; $table->head = array('','Mo','Di', 'Mi' , 'Do', 'Fr'); if ($numdayweek == 6) $table->head[] = 'Sa'; for ($i = 1; $i<=$numperiod; $i++) { $tablerow = new \html_table_row(); $cell = new \html_table_cell($i); $cell->style = 'font-weight: bold;'; // $cell->attributes['class'] = 'header'; $tablerow->cells[] = $cell; for ($k = 1; $k <= $numdayweek; $k++) { $flag = 0; if (array_key_exists($i,$this->data[$k])) { $content = ""; foreach ($this->data[$k][$i] as $lesson) { if ($content) $content .= "
"; if ($lesson->flag) $content .= ""; //if (substr($lesson->week,$this->week,1) == '1') $content .= $lesson->{$view}; if ($lesson->week[$this->week-1] == '1') $content .= $lesson->{$view}; if ($lesson->week[$this->week-1] == 'x') $content .= "---"; if ($lesson->flag) $content .= ""; $flag += $lesson->flag; } } else { $content = "-"; } $cell = new \html_table_cell($content); // if ($flag) $cell->style = 'color: red;'; $tablerow->cells[] = $cell; } $table->data[] = $tablerow; } return \html_writer::table($table); } }