aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/1.194_tic_6576_preferential_admission.php
blob: 3547d2470957de50275c033b7da3565e47e2a5b8 (plain)
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
<?php
/**
 * Introduces preferential admission rule.
 *
 * @author  Thomas Hackl <thomas.hackl@uni-passau.de>
 * @license GPL2 or any later version
 * @since   Stud.IP 3.5
 *
 * @see https://develop.studip.de/trac/ticket/6576
 */
class TIC6576PreferentialAdmission extends Migration
{
    public function description()
    {
        return 'Introduces an admission rule for favoring selected courses '.
            'of study/degrees/semesters or higher semesters of study in seat '.
            'distribution.';
    }

    public function up()
    {
        // Table for rule definitions.
        DBManager::get()->exec("CREATE TABLE IF NOT EXISTS `prefadmissions` (
                `rule_id` VARCHAR(32),
                `favor_semester` TINYINT(1) NOT NULL DEFAULT 0,
                `mkdate` int(11) NOT NULL DEFAULT 0,
                `chdate` int(11) NOT NULL DEFAULT 0,
                PRIMARY KEY (`rule_id`)
            ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC");

        // Table for storing rule - condition relations.
        DBManager::get()->exec("CREATE TABLE IF NOT EXISTS `prefadmission_condition` (
                `rule_id` VARCHAR(32) NOT NULL,
                `condition_id` VARCHAR(32) NOT NULL,
                `chance` INT(4) NOT NULL DEFAULT 1,
                `mkdate` int(11) NOT NULL DEFAULT 0,
                PRIMARY KEY (`rule_id`,`condition_id`)
            ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC");

        // Install rule to database.
        DBManager::get()->exec("INSERT IGNORE INTO `admissionrules` (`id`, `ruletype`, `active`, `mkdate`)
                                VALUES (0, 'PreferentialAdmission', '1', UNIX_TIMESTAMP())");

        // Allow higher bonus factors for users (as generated by PreferentialAdmission)
        DBManager::get()->exec("ALTER TABLE `admissionfactor` CHANGE `factor` `factor` FLOAT NOT NULL DEFAULT '1.00';");

    }

    public function down()
    {
        // Remove entry in admission rule registry.
        DBManager::get()->exec("DELETE FROM `admissionrules` WHERE `ruletype` = 'PreferentialAdmission'");

        // Remove rule data tables.
        DBManager::get()->exec("DROP TABLE IF EXISTS `prefadmission`");
        DBManager::get()->exec("DROP TABLE IF EXISTS `prefadmission_condition`");
    }
}