diff --git a/block_timetable.php b/block_timetable.php
index a398089..eef4c65 100644
--- a/block_timetable.php
+++ b/block_timetable.php
@@ -33,7 +33,7 @@ class block_timetable extends block_base {
}
function get_content() {
- global $CFG, $OUTPUT;
+ global $CFG, $OUTPUT, $USER;
if ($this->content !== null) {
return $this->content;
@@ -47,8 +47,10 @@ class block_timetable extends block_base {
$this->content = new stdClass();
$this->content->items = array();
$this->content->icons = array();
- $this->content->footer = 'Fächer
Lehrer
Räume';
+ $this->content->footer = 'Fächer
Lehrer
Räume';
+ $this->content->text = "";
+ /*
// user/index.php expect course context, so get one if page has module context.
$currentcontext = $this->page->context->get_course_context(false);
@@ -63,29 +65,53 @@ class block_timetable extends block_base {
if ($this->page->course->id == SITEID) {
$this->content->text .= "site context";
}
+ */
+ $view = 'subject';
if ($this->page->course->idnumber && $this->page->course->shortname) {
$class = $this->page->course->shortname;
- $class = 'TG11/3';
- $this->content->text .= "Stundenplan der Klasse $class
";
- } //elseif ($USER->
+ $this->content->text .= "Stundenplan der Klasse $class
";
+ $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
";
+ $ttable = new timetable('teacher',$teacher);
+ $view = 'class';
+ } elseif ($USER->department) {
+ $class = $USER->department;
+ $class = str_replace("_", "/", $class);
+ $this->content->text .= "Stundenplan der Klasse $class
";
+ $ttable = new timetable('class',$class);
+ } else {
+ return $this->content;
+ }
//$context_id = get_context_instance_by_id($course->id);
//echo "Contextid = $contextid->contextlevel\n";
+ $numdayweek = 5 + get_config('timetable', 'saturday');
+
$date = new DateTime();
$monday = new DateTime();
- $friday = new DateTime();
- $week = $date->format("W");
+
$dayofweek = $date->format('w')-1;
-
- $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');
+ if ($dayofweek >= $numdayweek) {
+ $monday->add(new DateInterval("P".(7-$dayofweek)."D"));
+ } else {
+ $monday->sub(new DateInterval("P{$dayofweek}D"));
+ }
+
+ $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);
$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');
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
public function applicable_formats() {
- return array('all' => false,
+ return array('all' => true,
'site' => true,
'site-index' => true,
'course-view' => true,
diff --git a/classes/timetable.php b/classes/timetable.php
index 74b47cc..bfe6fe9 100755
--- a/classes/timetable.php
+++ b/classes/timetable.php
@@ -35,7 +35,7 @@ class timetable {
$this->name = $name;
$this->periodmax=0;
$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;
$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)) {
foreach ($result as $lesson) {
$this->data[$lesson->day][$lesson->period][] = $lesson;
@@ -63,31 +64,35 @@ class timetable {
public function print_table($view) {
global $DB;
//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;
$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 <= 5; $k++) {
+ 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 .= "";
$content .= $lesson->{$view};
+ if ($lesson->flag) $content .= "";
$flag += $lesson->flag;
}
} else {
$content = "-";
}
$cell = new \html_table_cell($content);
- if ($flag) $cell->style = 'color: red;';
+// if ($flag) $cell->style = 'color: red;';
$tablerow->cells[] = $cell;
}
$table->data[] = $tablerow;
diff --git a/lang/en/block_timetable.php b/lang/en/block_timetable.php
index 4af5280..320917c 100644
--- a/lang/en/block_timetable.php
+++ b/lang/en/block_timetable.php
@@ -36,3 +36,5 @@ $string['labelfnamelesson'] = 'import file';
$string['descfnamelesson'] = 'Absolute path and Filename of untis import file lesson.txt';
$string['labelnumperiod'] = 'max period';
$string['descnumperiod'] = 'max period per day';
+$string['labelsaturday'] = 'saturday';
+$string['descsaturday'] = 'enabled if saturday in timetable';
diff --git a/settings.php b/settings.php
index 16e7190..b7586fe 100644
--- a/settings.php
+++ b/settings.php
@@ -27,12 +27,11 @@ defined('MOODLE_INTERNAL') || die();
$settings->add(new admin_setting_heading('sampleheader',
get_string('headerconfig', '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',
get_string('labelfnamelesson', 'block_timetable'),
diff --git a/version.php b/version.php
index 7a5b1b7..4af4a6a 100644
--- a/version.php
+++ b/version.php
@@ -24,6 +24,6 @@
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->component = 'block_timetable'; // Full name of the plugin (used for diagnostics)