5/6 day week (saturday)
block on dashboard too automatic detection wheater class or teacher plan automatic next week detection (rd)
This commit is contained in:
parent
cd4a4c19a3
commit
60c4b8e1f8
5 changed files with 57 additions and 25 deletions
|
@ -33,7 +33,7 @@ class block_timetable extends block_base {
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_content() {
|
function get_content() {
|
||||||
global $CFG, $OUTPUT;
|
global $CFG, $OUTPUT, $USER;
|
||||||
|
|
||||||
if ($this->content !== null) {
|
if ($this->content !== null) {
|
||||||
return $this->content;
|
return $this->content;
|
||||||
|
@ -48,7 +48,9 @@ class block_timetable extends block_base {
|
||||||
$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 = 'Fächer<br>Lehrer<br>Räume';
|
||||||
|
$this->content->text = "";
|
||||||
|
|
||||||
|
/*
|
||||||
// user/index.php expect course context, so get one if page has module context.
|
// user/index.php expect course context, so get one if page has module context.
|
||||||
$currentcontext = $this->page->context->get_course_context(false);
|
$currentcontext = $this->page->context->get_course_context(false);
|
||||||
|
|
||||||
|
@ -63,29 +65,53 @@ class block_timetable extends block_base {
|
||||||
if ($this->page->course->id == SITEID) {
|
if ($this->page->course->id == SITEID) {
|
||||||
$this->content->text .= "site context";
|
$this->content->text .= "site context";
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
$view = 'subject';
|
||||||
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;
|
||||||
$class = 'TG11/3';
|
|
||||||
$this->content->text .= "Stundenplan der Klasse $class<br>";
|
$this->content->text .= "Stundenplan der Klasse $class<br>";
|
||||||
} //elseif ($USER->
|
$ttable = new timetable('class',$class);
|
||||||
|
} elseif ($USER->department == "Lehrer") {
|
||||||
|
$teacher = $USER->username;
|
||||||
|
$teacher = str_replace("l_", "", $teacher);
|
||||||
|
$teacher = str_replace("-fvs", "", $teacher);
|
||||||
|
//echo var_dump($USER);
|
||||||
|
$this->content->text .= "Stundenplan von Lehrer*in $teacher<br>";
|
||||||
|
$ttable = new timetable('teacher',$teacher);
|
||||||
|
$view = 'class';
|
||||||
|
} elseif ($USER->department) {
|
||||||
|
$class = $USER->department;
|
||||||
|
$class = str_replace("_", "/", $class);
|
||||||
|
$this->content->text .= "Stundenplan der Klasse $class<br>";
|
||||||
|
$ttable = new timetable('class',$class);
|
||||||
|
} else {
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
|
||||||
//$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');
|
||||||
|
|
||||||
$date = new DateTime();
|
$date = new DateTime();
|
||||||
$monday = new DateTime();
|
$monday = new DateTime();
|
||||||
$friday = new DateTime();
|
|
||||||
$week = $date->format("W");
|
|
||||||
$dayofweek = $date->format('w')-1;
|
|
||||||
|
|
||||||
|
$dayofweek = $date->format('w')-1;
|
||||||
|
if ($dayofweek >= $numdayweek) {
|
||||||
|
$monday->add(new DateInterval("P".(7-$dayofweek)."D"));
|
||||||
|
} else {
|
||||||
$monday->sub(new DateInterval("P{$dayofweek}D"));
|
$monday->sub(new DateInterval("P{$dayofweek}D"));
|
||||||
$friday->add(new DateInterval("P".(4-$dayofweek)."D"));
|
}
|
||||||
$this->content->text .= $monday->format('d.m') . " - " . $friday->format('d.m');
|
|
||||||
$ttable = new timetable('class','TG11/3');
|
$week = $monday->format("W");
|
||||||
|
$lastday = new DateTime($monday->format('Y-m-d\TH:i:sP'));
|
||||||
|
$lastday->add(new DateInterval("P".($numdayweek-1)."D"));
|
||||||
|
$this->content->text .= $monday->format('d.m') . " - " . $lastday->format('d.m');
|
||||||
|
//$ttable = new timetable('class',$class);
|
||||||
$ttable->read_db($week);
|
$ttable->read_db($week);
|
||||||
$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('subject');
|
$this->content->text .= $ttable->print_table($view);
|
||||||
$this->content->text .= html_writer::end_tag('div');
|
$this->content->text .= html_writer::end_tag('div');
|
||||||
|
|
||||||
return $this->content;
|
return $this->content;
|
||||||
|
@ -93,7 +119,7 @@ class block_timetable extends block_base {
|
||||||
|
|
||||||
// my moodle can only have SITEID and it's redundant here, so take it away
|
// my moodle can only have SITEID and it's redundant here, so take it away
|
||||||
public function applicable_formats() {
|
public function applicable_formats() {
|
||||||
return array('all' => false,
|
return array('all' => true,
|
||||||
'site' => true,
|
'site' => true,
|
||||||
'site-index' => true,
|
'site-index' => true,
|
||||||
'course-view' => true,
|
'course-view' => true,
|
||||||
|
|
|
@ -35,7 +35,7 @@ class timetable {
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->periodmax=0;
|
$this->periodmax=0;
|
||||||
$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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,7 +46,8 @@ class timetable {
|
||||||
global $USER, $DB, $CFG;
|
global $USER, $DB, $CFG;
|
||||||
|
|
||||||
$this->week = $week;
|
$this->week = $week;
|
||||||
$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')";
|
||||||
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;
|
$this->data[$lesson->day][$lesson->period][] = $lesson;
|
||||||
|
@ -63,31 +64,35 @@ class timetable {
|
||||||
public function print_table($view) {
|
public function print_table($view) {
|
||||||
global $DB;
|
global $DB;
|
||||||
//var_dump($this->data[1]);
|
//var_dump($this->data[1]);
|
||||||
$numperiod = $period_max = get_config('timetable', 'numperiod');
|
$numperiod = get_config('timetable', 'numperiod');
|
||||||
|
$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';
|
||||||
$table->head = array('','Mo','Di', 'Mi' , 'Do', 'Fr');
|
$table->head = array('','Mo','Di', 'Mi' , 'Do', 'Fr');
|
||||||
|
if ($numdayweek == 6) $table->head[] = 'Sa';
|
||||||
for ($i = 1; $i<=$numperiod; $i++) {
|
for ($i = 1; $i<=$numperiod; $i++) {
|
||||||
$tablerow = new \html_table_row();
|
$tablerow = new \html_table_row();
|
||||||
$cell = new \html_table_cell($i);
|
$cell = new \html_table_cell($i);
|
||||||
$cell->style = 'font-weight: bold;';
|
$cell->style = 'font-weight: bold;';
|
||||||
// $cell->attributes['class'] = 'header';
|
// $cell->attributes['class'] = 'header';
|
||||||
$tablerow->cells[] = $cell;
|
$tablerow->cells[] = $cell;
|
||||||
for ($k = 1; $k <= 5; $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])) {
|
||||||
$content = "";
|
$content = "";
|
||||||
foreach ($this->data[$k][$i] as $lesson) {
|
foreach ($this->data[$k][$i] as $lesson) {
|
||||||
if ($content) $content .= "<br>";
|
if ($content) $content .= "<br>";
|
||||||
|
if ($lesson->flag) $content .= "<span style='color:red;'>";
|
||||||
$content .= $lesson->{$view};
|
$content .= $lesson->{$view};
|
||||||
|
if ($lesson->flag) $content .= "</span>";
|
||||||
$flag += $lesson->flag;
|
$flag += $lesson->flag;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$content = "-";
|
$content = "-";
|
||||||
}
|
}
|
||||||
$cell = new \html_table_cell($content);
|
$cell = new \html_table_cell($content);
|
||||||
if ($flag) $cell->style = 'color: red;';
|
// if ($flag) $cell->style = 'color: red;';
|
||||||
$tablerow->cells[] = $cell;
|
$tablerow->cells[] = $cell;
|
||||||
}
|
}
|
||||||
$table->data[] = $tablerow;
|
$table->data[] = $tablerow;
|
||||||
|
|
|
@ -36,3 +36,5 @@ $string['labelfnamelesson'] = 'import file';
|
||||||
$string['descfnamelesson'] = 'Absolute path and Filename of untis import file lesson.txt';
|
$string['descfnamelesson'] = 'Absolute path and Filename of untis import file lesson.txt';
|
||||||
$string['labelnumperiod'] = 'max period';
|
$string['labelnumperiod'] = 'max period';
|
||||||
$string['descnumperiod'] = 'max period per day';
|
$string['descnumperiod'] = 'max period per day';
|
||||||
|
$string['labelsaturday'] = 'saturday';
|
||||||
|
$string['descsaturday'] = 'enabled if saturday in timetable';
|
||||||
|
|
|
@ -27,12 +27,11 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
$settings->add(new admin_setting_heading('sampleheader',
|
$settings->add(new admin_setting_heading('sampleheader',
|
||||||
get_string('headerconfig', 'block_timetable'),
|
get_string('headerconfig', 'block_timetable'),
|
||||||
get_string('descconfig', 'block_timetable')));
|
get_string('descconfig', 'block_timetable')));
|
||||||
|
|
||||||
$settings->add(new admin_setting_configcheckbox('timetable/foo',
|
|
||||||
get_string('labelfoo', 'block_timetable'),
|
|
||||||
get_string('descfoo', 'block_timetable'),
|
|
||||||
'0'));
|
|
||||||
*/
|
*/
|
||||||
|
$settings->add(new admin_setting_configcheckbox('timetable/saturday',
|
||||||
|
get_string('labelsaturday', 'block_timetable'),
|
||||||
|
get_string('descsaturday', 'block_timetable'),
|
||||||
|
'0'));
|
||||||
|
|
||||||
$settings->add(new admin_setting_configtext('timetable/fnamelesson',
|
$settings->add(new admin_setting_configtext('timetable/fnamelesson',
|
||||||
get_string('labelfnamelesson', 'block_timetable'),
|
get_string('labelfnamelesson', 'block_timetable'),
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
$plugin->version = 2020062504; // The current plugin version (Date: YYYYMMDDXX)
|
$plugin->version = 2020062702; // The current plugin version (Date: YYYYMMDDXX)
|
||||||
$plugin->requires = 2012112900; // Requires this Moodle version
|
$plugin->requires = 2012112900; // Requires this Moodle version
|
||||||
$plugin->component = 'block_timetable'; // Full name of the plugin (used for diagnostics)
|
$plugin->component = 'block_timetable'; // Full name of the plugin (used for diagnostics)
|
||||||
|
|
Loading…
Add table
Reference in a new issue