commit 784cb23da30890986e5bd754861990abf9b14410 Author: root Date: Fri Jun 26 11:30:19 2020 +0000 Initial commit of timetable-Module (rd) diff --git a/README.md b/README.md new file mode 100644 index 0000000..9a41604 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +Moodle Block Timetable +====================== + +This Module provides a timetable based on untis export-files: lesson.txt, substitution.txt diff --git a/block_timetable.php b/block_timetable.php new file mode 100644 index 0000000..b465d77 --- /dev/null +++ b/block_timetable.php @@ -0,0 +1,190 @@ +. + +/** + * Newblock block caps. + * + * @package block_timetable + * @copyright Daniel Neis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +use block_timetable\timetable; + +class block_timetable extends block_base { + + function init() { + $this->title = get_string('pluginname', 'block_timetable'); + } + + function get_content() { + global $CFG, $OUTPUT; + + 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 = 'Faecher
Lehrer
Raeume'; + + // user/index.php expect course context, so get one if page has module context. + $currentcontext = $this->page->context->get_course_context(false); + + + if (! empty($this->config->text)) { + $this->content->text = $this->config->text; + } + + $this->content->text = ''; + if (empty($currentcontext)) { + return $this->content; + } + if ($this->page->course->id == SITEID) { + $this->content->text .= "site context"; + } + 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-> + + //$context_id = get_context_instance_by_id($course->id); + //echo "Contextid = $contextid->contextlevel\n"; + + /* + // Verbindung zu localhost auf port 3307 + $mysqli = new mysqli('mistral:3307', 'timetable_user1', 'd7jzRYpfGS3OkIpHCBEE','timetable'); + if ($mysqli->connect_errno) { + $this->content->text .= 'Verbindung schlug fehl: ' . $mysqli->connect_errno; + } + */ + $period_max = get_config('timetable', 'numperiod'); + $table = new html_table(); + $table->cellspacing = 0; + $table->cellpadding = 0; + $table->attributes['cellpadding'] = '0'; + $table->attributes['class'] = 'minicalendar calendartable'; +// $table->align = array('right','center','center','center','center','center'); +// $table->size = array('50', '50'); + $table->head = array('','Mo','Di', 'Mi' , 'Do', 'Fr'); + for ($i = 1; $i <= $period_max; $i++) { + $tablerow = new \html_table_row(); + $tablerow->cells[] = new html_table_cell($i); + for ($k = 1; $k <= 5; $k++) { + //$cell = new html_table_cell("$i+$k"); + $cell = new html_table_cell(""); + $cell->abbr = ""; +// $cell->attributes['class'] = 'day text-center'; + $tablerow->cells[] = $cell; + //$tablerow->cells[] = ''+"$i+$k"; + //$tablerow->cells[] = new html_table_cell("$i+$k"); + } + $table->data[] = $tablerow; + } + //$sql = "Select * from lesson where teacher = 'Hbr' and not (mid(week, 36, 1) = '0')"; + $sql = "teacher = 'Hbr' and not (mid(week, 26, 1) = '0')"; + if ($class) { + //$sql = "Select * from lesson where class = '$class' and not (mid(week, 37, 1) = '0')"; + $sql = "class = '$class' and not (mid(week, 26, 1) = '0')"; + } + global $DB; + if ($result = $DB->get_records_select('timetable_lesson',$sql)) { + foreach ($result as $lesson) { + if ($lesson->period < $period_max) { + if ($table->data[$lesson->period-1]->cells[$lesson->day]->text) + $table->data[$lesson->period-1]->cells[$lesson->day]->text .= "
"; + $table->data[$lesson->period-1]->cells[$lesson->day]->text .= $lesson->subject; + } + + } + } else { + echo "get_records_select failed\n"; + } + for ($i = 0; $i < $period_max; $i++) { + for ($k = 1; $k <= 5; $k++) { + if (!$table->data[$i]->cells[$k]->text) $table->data[$i]->cells[$k]->text = "-"; + } + } + +/* + if (!$result = $mysqli->query($sql)) { + // Oh no! The query failed. + $this->content->text .= "Sorry, the website is experiencing problems."; + } + while ($lesson = $result->fetch_assoc()) { +// if ($lesson['period']<5 && $lesson['day']<5); + //$table->data[$lesson['period']-1]->cells[$lesson['day']]->text = $lesson['subject']; + //$table->data[$lesson['period']-1]->cells[$lesson['day']]->text = $lesson['room']; + $table->data[$lesson['period']-1]->cells[$lesson['day']]->text = $lesson['class']; + } + */ + + //$table->data = array($row1, $row2); + $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'); + $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 .= html_writer::table($table); + $this->content->text .= html_writer::end_tag('div'); + + //$this->content->text .= file_get_contents("/var/www/plaene/25/c/mc00005.htm"); + //$mysqli->close(); + return $this->content; + } + + // my moodle can only have SITEID and it's redundant here, so take it away + public function applicable_formats() { + return array('all' => false, + 'site' => true, + 'site-index' => true, + 'course-view' => true, + 'course-view-social' => false, + 'mod' => true, + 'mod-quiz' => false); + } + + public function instance_allow_multiple() { + return true; + } + + function has_config() {return true;} + + public function cron() { + mtrace( "Hey, my cron script is running" ); + + // do something + + return true; + } +} diff --git a/classes/task/import_data.php b/classes/task/import_data.php new file mode 100644 index 0000000..87e4743 --- /dev/null +++ b/classes/task/import_data.php @@ -0,0 +1,91 @@ +start_delegated_transaction(); + echo "before delete\n"; + $DB->delete_records_select("timetable_lesson", "id>0"); + echo "after delete\n"; + $handle = @fopen($filename, "r"); + echo "after handle\n"; + while (($buffer = fgets($handle, 4096)) !== false) { +// echo $buffer; + $buffer = utf8_encode(rtrim($buffer)); + $data = explode("\t", $buffer); +// echo "Num elements: ".count($data)."\n"; + if (count($data) != 10) throw new Exception('Wrong size of elements'); +// echo "after count data \n"; +// echo "data 0 =$data[0]\n"; + + /* + $dataobject = new stdClass(); + //$dataobject = new object; + $dataobject->teacher = $data[0]; + $dataobject->day = $data[1]; + $dataobject->period = $data[2]; + $dataobject->subject = $data[3]; + $dataobject->room = $data[4]; + $dataobject->lessonid= $data[5]; + $dataobject->flag = $data[6]; + $dataobject->class = $data[7]; + $dataobject->week = $data[8]; + $dataobject->unknown = $data[9]; + */ + $dataobject = (object)array('teacher' => $data[0], + 'day' => $data[1], + 'period' => $data[2], + 'subject' => $data[3], + 'room' => $data[4], + 'lessonid'=> $data[5], + 'flag' => $data[6], + 'class' => $data[7], + 'week' => $data[8], + 'unknown' => $data[9]); + +// echo "after dataobject\n"; + $DB->insert_record("timetable_lesson", $dataobject); + } + $transaction->allow_commit(); + $lastmtime = $mtime; + set_config('lastmtime', $lastmtime, 'block_timetable'); + } catch(Exception $e) { + $transaction->rollback($e); + } + + } + // Apply fungus cream. + // Apply chainsaw. + // Apply olive oil. + } +} diff --git a/classes/timetable.php b/classes/timetable.php new file mode 100755 index 0000000..74b47cc --- /dev/null +++ b/classes/timetable.php @@ -0,0 +1,98 @@ +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 .= "
"; + $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); + } + +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..cd8c1fb --- /dev/null +++ b/composer.json @@ -0,0 +1,18 @@ +{ + "name": "dannecker/moodle-block_timetable", + "description": "A block template for Moodle based on http://docs.moodle.org/dev/Blocks", + "license": "GPLv3", + "authors": [ + { + "name": "Raphael Dannecker", + "email": "raphael.dannecker@steinbeisschule-reutlingen.de" + } + ], + "type": "moodle-block", + "require": { + "composer/installers": "~1.0" + }, + "extra": { + "installer-name": "timetable" + } +} diff --git a/db/access.php b/db/access.php new file mode 100644 index 0000000..2f11c15 --- /dev/null +++ b/db/access.php @@ -0,0 +1,51 @@ +. + +/** + * Newblock block caps. + * + * @package block_timetable + * @copyright Daniel Neis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$capabilities = array( + + 'block/timetable:myaddinstance' => array( + 'captype' => 'write', + 'contextlevel' => CONTEXT_SYSTEM, + 'archetypes' => array( + 'user' => CAP_ALLOW + ), + + 'clonepermissionsfrom' => 'moodle/my:manageblocks' + ), + + 'block/timetable:addinstance' => array( + 'riskbitmask' => RISK_SPAM | RISK_XSS, + + 'captype' => 'write', + 'contextlevel' => CONTEXT_BLOCK, + 'archetypes' => array( + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ), + + 'clonepermissionsfrom' => 'moodle/site:manageblocks' + ), +); diff --git a/db/install.xml b/db/install.xml new file mode 100644 index 0000000..070c946 --- /dev/null +++ b/db/install.xml @@ -0,0 +1,34 @@ + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+
+
diff --git a/db/tasks.php b/db/tasks.php new file mode 100644 index 0000000..f77f3a9 --- /dev/null +++ b/db/tasks.php @@ -0,0 +1,16 @@ + '\block_timetable\task\import_data', + 'blocking' => 0, + 'minute' => '*/10', + 'hour' => '*', + 'day' => '*', + 'month' => '*', + 'dayofweek' => '*', + ], +]; + diff --git a/db/upgrade.php b/db/upgrade.php new file mode 100644 index 0000000..81f331a --- /dev/null +++ b/db/upgrade.php @@ -0,0 +1,60 @@ +get_manager(); // Loads ddl manager and xmldb classes. + + if ($oldversion < 2020062400) { + + // Define table block_timetable to be created. + $table = new xmldb_table('block_timetable'); + + // Adding fields to table block_timetable. + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + + // Adding keys to table block_timetable. + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); + + // Conditionally launch create table for block_timetable. + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + // Define table timetable_lesson to be created. + $table = new xmldb_table('timetable_lesson'); + + // Adding fields to table timetable_lesson. + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('teacher', XMLDB_TYPE_CHAR, '20', null, null, null, null); + $table->add_field('day', XMLDB_TYPE_INTEGER, '2', null, null, null, null); + $table->add_field('period', XMLDB_TYPE_INTEGER, '2', null, null, null, null); + $table->add_field('subject', XMLDB_TYPE_CHAR, '20', null, null, null, null); + $table->add_field('room', XMLDB_TYPE_CHAR, '20', null, null, null, null); + $table->add_field('lessonid', XMLDB_TYPE_INTEGER, '7', null, null, null, null); + $table->add_field('flag', XMLDB_TYPE_INTEGER, '7', null, null, null, null); + $table->add_field('class', XMLDB_TYPE_CHAR, '20', null, null, null, null); + $table->add_field('week', XMLDB_TYPE_CHAR, '53', null, null, null, null); + $table->add_field('unknown', XMLDB_TYPE_INTEGER, '7', null, null, null, null); + + // Adding keys to table timetable_lesson. + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); + + // Conditionally launch create table for timetable_lesson. + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + // Timetable savepoint reached. + upgrade_block_savepoint(true, 2020062400, 'timetable'); + + + } + + + return $result; +} +?> diff --git a/edit_form.php b/edit_form.php new file mode 100644 index 0000000..e76fc01 --- /dev/null +++ b/edit_form.php @@ -0,0 +1,16 @@ +addElement('header', 'configheader', get_string('blocksettings', 'block')); + + // A sample string variable with a default value. + $mform->addElement('text', 'config_text', get_string('blockstring', 'block_timetable')); + $mform->setDefault('config_text', 'default value'); + $mform->setType('config_text', PARAM_TEXT); + + } +} diff --git a/lang/de/block_timetable.php b/lang/de/block_timetable.php new file mode 100644 index 0000000..36c9b7b --- /dev/null +++ b/lang/de/block_timetable.php @@ -0,0 +1,33 @@ +. + +/** + * Strings for component 'block_timetable', language 'en' + * + * @package block_timetable + * @copyright Daniel Neis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['blockstring'] = 'Block string'; +$string['descconfig'] = 'Description of the config section'; +$string['descfoo'] = 'Config description'; +$string['headerconfig'] = 'Config section header'; +$string['labelfoo'] = 'Config label'; +$string['timetable:addinstance'] = 'Add a timetable block'; +$string['timetable:myaddinstance'] = 'Add a timetable block to my moodle'; +$string['pluginname'] = 'Stundenplan'; diff --git a/lang/en/block_timetable.php b/lang/en/block_timetable.php new file mode 100644 index 0000000..4af5280 --- /dev/null +++ b/lang/en/block_timetable.php @@ -0,0 +1,38 @@ +. + +/** + * Strings for component 'block_timetable', language 'en' + * + * @package block_timetable + * @copyright Daniel Neis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['blockstring'] = 'Block string'; +$string['descconfig'] = 'Description of the config section'; +$string['descfoo'] = 'Config description'; +$string['headerconfig'] = 'Config section header'; +$string['labelfoo'] = 'Config label'; +$string['timetable:addinstance'] = 'Add a timetable block'; +$string['timetable:myaddinstance'] = 'Add a timetable block to my moodle'; +$string['pluginname'] = 'Timetable'; +$string['import_data'] = 'import_data'; +$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'; diff --git a/settings.php b/settings.php new file mode 100644 index 0000000..f859317 --- /dev/null +++ b/settings.php @@ -0,0 +1,45 @@ +. + +/** + * Newblock block caps. + * + * @package block_timetable + * @copyright Daniel Neis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +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_configtext('timetable/fnamelesson', + get_string('labelfnamelesson', 'block_timetable'), + get_string('descfnamelesson', 'block_timetable'), + '')); + +$settings->add(new admin_setting_configtext('timetable/numperiod', + get_string('labelnumperiod', 'block_timetable'), + get_string('descnumperiod', 'block_timetable'), + 12, PARAM_INT)); diff --git a/version.php b/version.php new file mode 100644 index 0000000..7a5b1b7 --- /dev/null +++ b/version.php @@ -0,0 +1,29 @@ +. + +/** + * Version details + * + * @package block_timetable + * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->version = 2020062504; // 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)