
block on dashboard too automatic detection wheater class or teacher plan automatic next week detection (rd)
103 lines
2.9 KiB
PHP
Executable file
103 lines
2.9 KiB
PHP
Executable file
<?php
|
|
|
|
/**
|
|
* File containing timetable class.
|
|
*
|
|
* @package block_online_users
|
|
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
|
|
namespace block_timetable;
|
|
|
|
defined('MOODLE_INTERNAL') || die();
|
|
|
|
/**
|
|
* Class used to list and count online users
|
|
*
|
|
* @package block_online_users
|
|
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
class timetable {
|
|
|
|
/** @var array the data of timetable */
|
|
public $data;
|
|
|
|
/**
|
|
* Class constructor
|
|
*
|
|
* @param string $type The type of the timetable [class, room, teacher]
|
|
* @param int $name Name of class or room or teacher
|
|
*/
|
|
public function __construct($type, $name) {
|
|
$this->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 .= "<br>";
|
|
if ($lesson->flag) $content .= "<span style='color:red;'>";
|
|
$content .= $lesson->{$view};
|
|
if ($lesson->flag) $content .= "</span>";
|
|
$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);
|
|
}
|
|
|
|
}
|