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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
<?php
/**
* Calendar.class.php - Holds some additional functions and constants
* related to the personal calendar.
*
* 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 Peter Thienel <thienel@data-quest.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
* @since 3.2
*/
class Calendar
{
/**
* The (positive) end of unix epche
*/
const CALENDAR_END = 0x7FFFFFFF;
/**
* The user is the owner of the calendar.
*/
const PERMISSION_OWN = 16;
/**
* The user has administrative access to the calendar.
* Means, he is not the owner but have the same rights.
* Not in use at the moment.
*/
const PERMISSION_ADMIN = 8;
/**
* The user can add new events and edit existing events in the calendar.
* If the owner of the calendar has created an confidential event, the only
* information the user get is the start and end time. The event is shown as
* busy time in the views for him.
* If the user adds a confidential event, only he and the owner has full
* access to it. The event is shown as busy time to all other users.
*/
const PERMISSION_WRITABLE = 4;
/**
* The user can read all information of all events, except events marked as
* confidential. These events are shown as busy times in the views.
* The user can not add new events nor edit existing events.
*/
const PERMISSION_READABLE = 2;
/**
* The user is not allowed to get any information about the calendar.
* The user has no access to the calendar but he see public events on the
* profile of the owner.
*/
const PERMISSION_FORBIDDEN = 1;
/**
* The calendar is related to one user. He is the owner of the calendar.
*/
const RANGE_USER = 1;
/**
* The calendar is related to a group of users
* ("contact group" or Statusgruppe).
* Not used at the moment.
* The implemeted group functionality shows all personal calendars of the
* members of a contact group. It is not a shared calendar where all members
* have access to.
*/
const RANGE_GROUP = 2;
/**
* The calendar is a module of a course or studygroup. All members with
* status author, tutor or dozent have write access (PERMISSION_WRITABLE).
* Users with local status user has only read access (PERMISSION_READABLE).
*/
const RANGE_SEM = 3;
/**
* The calendar is a module of an institute or faculty. All members with
* status author, tutor or dozent have write access (PERMISSION_WRITABLE).
* Users with local status user has only read access (PERMISSION_READABLE).
*/
const RANGE_INST = 4;
/**
* Retrieves all contact groups (statusgruppen) owned by the given user
* where at least one member has granted access to his calender for the user.
*
* @param string $user_id User id of the owner.
* @return type
*/
public static function getGroups($user_id)
{
$groups = [];
$calendar_owners = CalendarUser::getOwners($user_id)->pluck('owner_id');
$sg_groups = SimpleORMapCollection::createFromArray(
Statusgruppen::findByRange_id($user_id))
->orderBy('position')
->pluck('statusgruppe_id');
if (sizeof($calendar_owners)) {
$sg_users = StatusgruppeUser::findBySQL(
'statusgruppe_id IN(?) AND user_id IN(?)',
[$sg_groups, $calendar_owners]);
foreach ($sg_users as $sg_user) {
$groups[$sg_user->group->id] = $sg_user->group;
}
}
return $groups;
}
public static function GetInstituteActivatedCalendar($user_id)
{
$ret = [];
Institute::findAndMapBySQL(function($i) use (&$ret) {
if ($i->isToolActive('CoreCalendar')) {
$ret[$i->id] = $i->name;
}
},
"JOIN user_inst USING(Institut_id)
WHERE user_id = ? AND inst_perms IN ('admin','dozent','tutor','autor')
ORDER BY Name ASC",
[$user_id]
);
return $ret;
}
/**
*
* @param string $user_id
* @return array
*/
public static function GetCoursesActivatedCalendar($user_id)
{
$courses_user = SimpleCollection::createFromArray(
CourseMember::findByUser($user_id));
$courses = $courses_user->filter(function ($c) {
if ($c->course->isToolActive('CoreCalendar')) {
return $c;
}
});
return $courses->pluck('course');
}
public static function GetLecturers()
{
$stmt = DBManager::get()->prepare("SELECT aum.username, "
. "CONCAT(aum.Nachname,', ',aum.vorname) as fullname, "
. "aum.user_id FROM auth_user_md5 aum WHERE perms = 'dozent' "
. "ORDER BY fullname");
$stmt->execute();
$lecturers = [];
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
if ($row['user_id'] != $GLOBALS['user']->id) {
$lecturers[] = ['name' => $row['fullname'],
'username' => $row['username'], 'id' => $row['user_id']];
}
}
return $lecturers;
}
/**
* Returns an array of default user settings for the calendar or a specific
* value if the index is given.
*
* @param string $index Index of setting to get.
* @return string|array Array of settings or one setting
*/
public static function getDefaultUserSettings($index = null)
{
$default = [
'view' => 'week',
'start' => '9',
'end' => '20',
'step_day' => '900',
'step_week' => '1800',
'type_week' => 'LONG',
'step_week_group' => '3600',
'step_day_group' => '3600',
'show_declined' => '0'
];
return (is_null($index) ? $default : $default[$index]);
}
}
|