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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
<?php
/**
* 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 Rasmus Fuhse <fuhse@data-quest.de>
* @copyright 2014 Stud.IP Core-Group
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
*
* @property string termin_id database column
* @property string id alias column for termin_id
* @property string range_id database column
* @property string autor_id database column
* @property string content database column
* @property string description database column
* @property string date database column
* @property string end_time database column
* @property string mkdate database column
* @property string chdate database column
* @property string date_typ database column
* @property string topic_id database column
* @property string raum database column
* @property string metadate_id database column
* @property string resource_id database column
* @property string topics computed column
* @property string statusgruppen computed column
* @property string dozenten computed column
* @property User author belongs_to User
* @property Course course belongs_to Course
* @property SeminarCycleDate cycle belongs_to SeminarCycleDate
*/
class CourseExDate extends SimpleORMap implements PrivacyObject
{
/**
* Configures this model.
*
* @param Array $config Configuration array
*/
protected static function configure($config = [])
{
$config['db_table'] = 'ex_termine';
$config['belongs_to']['author'] = [
'class_name' => User::class,
'foreign_key' => 'autor_id'
];
$config['belongs_to']['course'] = [
'class_name' => Course::class,
'foreign_key' => 'range_id'
];
$config['belongs_to']['cycle'] = [
'class_name' => SeminarCycleDate::class,
'foreign_key' => 'metadate_id'
];
$dummy_relation = function () { return new SimpleCollection(); };
$dummy_null = function () { return null; };
$config['additional_fields']['topics']['get'] = $dummy_relation;
$config['additional_fields']['statusgruppen']['get'] = $dummy_relation;
$config['additional_fields']['dozenten']['get'] = $dummy_relation;
$config['additional_fields']['room_booking']['get'] = $dummy_null;
$config['additional_fields']['room_request']['get'] = $dummy_null;
$config['default_values']['date_typ'] = 1;
parent::configure($config);
}
const FORMAT_DEFAULT = 'default';
const FORMAT_VERBOSE = 'verbose';
/**
* Returns course dates by course id
*
* @param String $seminar_id Id of the course
* @return array with the associated dates
*/
public static function findBySeminar_id($seminar_id)
{
return self::findByRange_id($seminar_id);
}
/**
* Return course dates by range id (which is in many cases the course id)
*
* @param String $seminar_id Id of the course
* @param String $order_by Optional order definition
* @return array with the associated dates
*/
public static function findByRange_id($seminar_id, $order_by = 'ORDER BY date')
{
return parent::findByRange_id($seminar_id, $order_by);
}
/**
* Returns the name of the assigned room for this date.
*
* @return String that is always empty
*/
public function getRoomName()
{
return '';
}
/**
* Returns the assigned room for this date as an object.
*
* @return null. always. canceled dates need no room.
*/
public function getRoom()
{
return null;
}
/**
* Returns the name of the type of this date.
*
* @param String containing the type name
*/
public function getTypeName()
{
return $GLOBALS['TERMIN_TYP'][$this->date_typ]['name'];
}
/**
* Returns the full qualified name of this date.
*
* @param String $format Optional format type (only 'default' and
* 'verbose' are supported by now)
* @return String containing the full name of this date.
*/
public function getFullname($format = 'default')
{
if (!$this->date || !in_array($format, ['default', 'verbose'])) {
return '';
}
$latter_template = $format === 'verbose'
? _('%R Uhr')
: '%R';
if (($this->end_time - $this->date) / 60 / 60 > 23) {
return strftime('%a., %x' . ' (' . _('ganztägig') . ')' , $this->date) . " (" . _("fällt aus") . ")";
}
return strftime('%a., %x, %R', $this->date) . ' - '
. strftime($latter_template, $this->end_time)
. ' (' . _('fällt aus') . ')';
}
/**
* Converts a CourseExDate Entry to a CourseDate Entry
* returns instance of the new CourseDate or NULL
* @return Object CourseDate
*/
public function unCancelDate()
{
//NOTE: If you modify this method make sure the changes
//are also inserted in SingleDateDB::storeSingleDate
//and CourseDate::cancelDate to keep the behavior consistent
//across Stud.IP!
//These statements are used below to update the relations
//of this ex-date.
$db = DBManager::get();
$groups_stmt = $db->prepare(
"UPDATE termin_related_groups
SET termin_id = :termin_id
WHERE termin_id = :ex_termin_id;"
);
$persons_stmt = $db->prepare(
"UPDATE termin_related_persons
SET range_id = :termin_id
WHERE range_id = :ex_termin_id;"
);
$ex_date = $this->toArray();
//REMOVE content
unset($ex_date['content']);
$date = new CourseDate();
$date->setData($ex_date);
$date->setId($date->getNewId());
if ($date->store()) {
//Update the relations to the ex-date so that they
//use the ID of the new date.
$groups_stmt->execute(
[
'termin_id' => $date->id,
'ex_termin_id' => $this->id
]
);
$persons_stmt->execute(
[
'termin_id' => $date->id,
'ex_termin_id' => $this->id
]
);
//After we updated the relations so that they refer to the
//new date we can delete this ex-date and return the date:
StudipLog::log('SEM_UNDELETE_SINGLEDATE', $this->termin_id, $this->range_id, 'Cycle_id: ' . $this->metadate_id);
$this->delete();
return $date;
}
return null;
}
/**
* Export available data of a given user into a storage object
* (an instance of the StoredUserData class) for that user.
*
* @param StoredUserData $storage object to store data into
*/
public static function exportUserData(StoredUserData $storage)
{
$sorm = self::findBySQL("autor_id = ?", [$storage->user_id]);
if ($sorm) {
$field_data = [];
foreach ($sorm as $row) {
$field_data[] = $row->toRawArray();
}
if ($field_data) {
$storage->addTabularData(_('ausgefallende Termine'), 'ex_termine', $field_data);
}
}
}
/**
* @return string A string representation of the course date.
*/
public function __toString() : string
{
return sprintf(
_('Ausgefallener Termin am %1$s, %2$s von %3$s bis %4$s Uhr'),
strftime('%A', $this->date),
strftime('%x', $this->date),
date('H:i', $this->date),
date('H:i', $this->end_time)
);
}
}
|