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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
|
<?
# Lifter002: TODO
# Lifter007: TODO
# Lifter003: TODO
# Lifter010: TODO
// +--------------------------------------------------------------------------+
// This file is part of Stud.IP
// CycleData.class.php
//
// Repräsentiert ein Turnusdatum eines MetaDates
//
// +--------------------------------------------------------------------------+
// 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 any later version.
// +--------------------------------------------------------------------------+
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// +--------------------------------------------------------------------------+
/**
* This class is subject to change, for now it wraps getter
* and setter to SeminarCycleDate. For compatibility reasons it has
* magic __get() __set() __isset, and it combines the old metadata_dates
* keys and the new fields from SeminarCycleDate (see CycleData::$alias)
*
*
* @author Till Glöggler <tgloeggl@uos.de>
* @version 19. Oktober 2005
* @access protected
* @package raumzeit
*/
class CycleData
{
/**
* list of aliases to translate old style metadata_dates keys to
* new fields of SeminarCycleDate
*
* @var array
*/
private $alias = [
'start_stunde' => 'start_hour',
'end_stunde' => 'end_hour',
'day' => 'weekday',
'desc' => 'description',
'is_visible' => 'is_visible'
];
/**
* this is mostly filtered, see readSingleDates()
* should not be public
*
* @var array of SingleDate
*/
public $termine = NULL; // Array
/**
* Enter description here ...
* @var SeminarCycleDate
*/
private $cycle_date = null;
/**
* Constructor
* @param SeminarCycleDate|array
*/
function __construct($cycle_data = FALSE)
{
if ($cycle_data instanceof SeminarCycleDate) {
$this->cycle_date = $cycle_data;
} else {
if ($cycle_data['metadate_id']) {
$metadate_id = $cycle_data['metadate_id'];
} else {
$metadate_id = md5(uniqid('metadate_id'));
}
$this->cycle_date = new SeminarCycleDate($metadate_id);
$this->setStart($cycle_data['start_stunde'], $cycle_data['start_minute']);
$this->setEnd($cycle_data['end_stunde'], $cycle_data['end_minute']);
$this->setDay($cycle_data['day']);
$this->setDescription($cycle_data['desc']);
}
}
function getDescription()
{
return $this->cycle_date->description;
}
function getCycleDate() {
return $this->cycle_date;
}
function setDescription($description)
{
$this->cycle_date->description = $description;
}
function setStart($start_stunde, $start_minute)
{
$this->cycle_date->start_hour = (int)$start_stunde;
$this->cycle_date->start_minute = (int)$start_minute;
}
function setEnd($end_stunde, $end_minute)
{
$this->cycle_date->end_hour = (int)$end_stunde;
$this->cycle_date->end_minute = (int)$end_minute;
}
function getStartStunde ()
{
return $this->cycle_date->start_hour;
}
function getStartMinute ()
{
return $this->cycle_date->start_minute;
}
function getEndStunde ()
{
return $this->cycle_date->end_hour;
}
function getEndMinute ()
{
return $this->cycle_date->end_minute;
}
function getMetaDateID()
{
return $this->cycle_date->getId();
}
function getDay()
{
return $this->cycle_date->weekday;
}
function getStartTime()
{
return sprintf('%02d:%02d',$this->getStartStunde(), $this->getStartMinute());
}
function getEndTime()
{
return sprintf('%02d:%02d',$this->getEndStunde(), $this->getEndMinute());
}
function setDay($day)
{
$this->cycle_date->weekday = $day;
}
/**
* Check if there is a least one not cancelled date for this cycle data
*
* @return bool true, if there is at least one not cancelled date
*/
function getIsVisible()
{
return $this->cycle_date->is_visible;
}
function __get($field)
{
if(isset($this->alias[$field])) {
$field = $this->alias[$field];
}
return $this->cycle_date->$field;
}
function __set($field, $value)
{
if(isset($this->alias[$field])) {
$field = $this->alias[$field];
}
return $this->cycle_date->$field = $value;
}
function __isset($field)
{
if(isset($this->alias[$field])) {
$field = $this->alias[$field];
}
return isset($this->cycle_date->$field);
}
/**
* stores only the cycledate data
*
* @return boolean
*/
function storeCycleDate()
{
if (!$this->description) $this->description = '';
return $this->cycle_date->store();
}
/**
* stores the single dates belonging to this cycledate,
* but only the ones which are currently loaded!
* (see readSingleDates())
* should be private
*
* @return boolean
*/
function store()
{
foreach ($this->termine as $val) {
$val->store();
}
return TRUE;
}
/**
* refreshes the currently loaded single dates from database,
* does not reload cycledate data!
* should be private
*
* @return boolean
*/
function restore()
{
foreach ($this->termine as $key => $val) {
$new_termine[$key] = $val->restore();
}
$this->termine =& $new_termine;
return TRUE;
}
/**
* deletes cycledate and corresponding single dates
*
* @param boolean $removeSingles
* @return boolean
*/
function delete($removeSingles = TRUE)
{
if ($removeSingles) {
if (!$this->termine) {
$this->readSingleDates();
}
foreach ($this->termine as $termin) {
$termin->delete();
}
}
return $this->cycle_date->delete();
}
/**
* this does not delete a single date, but set it to be marked
* as to not take place. do not use!
*
* @deprecated
* @param sting $date_id
* @param int $filterStart
* @param int $filterEnd
*/
function deleteSingleDate($date_id, $filterStart, $filterEnd)
{
if (!$this->termine) {
$this->readSingleDates($filterStart, $filterEnd);
}
$this->termine[$date_id]->setExTermin(true);
$this->termine[$date_id]->store();
}
/**
* this should ressurect a single date whis is marked
* as to not take place. do not use!
*
* @deprecated
* @param sting $date_id
* @param int $filterStart
* @param int $filterEnd
*/
function unDeleteSingleDate($date_id, $filterStart, $filterEnd)
{
if (!$this->termine) {
$this->readSingleDates($filterStart, $filterEnd);
}
if (!$this->termine[$date_id]->isExTermin()) {
return false;
}
$this->termine[$date_id]->setExTermin(false);
$this->termine[$date_id]->store();
return true;
}
/**
* load corresponding single dates from database
* give timestamps as params to filter by time range
*
* @param int $start
* @param int $end
* @return boolean
*/
function readSingleDates($start = 0, $end = 0)
{
$this->termine = [];
$termin_data = CycleDataDB::getTermine($this->metadate_id, $start, $end);
if ($termin_data) {
foreach ($termin_data as $val) {
unset($termin);
$termin = new SingleDate();
$termin->fillValuesFromArray($val);
$termin->setExTermin($val['ex_termin']);
$this->termine[$val['termin_id']] = $termin;
}
return TRUE;
}
return FALSE;
}
/**
* get the currently loaded single dates, or all when no dates
* are loaded. you must use readSingleDates() before to be shure what to get!
*
* @return array of SingleDate
*/
function getSingleDates()
{
if (!$this->termine) {
$this->readSingleDates();
}
return $this->termine;
}
/**
* returns an assoc array, keys are room names values are number of dates for this room
* give timestamps as params to filter by time range
*
* @param int $filterStart
* @param int $filterEnd
* @return array|false
*/
function getFreeTextPredominantRoom($filterStart = 0, $filterEnd = 0)
{
return CycleDataDB::getFreeTextPredominantRoomDB($this->metadate_id, $filterStart, $filterEnd);
}
/**
* returns an assoc array, keys are resource_id of rooms values are number of dates for this room
* give timestamps as params to filter by time range
*
* @param int $filterStart
* @param int $filterEnd
* @return array
*/
function getPredominantRoom($filterStart = 0, $filterEnd = 0)
{
if ($rooms = CycleDataDB::getPredominantRoomDB($this->metadate_id, $filterStart, $filterEnd)) {
return $rooms;
}
return false;
}
/**
* returns a formatted string for cycledate
*
* @see SeminarCycleDate::toString()
* @param boolean $short
* @return string
*/
function toString($short = false)
{
if($short === false) {
return $this->cycle_date->toString('long');
} else if ($short === true) {
return $this->cycle_date->toString('short');
} else {
return $this->cycle_date->toString($short);
}
}
/**
* return all fields from SeminarCycleDate and old style
* metadata_dates, combined with info about rooms
*
* @return array
*/
function toArray()
{
$ret = $this->cycle_date->toArray();
foreach($this->alias as $a => $o) {
$ret[$a] = $this->cycle_date->$o;
}
$ret['assigned_rooms'] = $this->getPredominantRoom();
$ret['freetext_rooms'] = $this->getFreetextPredominantRoom();
$ret['tostring'] = $this->toString();
$ret['tostring_short'] = $this->toString(true);
$ret['start_minute'] = leadingZero($ret['start_minute']);
$ret['end_minute'] = leadingZero($ret['end_minute']);
return $ret;
}
/**
* assign single dates one by one to a list of issues
* seems not to be the right place for this method
*
* @deprecated
* @param array $themen
* @param int $filterStart
* @param int $filterEnd
*/
function autoAssignIssues($themen, $filterStart, $filterEnd)
{
$this->readSingleDates($filterStart, $filterEnd);
$z = 0;
foreach ($this->termine as $key => $val) {
if (sizeof($val->getIssueIDs()) == 0) {
if (!$themen[$z]) break;
if (!$val->isExTermin()) {
$this->termine[$key]->addIssueID($themen[$z++]);
}
}
}
$this->store();
}
}
|