aboutsummaryrefslogtreecommitdiff
path: root/lib/modules/ConsultationModule.class.php
blob: acb15b2be6db9c4f063da75d89c99ece6292272c (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
 * @author  Jan-Hendrik Willms <tleilax+studip@gmail.com>
 * @license GPL2 or any later version
 */
class ConsultationModule extends CorePlugin implements StudipModule, SystemPlugin, PrivacyPlugin, HomepagePlugin
{
    public function __construct()
    {
        parent::__construct();

        NotificationCenter::on('UserDidDelete', function ($event, $user) {
            // Delete consultation bookings and slots
            ConsultationBooking::deleteByUser_id($user->id);
            ConsultationBlock::deleteBySQL("range_id = ? AND range_type = 'user'", [$user->id]);
        });
        NotificationCenter::on('CourseDidDelete', function ($event, $course) {
            // Delete consultation blocks
            ConsultationBlock::deleteBySQL("range_id = ? AND range_type = 'course'", [$course->id]);
        });
        NotificationCenter::on('InstituteDidDelete', function ($event, $institute) {
            // Delete consultation blocks
            ConsultationBlock::deleteBySQL("range_id = ? AND range_type = 'institute'", [$institute->id]);
        });
    }

    /**
     * {@inheritdoc}
     */
    public function isActivatableForContext(Range $context)
    {
        // Consultations globally disabled?
        if (!Config::get()->CONSULTATION_ENABLED) {
            return false;
        }

        // Context is user and current user has required permission?
        if ($context instanceof User) {
            return $GLOBALS['perm']->have_perm(Config::get()->CONSULTATION_REQUIRED_PERMISSION, $context->getRangeId());
        }

        return true;
    }

    /**
     * {@inheritdoc}
     */
    public function getIconNavigation($course_id, $last_visit, $user_id)
    {
        // TODO

        return null;
    }

    /**
     * {@inheritdoc}
     */
    public function getTabNavigation($course_id)
    {
        if ($GLOBALS['user']->id !== 'nobody') {
            return ['consultation' => new ConsultationNavigation(RangeFactory::find($course_id))];
        }
    }

    /**
     * {@inheritdoc}
     */
    public function getInfoTemplate($course_id)
    {
        return null;
    }

    /**
     * {@inheritdoc}
     */
    public function getHomepageTemplate($user_id)
    {
        return null;
    }


    /**
     * {@inheritdoc}
     */
    public function getMetadata()
    {
        return [
            'summary'     => _('Generische Terminvergabe'),
            'description' => _('Über die generische Terminvergabe können jegliche Formen von Terminen ' .
                               'angeboten werden, zu denen sich Personen oder auch Gruppen von Personen ' .
                               'anmelden können.'),
            'category'    => _('Kommunikation und Zusammenarbeit'),
            'keywords'    => _('Terminvergabe, Sprechstunden'),
            'displayname' => _('Terminvergabe'),
            'icon'        => Icon::create('consultation', Icon::ROLE_INFO),
             'screenshots' => [
                 'path'     => 'assets/images/plus/screenshots/Terminvergabe',
                 'pictures' => [
                     [
                         'source' => 'uebersicht.png',
                         'title'  => _('Übersicht der erstellten Termine'),
                     ],
                     [
                         'source' => 'anlegen.png',
                         'title'  => _('Erstellen neuer Termine'),
                     ],
                 ]
             ]
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function exportUserData(StoredUserData $storage)
    {
        $storage->addTabularData(
            _('Terminblöcke'),
            'consultation_blocks',
            ConsultationBlock::findAndMapBySQL(
                function ($block) {
                    return $block->toRawArray();
                },
                "range_id = :user_id AND range_type = 'user'",
                [':user_id' => $storage->user_id]
            )
        );
        $storage->addTabularData(
            _('Terminbuchungen'),
            'consultation_bookings',
            ConsultationBooking::findAndMapBySQL(
                function ($booking) {
                    return $booking->toRawArray();
                },
                'user_id = :user_id',
                [':user_id' => $storage->user_id]
            )
        );
        $storage->addTabularData(
            _('Terminverantwortlichkeiten'),
            'consultation_responsibilities',
            ConsultationResponsibility::findAndMapBySQL(
                function ($responsibility) {
                    return $responsibility->toRawArray();
                },
                "range_id = :user_id AND range_type = 'user'",
                [':user_id' => $storage->user_id]
            )
        );
    }
}