aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/1.188_step_00296_appointment_requests.php
blob: c671bc3958740ba94d3f8a87d67620989e2df94c (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
<?php

class Step00296AppointmentRequests extends Migration
{

    /**
     * new config options to install
     */
    private $options_new = [
        [
            'name' => 'CALENDAR_GRANT_ALL_INSERT',
            'description' => 'Ermöglicht das Eintragen von Terminen in alle Nutzerkalender, ohne Beachtung des Rechtesystems.',
            'section' => 'modules',
            'type' => 'boolean',
            'value' => '0'
        ]
    ];

    /**
     * short description of this migration
     */
    function description()
    {
        return "Extends the calendar by the possibility to state an appointment in"
            . "another user's calendar as a requested appointment. "
            . "Displaying of course appointments is now optional.";
    }

    /**
     * insert list of options into config table
     */
    function insertConfig($options)
    {
        $db = DBManager::get();
        $time = time();

        $stmt = $db->prepare("
                INSERT INTO config
                    (config_id, field, value, is_default, type, section, mkdate, chdate, description)
                VALUES
                    (MD5(:name), :name, :value, 1, :type, :section, $time, $time, :description)
                ");

        foreach ($options as $option) {
            $stmt->execute($option);
        }
    }

    /**
     * remove list of options from config table
     */
    function deleteConfig($options)
    {
        $db = DBManager::get();

        $stmt = $db->prepare("DELETE FROM config WHERE field = :name");

        foreach ($options as $option) {
            $stmt->execute(['name' => $option['name']]);
        }
    }

    /**
     * perform this migration
     */
    public function up()
    {
        $this->insertConfig($this->options_new);
    }

    /**
     * revert this migration
     */
    public function down()
    {
        $this->deleteConfig($this->options_new);
    }
}