. /** * Block timetable is defined here. * * @package block_timetable * @copyright 2020 Raphael Dannecker * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** * timetable block. * * @package block_timetable * @copyright 2020 Raphael Dannecker * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class block_timetable extends block_base { /** * Initializes class member variables. */ public function init() { // Needed by Moodle to differentiate between blocks. $this->title = get_string('pluginname', 'block_timetable'); } /** * Returns the block contents. * * @return stdClass The block contents. */ public function get_content() { global $USER, $PAGE; if ($this->content !== null) { return $this->content; } if (empty($this->instance)) { $this->content = ''; return $this->content; } $this->content = new stdClass(); $this->content->items = array(); $this->content->icons = array(); $this->content->footer = ''; /* $view1 = 'subject'; $view2 = 'teacher'; if ($this->page->course->idnumber && $this->page->course->shortname) { $class = $this->page->course->shortname; $this->content->text .= "Stundenplan der Klasse $class
"; $ttable = new timetable('class',$class); } elseif ($USER->department == "Lehrer" || $USER->department == "Lehrer_fvs") { $teacher = $USER->username; $teacher = str_replace("l_", "", $teacher); $teacher = str_replace("-fvs", "", $teacher); $this->content->text .= "Stundenplan von ".(substr($USER->firstname,0,1)).". {$USER->lastname}
"; $ttable = new \mod\timetable\timetable('teacher',$teacher); $view1 = 'class'; $view2 = 'subject'; $this->content->footer = ''; } elseif ($USER->department) { $class = $USER->department; $class = str_replace("_", "/", $class); $this->content->text .= "Stundenplan der Klasse $class
"; $ttable = new \mod\timetable\timetable('class',$class); } else { return $this->content; } */ $today = new \DateTime(); $week = $today->format("W"); $dayofweek = $today->format('w'); if ($dayofweek > 5 + get_config('timetable', 'saturday')) { $week++; } $ttable = new \mod_timetable\timetable('teacher','Da'); $ttable->read_db($week); /* for ($i=0; $i<3; $i++) { $ttable->read_db($i); } */ /* if (!empty($this->config->text)) { $this->content->text = $this->config->text; } else { $text = 'Please define the content text in /blocks/timetable/block_timetable.php.'; $this->content->text = $text; } */ $output = $PAGE->get_renderer('mod_timetable'); $renderable = new \mod_timetable\output\timetable($ttable); $this->content->text = $output->render($renderable); return $this->content; } /** * Defines configuration data. * * The function is called immediatly after init(). */ public function specialization() { // Load user defined title and make sure it's never empty. if (empty($this->config->title)) { $this->title = get_string('pluginname', 'block_timetable'); } else { $this->title = $this->config->title; } } /** * Enables global configuration of the block in settings.php. * * @return bool True if the global configuration is enabled. */ function has_config() { return true; } /** * Sets the applicable formats for the block. * * @return string[] Array of pages and permissions. */ public function applicable_formats() { return array('all' => true, 'site' => true, 'site-index' => true, 'course-view' => true, 'course-view-social' => false, 'mod' => true, 'mod-quiz' => false); } }