184 lines
8.7 KiB
PHP
184 lines
8.7 KiB
PHP
![]() |
<?php
|
||
|
// This file is part of Moodle - https://moodle.org/
|
||
|
//
|
||
|
// Moodle is free software: you can redistribute it and/or modify
|
||
|
// it under the terms of the GNU General Public License as published by
|
||
|
// the Free Software Foundation, either version 3 of the License, or
|
||
|
// (at your option) any later version.
|
||
|
//
|
||
|
// Moodle is distributed in the hope that it will be useful,
|
||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
// GNU General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
|
||
|
|
||
|
/**
|
||
|
* Plugin upgrade steps are defined here.
|
||
|
*
|
||
|
* @package mod_timetable
|
||
|
* @category upgrade
|
||
|
* @copyright 2020 Raphael Dannecker <raphael.dannecker@steinbeisschule-reutlingen.de>
|
||
|
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||
|
*/
|
||
|
|
||
|
defined('MOODLE_INTERNAL') || die();
|
||
|
|
||
|
/**
|
||
|
* Execute mod_timetable upgrade from the given old version.
|
||
|
*
|
||
|
* @param int $oldversion
|
||
|
* @return bool
|
||
|
*/
|
||
|
function xmldb_timetable_upgrade($oldversion) {
|
||
|
global $DB;
|
||
|
|
||
|
$dbman = $DB->get_manager();
|
||
|
|
||
|
// For further information please read the Upgrade API documentation:
|
||
|
// https://docs.moodle.org/dev/Upgrade_API
|
||
|
//
|
||
|
// You will also have to create the db/install.xml file by using the XMLDB Editor.
|
||
|
// Documentation for the XMLDB Editor can be found at:
|
||
|
// https://docs.moodle.org/dev/XMLDB_editor
|
||
|
|
||
|
if ($oldversion < 2020082903) {
|
||
|
|
||
|
// Define table timetable to be created.
|
||
|
$table = new xmldb_table('timetable');
|
||
|
|
||
|
// Adding fields to table timetable.
|
||
|
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||
|
$table->add_field('course', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
||
|
$table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||
|
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||
|
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||
|
$table->add_field('intro', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
||
|
$table->add_field('introformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0');
|
||
|
|
||
|
// Adding keys to table timetable.
|
||
|
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||
|
$table->add_key('fk_course', XMLDB_KEY_FOREIGN, ['course'], 'course', ['id']);
|
||
|
|
||
|
// Conditionally launch create table for 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);
|
||
|
}
|
||
|
|
||
|
// Define table timetable_substitution to be created.
|
||
|
$table = new xmldb_table('timetable_substitution');
|
||
|
|
||
|
// Adding fields to table timetable_substitution.
|
||
|
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||
|
$table->add_field('date', XMLDB_TYPE_CHAR, '8', null, null, null, null);
|
||
|
$table->add_field('period', XMLDB_TYPE_INTEGER, '2', null, null, null, null);
|
||
|
$table->add_field('absence', XMLDB_TYPE_INTEGER, '6', null, null, null, null);
|
||
|
$table->add_field('lesson', XMLDB_TYPE_INTEGER, '6', null, null, null, null);
|
||
|
$table->add_field('teachera', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||
|
$table->add_field('teacherb', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||
|
$table->add_field('subjecta', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||
|
$table->add_field('statistica', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||
|
$table->add_field('subjectb', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||
|
$table->add_field('statisticb', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||
|
$table->add_field('rooma', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||
|
$table->add_field('roomb', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||
|
$table->add_field('statisticflag', XMLDB_TYPE_CHAR, '10', null, null, null, null);
|
||
|
$table->add_field('classa', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||
|
$table->add_field('reason', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||
|
$table->add_field('text', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||
|
$table->add_field('type', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
|
||
|
$table->add_field('classb', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||
|
$table->add_field('substitutiontype', XMLDB_TYPE_CHAR, '1', null, null, null, null);
|
||
|
$table->add_field('changetime', XMLDB_TYPE_INTEGER, '12', null, null, null, null);
|
||
|
$table->add_field('unknown', XMLDB_TYPE_CHAR, '10', null, null, null, null);
|
||
|
|
||
|
// Adding keys to table timetable_substitution.
|
||
|
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||
|
|
||
|
// Conditionally launch create table for timetable_substitution.
|
||
|
if (!$dbman->table_exists($table)) {
|
||
|
$dbman->create_table($table);
|
||
|
}
|
||
|
|
||
|
// Define table timetable_teacher to be created.
|
||
|
$table = new xmldb_table('timetable_teacher');
|
||
|
|
||
|
// Adding fields to table timetable_teacher.
|
||
|
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||
|
$table->add_field('teacher', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null);
|
||
|
$table->add_field('surname', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||
|
$table->add_field('firstname', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||
|
|
||
|
// Adding keys to table timetable_teacher.
|
||
|
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||
|
|
||
|
// Conditionally launch create table for timetable_teacher.
|
||
|
if (!$dbman->table_exists($table)) {
|
||
|
$dbman->create_table($table);
|
||
|
}
|
||
|
|
||
|
// Define table timetable_room to be created.
|
||
|
$table = new xmldb_table('timetable_room');
|
||
|
|
||
|
// Adding fields to table timetable_room.
|
||
|
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||
|
$table->add_field('room', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null);
|
||
|
$table->add_field('description', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||
|
|
||
|
// Adding keys to table timetable_room.
|
||
|
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||
|
|
||
|
// Conditionally launch create table for timetable_room.
|
||
|
if (!$dbman->table_exists($table)) {
|
||
|
$dbman->create_table($table);
|
||
|
}
|
||
|
|
||
|
// Define table timetable_class to be created.
|
||
|
$table = new xmldb_table('timetable_class');
|
||
|
|
||
|
// Adding fields to table timetable_class.
|
||
|
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||
|
$table->add_field('class', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null);
|
||
|
$table->add_field('description', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||
|
|
||
|
// Adding keys to table timetable_class.
|
||
|
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||
|
|
||
|
// Conditionally launch create table for timetable_class.
|
||
|
if (!$dbman->table_exists($table)) {
|
||
|
$dbman->create_table($table);
|
||
|
}
|
||
|
|
||
|
// Timetable savepoint reached.
|
||
|
upgrade_mod_savepoint(true, 2020082903, 'timetable');
|
||
|
}
|
||
|
|
||
|
|
||
|
return true;
|
||
|
}
|