98 lines
		
	
	
	
		
			2.6 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			98 lines
		
	
	
	
		
			2.6 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')";
 | |
| 	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 = $period_max = get_config('timetable', 'numperiod');
 | |
| 	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');
 | |
| 	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 <= 5; $k++) {
 | |
| 			$flag = 0;
 | |
| 			if (array_key_exists($i,$this->data[$k])) {
 | |
| 				$content = "";
 | |
| 				foreach ($this->data[$k][$i] as $lesson) {
 | |
| 					if ($content) $content .= "<br>";
 | |
| 					$content .= $lesson->{$view};
 | |
| 					$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);
 | |
|     }
 | |
| 
 | |
| }
 |