timetable in slider (rd)
This commit is contained in:
		
							parent
							
								
									a6334e6c86
								
							
						
					
					
						commit
						3a996bd5a5
					
				
					 2 changed files with 179 additions and 14 deletions
				
			
		|  | @ -33,7 +33,7 @@ class block_timetable extends block_base { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     function get_content() { |     function get_content() { | ||||||
|         global $CFG, $OUTPUT, $USER; |         global $CFG, $OUTPUT, $USER, $PAGE; | ||||||
| 
 | 
 | ||||||
|         if ($this->content !== null) { |         if ($this->content !== null) { | ||||||
|             return $this->content; |             return $this->content; | ||||||
|  | @ -47,7 +47,7 @@ class block_timetable extends block_base { | ||||||
|         $this->content = new stdClass(); |         $this->content = new stdClass(); | ||||||
|         $this->content->items = array(); |         $this->content->items = array(); | ||||||
|         $this->content->icons = array(); |         $this->content->icons = array(); | ||||||
| 	$this->content->footer = 'Fächer<br>Lehrer<br>Räume'; | 	$this->content->footer = '<div class="timetable_legend"><a href="javascript:M.block_timetable.view_subject()">Fächer</a>  -  <a href="javascript:M.block_timetable.view_teacher()">Lehrer</a>  -  <a href="javascript:M.block_timetable.view_room()">Räume</a></div>'; | ||||||
| 	$this->content->text = ""; | 	$this->content->text = ""; | ||||||
| 
 | 
 | ||||||
| 	/* | 	/* | ||||||
|  | @ -67,7 +67,8 @@ class block_timetable extends block_base { | ||||||
| 	} | 	} | ||||||
| 	 */ | 	 */ | ||||||
| //	echo var_dump($USER);
 | //	echo var_dump($USER);
 | ||||||
| 	$view = 'subject';	 | 	$view1 = 'subject';	 | ||||||
|  | 	$view2 = 'teacher';	 | ||||||
|         if ($this->page->course->idnumber && $this->page->course->shortname) { |         if ($this->page->course->idnumber && $this->page->course->shortname) { | ||||||
| 		$class = $this->page->course->shortname; | 		$class = $this->page->course->shortname; | ||||||
|             	$this->content->text .= "Stundenplan der Klasse $class<br>"; |             	$this->content->text .= "Stundenplan der Klasse $class<br>"; | ||||||
|  | @ -78,7 +79,9 @@ class block_timetable extends block_base { | ||||||
| 		$teacher = str_replace("-fvs", "", $teacher); | 		$teacher = str_replace("-fvs", "", $teacher); | ||||||
|             	$this->content->text .= "Stundenplan von ".(substr($USER->firstname,0,1)).". {$USER->lastname}<br>"; |             	$this->content->text .= "Stundenplan von ".(substr($USER->firstname,0,1)).". {$USER->lastname}<br>"; | ||||||
| 		$ttable = new timetable('teacher',$teacher); | 		$ttable = new timetable('teacher',$teacher); | ||||||
| 		$view = 'class'; | 		$view1 = 'class'; | ||||||
|  | 		$view2 = 'subject'; | ||||||
|  | 		$this->content->footer = '<div class="timetable_legend"><a href="javascript:M.block_timetable.view_class()">Klassen</a>  -  <a href="javascript:M.block_timetable.view_subject()">Fächer</a>  -  <a href="javascript:M.block_timetable.view_room()">Räume</a></div>'; | ||||||
| 	} elseif ($USER->department) { | 	} elseif ($USER->department) { | ||||||
| 		$class = $USER->department; | 		$class = $USER->department; | ||||||
| 		$class = str_replace("_", "/", $class); | 		$class = str_replace("_", "/", $class); | ||||||
|  | @ -91,7 +94,7 @@ class block_timetable extends block_base { | ||||||
| 	//$context_id = get_context_instance_by_id($course->id);
 | 	//$context_id = get_context_instance_by_id($course->id);
 | ||||||
| 	//echo "Contextid = $contextid->contextlevel\n";
 | 	//echo "Contextid = $contextid->contextlevel\n";
 | ||||||
| 
 | 
 | ||||||
| 
 | 	/* | ||||||
| 	$numdayweek = 5 + get_config('timetable', 'saturday'); | 	$numdayweek = 5 + get_config('timetable', 'saturday'); | ||||||
| 
 | 
 | ||||||
| 	$date = new DateTime(); | 	$date = new DateTime(); | ||||||
|  | @ -113,10 +116,48 @@ class block_timetable extends block_base { | ||||||
| 	$this->content->text .= $monday->format('d.m') . " - " . $lastday->format('d.m'); | 	$this->content->text .= $monday->format('d.m') . " - " . $lastday->format('d.m'); | ||||||
| 	//$ttable = new timetable('class',$class);
 | 	//$ttable = new timetable('class',$class);
 | ||||||
| 	$ttable->read_db($week); | 	$ttable->read_db($week); | ||||||
|  | 	 */ | ||||||
|  | 	//$this->content->text .= $ttable->monday->format('d.m') . " - " . $ttable->lastday->format('d.m');
 | ||||||
|  | 		 | ||||||
|  | 	$jsmodule = array( | ||||||
|  | 			'name'     => 'block_timetable', | ||||||
|  | 			'fullpath' => '/blocks/timetable/module.js', | ||||||
|  | 			'requires' => array() | ||||||
|  | 		); | ||||||
|  | 	$opts =Array(); | ||||||
|  | 	$opts['someinstancesetting'] = 1; | ||||||
|  | 	$PAGE->requires->js_init_call('M.block_timetable.helper.init', array($opts),false,$jsmodule); | ||||||
|  | 
 | ||||||
| 	$this->content->text .= html_writer::start_tag('div', ['data-region' => 'calendar', 'class' => 'maincalendar']);	 | 	$this->content->text .= html_writer::start_tag('div', ['data-region' => 'calendar', 'class' => 'maincalendar']);	 | ||||||
| 	$this->content->text .= $ttable->print_table($view); | 	$this->content->text .= html_writer::start_tag('div', ['class' =>'slider']);	 | ||||||
|  | 	$this->content->text .= html_writer::start_tag('div', ['class' =>'slides']);	 | ||||||
|  | 	for ($i=0; $i<3; $i++) { | ||||||
|  | 		$ttable->read_db($i); | ||||||
|  | //		$this->content->text .= $ttable->print_navigation($i);
 | ||||||
|  | 		//$this->content->text .= html_writer::start_tag('div', ['class' =>'slide', 'id'=>"slide-$i", 'data-region' => 'calendar']);	
 | ||||||
|  | 		$this->content->text .= html_writer::start_tag('div', ['class' => 'slide', 'id'=>"slide-$i"]);	 | ||||||
|  | 		//$this->content->text .= $ttable->print_table($view1);
 | ||||||
|  | 		$this->content->text .= $ttable->print_table($view1,$i); | ||||||
|  | 		$this->content->text .= $ttable->print_table($view2,$i); | ||||||
|  | 		$this->content->text .= $ttable->print_table('room',$i); | ||||||
|  | 		$this->content->text .= html_writer::end_tag('div'); | ||||||
|  | 	} | ||||||
|  | 	$this->content->text .= html_writer::end_tag('div'); | ||||||
|  | 	$this->content->text .= html_writer::end_tag('div'); | ||||||
| 	$this->content->text .= html_writer::end_tag('div'); | 	$this->content->text .= html_writer::end_tag('div'); | ||||||
| 
 | 
 | ||||||
|  | 	/* | ||||||
|  | 	$this->content->text .= html_writer::start_tag('div', ['data-region' => 'calendar', 'style' => 'display: none;']);	 | ||||||
|  | 	$this->content->text .= $ttable->print_table($view1); | ||||||
|  | 	$this->content->text .= html_writer::end_tag('div'); | ||||||
|  | 	$this->content->text .= html_writer::start_tag('div', ['data-region' => 'calendar', 'style' => 'display: none;']);	 | ||||||
|  | 	$this->content->text .= $ttable->print_table($view2); | ||||||
|  | 	$this->content->text .= html_writer::end_tag('div'); | ||||||
|  | 	$this->content->text .= html_writer::start_tag('div', ['data-region' => 'calendar', 'style' => 'displaay: none;']);	 | ||||||
|  | 	$this->content->text .= $ttable->print_table('room'); | ||||||
|  | 	$this->content->text .= html_writer::end_tag('div'); | ||||||
|  | 	$this->content->text .= html_writer::end_tag('div'); | ||||||
|  | 	 */ | ||||||
|         return $this->content; |         return $this->content; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -34,6 +34,13 @@ class timetable { | ||||||
| 	$this->type = $type; | 	$this->type = $type; | ||||||
| 	$this->name = $name; | 	$this->name = $name; | ||||||
| 	$this->periodmax=0; | 	$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(); | 	$this->data = array(); | ||||||
| 	for ($i=1; $i<=6; $i++) $this->data[$i] = array(); | 	for ($i=1; $i<=6; $i++) $this->data[$i] = array(); | ||||||
|     } |     } | ||||||
|  | @ -45,15 +52,61 @@ class timetable { | ||||||
|     public function read_db($week) { |     public function read_db($week) { | ||||||
|         global $USER, $DB, $CFG; |         global $USER, $DB, $CFG; | ||||||
| 
 | 
 | ||||||
| 	$this->week = $week; | 	$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 not (mid(week, $this->week, 1) = '0')"; | ||||||
| 	//$sql = "$this->type = '$this->name' and (mid(week, $this->week, 1) = '1')";
 | 	//$sql = "$this->type = '$this->name' and (mid(week, $this->week, 1) = '1')";
 | ||||||
| 	if ($result = $DB->get_records_select('timetable_lesson',$sql)) { | 	if ($result = $DB->get_records_select('timetable_lesson',$sql)) { | ||||||
| 		foreach ($result as $lesson) { | 		foreach ($result as $lesson) { | ||||||
| 			$this->data[$lesson->day][$lesson->period][] = $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; | 			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")); | ||||||
|  | 
 | ||||||
|  |     	} | ||||||
|  |   | ||||||
|  | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | @ -61,14 +114,68 @@ class timetable { | ||||||
|      * |      * | ||||||
|      * @return int |      * @return int | ||||||
|      */ |      */ | ||||||
|     public function print_table($view) { |     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('<a href="#slide-'.($week-1).'" class="arrow_link previous" title="Vorherige Woche" data-week="-1"><span class="arrow">◄</span></a>'); | ||||||
|  | 	    } else { | ||||||
|  | 	    	$tablerow->cells[] = new \html_table_cell(''); | ||||||
|  | 	    } | ||||||
|  | 	    $tablerow->cells[] = new \html_table_cell('<a href="#">'.$this->monday->format('d.m') . " - " . $this->lastday->format('d.m').'</a>'); | ||||||
|  | 	    if ($week<2) { | ||||||
|  | 	    	$tablerow->cells[] = new \html_table_cell('<a href="#slide-'.($week+1).'" class="arrow_link next" title="Nächste Woche" data-month="8" data-week="1"><span class="arrow">►</span></a>'); | ||||||
|  | 	    } 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 .= '<a href="#slide-'.($week-1).'" class="arrow_link previous" title="Vorherige Woche" data-week="-1"><span class="arrow">◄</span></a>'; | ||||||
|  | 	    } else { | ||||||
|  | 	    	$result .=  '<a href="#" class="previous" style="visibility:hidden" data-week="-1"></A>'; | ||||||
|  | 	    	//$result .= '<a href="#" class="arrow_link previous" data-week="-1"><span class="arrow" style="display:none"></span></a>';
 | ||||||
|  | 	    } | ||||||
|  | 	    $result .= '<span class="hide"> | </span>'; | ||||||
|  | 	    $result .= '<span class="current">'; | ||||||
|  | 	    $result .= '<a href="#">'.$this->monday->format('d.m') . " - " . $this->lastday->format('d.m').'</a>'; | ||||||
|  | 	    $result .= "</span>"; | ||||||
|  | 	    $result .= '<span class="hide"> | </span>'; | ||||||
|  | 	    if ($week<2) { | ||||||
|  | 	    	$result .= '<a href="#slide-'.($week+1).'" class="arrow_link next" title="Nächste Woche" data-month="8" data-week="1"><span class="arrow">►</span></a>'; | ||||||
|  | 	    } else { | ||||||
|  | 	    	$result .= ''; | ||||||
|  | 	    } | ||||||
|  | 	return $result; | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     public function print_table($view,$week) { | ||||||
| 	global $DB; | 	global $DB; | ||||||
| 	//var_dump($this->data[1]);
 | 	//var_dump($this->data[1]);
 | ||||||
| 	$numperiod = get_config('timetable', 'numperiod'); | 	$numperiod = get_config('timetable', 'numperiod'); | ||||||
| 	$numdayweek = 5 + get_config('timetable', 'saturday'); | 	$numdayweek = 5 + get_config('timetable', 'saturday'); | ||||||
| 	if ($this->periodmax>$numperiod) $numperiod = $this->periodmax; | 	if ($this->periodmax>$numperiod) $numperiod = $this->periodmax; | ||||||
| 	$table = new \html_table(); | 	$table = new \html_table(); | ||||||
| 	$table->attributes['class'] = 'minicalendar calendartable generaltable'; | 	//$table->attributes['class'] = "minicalendar calendartable generaltable timetable_view_$view";
 | ||||||
|  | 	$table->attributes['class'] = "minicalendar calendartable generaltable timetable_view_$view"; | ||||||
|  | 	$table->caption = "<div class='calendar-controls'>".$this->get_caption($week)."</div>"; | ||||||
|  | 	//$table->style = 'display: none;';
 | ||||||
| 	$table->head = array('','Mo','Di', 'Mi' , 'Do', 'Fr'); | 	$table->head = array('','Mo','Di', 'Mi' , 'Do', 'Fr'); | ||||||
| 	if ($numdayweek == 6) $table->head[] = 'Sa'; | 	if ($numdayweek == 6) $table->head[] = 'Sa'; | ||||||
| 	for ($i = 1; $i<=$numperiod; $i++) { | 	for ($i = 1; $i<=$numperiod; $i++) { | ||||||
|  | @ -79,13 +186,19 @@ class timetable { | ||||||
| 		$tablerow->cells[] = $cell; | 		$tablerow->cells[] = $cell; | ||||||
| 		for ($k = 1; $k <= $numdayweek; $k++) { | 		for ($k = 1; $k <= $numdayweek; $k++) { | ||||||
| 			$flag = 0; | 			$flag = 0; | ||||||
| 			if (array_key_exists($i,$this->data[$k])) { | 			if (array_key_exists($i,$this->data[$k]) && array_key_exists('lesson',$this->data[$k][$i])) { | ||||||
| 				$content = ""; | 				$content = ""; | ||||||
| 				foreach ($this->data[$k][$i] as $lesson) { | 				foreach ($this->data[$k][$i]['lesson'] as $lesson) { | ||||||
| 					if ($content) $content .= "<br>"; | 					if ($content) $content .= "<br>"; | ||||||
| 					if ($lesson->flag) $content .= "<span style='color:red;'>"; | 					if ($lesson->flag) $content .= "<span style='color:red;'>"; | ||||||
| 					//if (substr($lesson->week,$this->week,1) == '1') $content .= $lesson->{$view};
 | 					//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] == '1') { | ||||||
|  | 						if ($lesson->{$view}) { | ||||||
|  | 							$content .= $lesson->{$view}; | ||||||
|  | 						} else { | ||||||
|  | 							$content .= "+++"; | ||||||
|  | 						}  | ||||||
|  | 					} | ||||||
| 					if ($lesson->week[$this->week-1] == 'x') $content .= "---"; | 					if ($lesson->week[$this->week-1] == 'x') $content .= "---"; | ||||||
| 					if ($lesson->flag) $content .= "</span>"; | 					if ($lesson->flag) $content .= "</span>"; | ||||||
| 					$flag += $lesson->flag; | 					$flag += $lesson->flag; | ||||||
|  | @ -93,8 +206,19 @@ class timetable { | ||||||
| 			} else { | 			} else { | ||||||
| 				$content = "-"; | 				$content = "-"; | ||||||
| 			} | 			} | ||||||
|  | 			$subtxt = ""; | ||||||
|  | 			if (array_key_exists($i,$this->data[$k]) && array_key_exists('substitution', $this->data[$k][$i])) { | ||||||
|  | 				foreach ($this->data[$k][$i]['substitution'] as $substitution) { | ||||||
|  | 					$subtxt .= $substitution->text; | ||||||
|  | 				} | ||||||
|  | 				if ($subtxt) { | ||||||
|  | 					$content = "<a href='#' data-toggle='tooltip' title='$subtxt'>$content</a>"; | ||||||
|  | 					//$content .= "<span class='tooltiptext'>$subtxt</span>";
 | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
| 			$cell = new \html_table_cell($content); | 			$cell = new \html_table_cell($content); | ||||||
| //			if ($flag) $cell->style = 'color: red;';
 | //			if ($flag) $cell->style = 'color: red;';
 | ||||||
|  | 			//if (array_key_exists($i, $this->data[$k] ) && array_key_exists('substitution', $this->data[$k][$i])) $cell->attributes['class'] = 'tooltip';
 | ||||||
| 			$tablerow->cells[] = $cell; | 			$tablerow->cells[] = $cell; | ||||||
| 		} | 		} | ||||||
| 		$table->data[] = $tablerow; | 		$table->data[] = $tablerow; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 L_DA
						L_DA