aboutsummaryrefslogtreecommitdiff
path: root/lib/admissionrules/lockedadmission/LockedAdmission.php
blob: 92ef5137e40ce8473f5f9e2d579862efea426523 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php

/**
 * LockedAdmission.php
 * 
 * Represents a rule for completely locking courses for admission.
 *
 * 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      Thomas Hackl <thomas.hackl@uni-passau.de>
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category    Stud.IP
 */

class LockedAdmission extends AdmissionRule
{
    // --- ATTRIBUTES ---

    // --- OPERATIONS ---

    /**
     * Standard constructor.
     *
     * @param  String ruleId
     */
    public function __construct($ruleId='', $courseSetId = '')
    {
        parent::__construct($ruleId, $courseSetId);
        $this->default_message = _('Die Anmeldung ist gesperrt.');
        
        if ($ruleId) {
            $this->load();
        } else {
            $this->id = $this->generateId('lockedadmissions');
        }
    }

    /**
     * Deletes the admission rule and all associated data.
     */
    public function delete() {
        parent::delete();
        // Delete rule data.
        $stmt = DBManager::get()->prepare("DELETE FROM `lockedadmissions` 
            WHERE `rule_id`=?");
        $stmt->execute([$this->id]);
    }

    /**
     * Gets some text that describes what this AdmissionRule (or respective 
     * subclass) does.
     */
    public static function getDescription() {
        return _("Diese Art von Anmelderegel sperrt die Anmeldung ".
            "zu allen zugehörigen Veranstaltungen, sodass sich niemand ".
            "eintragen kann.");
    }

    /**
     * Return this rule's name.
     */
    public static function getName() {
        return _("Anmeldung gesperrt");
    }

    /**
     * Gets the template that provides a configuration GUI for this rule.
     * 
     * @return String
     */
    public function getTemplate() {
        $factory = new Flexi\Factory(dirname(__FILE__).'/templates/');
        // Now open specific template for this rule and insert base template. 
        $tpl = $factory->open('configure');
        $tpl->set_attribute('rule', $this);
        return $tpl->render();
    }

    /**
     * Internal helper function for loading rule definition from database.
     */
    public function load() {
        $stmt = DBManager::get()->prepare("SELECT * FROM `lockedadmissions`
            WHERE `rule_id`=? LIMIT 1");
        $stmt->execute([$this->id]);
        if ($current = $stmt->fetch(PDO::FETCH_ASSOC)) {
            $this->message = $current['message'];
        }
    }

    /**
     * Does the current rule allow the given user to register as participant 
     * in the given course? Never happens here as admission is completely
     * locked.
     *
     * @param  String userId
     * @param  String courseId
     * @return Array Any errors that occurred on admission.
     */
    public function ruleApplies($userId, $courseId)
    {
        // YOU CANNOT PASS!
        return [$this->getMessage()];
    }

    /**
     * Helper function for storing data to DB.
     */
    public function store() {
        // Store data.
        $stmt = DBManager::get()->prepare("INSERT INTO `lockedadmissions`
            (`rule_id`, `message`, `mkdate`, `chdate`)
            VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE
            `message`=VALUES(`message`), `chdate`=VALUES(`chdate`)");
        $stmt->execute([$this->id, $this->message, time(), time()]);
        return $this;
    }

    /**
     * A textual description of the current rule.
     *
     * @return String
     */
    public function toString() {
        $factory = new Flexi\Factory(dirname(__FILE__).'/templates/');
        $tpl = $factory->open('info');
        $tpl->set_attribute('rule', $this);
        return $tpl->render();
    }

} /* end of class LockedAdmission */

?>