1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
<?php
/**
* Gradebook API for Stud.IP.
*
* This program 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 2 of
* the License, or (at your option) any later version.
*
* @author <mlunzena@uos.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
*/
class Gradebook extends Migration
{
public function description()
{
return 'initial database setup for Gradebook API';
}
public function up()
{
$db = DBManager::get();
$sql =
"CREATE TABLE `grading_definitions` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`course_id` char(32) COLLATE latin1_bin NOT NULL,
`item` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`tool` varchar(64) COLLATE latin1_bin NOT NULL,
`category` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`position` int(11) NOT NULL DEFAULT '0',
`weight` float UNSIGNED NOT NULL,
`mkdate` int(11) NOT NULL,
`chdate` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `course_id` (`course_id`),
KEY `tool` (`tool`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC";
$db->exec($sql);
$sql =
'CREATE TABLE `grading_instances` (
`definition_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` char(32) COLLATE latin1_bin NOT NULL,
`rawgrade` decimal(6,5) UNSIGNED NOT NULL,
`feedback` varchar(255) COLLATE utf8mb4_unicode_ci,
`mkdate` int(11) NOT NULL,
`chdate` int(11) NOT NULL,
PRIMARY KEY (`definition_id`,`user_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC';
$db->exec($sql);
// install as core plugin
$sql = "INSERT INTO plugins (pluginclassname, pluginname, plugintype, enabled, navigationpos)
VALUES ('GradebookModule', 'Gradebook', 'StandardPlugin,SystemPlugin', 'yes', 1)";
$db->exec($sql);
$sql = "INSERT INTO roles_plugins (roleid, pluginid) SELECT roleid, ? FROM roles WHERE `system` = 'y'";
$db->execute($sql, [$db->lastInsertId()]);
}
public function down()
{
$db = DBManager::get();
$db->exec("DELETE plugins, roles_plugins FROM plugins LEFT JOIN roles_plugins USING(pluginid)
WHERE pluginclassname = 'GradebookModule'");
$db->exec('DROP TABLE grading_definitions, grading_instances');
SimpleORMap::expireTableScheme();
}
}
|