ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilObjSession.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
6include_once './Services/Membership/classes/class.ilMembershipRegistrationSettings.php';
7
17{
18 const CAL_REG_START = 1;
19
20 protected $db;
21
22 protected $location;
23 protected $name;
24 protected $phone;
25 protected $email;
26 protected $details;
27 protected $registration;
28 protected $event_id;
29
31 protected $reg_limited = 0;
32 protected $reg_limited_users = 0;
33 protected $reg_waiting_list = 0;
34
35
36 protected $appointments;
37 protected $files = array();
38
39
40
47 public function __construct($a_id = 0,$a_call_by_reference = true)
48 {
49 global $ilDB;
50
51 $this->db = $ilDB;
52 $this->type = "sess";
53 parent::__construct($a_id,$a_call_by_reference);
54 }
55
64 public static function _lookupRegistrationEnabled($a_obj_id)
65 {
66 global $ilDB;
67
68 $query = "SELECT reg_type FROM event ".
69 "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
70 $res = $ilDB->query($query);
71 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
72 {
73 return (bool) $row->reg_type != ilMembershipRegistrationSettings::TYPE_NONE;
74 }
75 return false;
76 }
77
83 public static function lookupSession($a_obj_id)
84 {
85 global $ilDB;
86
87 $query = "SELECT * FROM event ".
88 "WHERE obj_id = ".$ilDB->quote($a_obj_id);
89 $res = $ilDB->query($query);
90 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
91 {
92 $data['location'] = $row->location ? $row->location : '';
93 $data['details'] = $row->details ? $row->details : '';
94 $data['name'] = $row->tutor_name ? $row->tutor_name : '';
95 $data['email'] = $row->tutor_email ? $row->tutor_email : '';
96 $data['phone'] = $row->tutor_phone ? $row->tutor_phone : '';
97 }
98 return (array) $data;
99 }
100
108 public function getPresentationTitle()
109 {
110 $date = new ilDate($this->getFirstAppointment()->getStart()->getUnixTime(),IL_CAL_UNIX);
111 if($this->getTitle())
112 {
113 return ilDatePresentation::formatDate($this->getFirstAppointment()->getStart()).': '.$this->getTitle();
114 }
115 else
116 {
117 return ilDatePresentation::formatDate($date);
118 }
119
120 }
121
122
123
130 public function getEventId()
131 {
132 return $this->event_id;
133 }
134
141 public function setLocation($a_location)
142 {
143 $this->location = $a_location;
144 }
145
152 public function getLocation()
153 {
154 return $this->location;
155 }
156
163 public function setName($a_name)
164 {
165 $this->name = $a_name;
166 }
167
174 public function getName()
175 {
176 return $this->name;
177 }
178
185 public function setPhone($a_phone)
186 {
187 $this->phone = $a_phone;
188 }
189
196 public function getPhone()
197 {
198 return $this->phone;
199 }
200
208 public function setEmail($a_email)
209 {
210 $this->email = $a_email;
211 }
212
219 public function getEmail()
220 {
221 return $this->email;
222 }
223
229 public function hasTutorSettings()
230 {
231 return strlen($this->getName()) or
232 strlen($this->getEmail()) or
233 strlen($this->getPhone());
234 }
235
236
243 public function setDetails($a_details)
244 {
245 $this->details = $a_details;
246 }
247
254 public function getDetails()
255 {
256 return $this->details;
257 }
258
259 public function setRegistrationType($a_type)
260 {
261 $this->reg_type = $a_type;
262 }
263
264 public function getRegistrationType()
265 {
266 return $this->reg_type;
267 }
268
270 {
271 return $this->reg_limited;
272 }
273
274 public function enableRegistrationUserLimit($a_limit)
275 {
276 $this->reg_limited = $a_limit;
277 }
278
279 public function getRegistrationMaxUsers()
280 {
282 }
283
284 public function setRegistrationMaxUsers($a_users)
285 {
286 $this->reg_limited_users = $a_users;
287 }
288
290 {
292 }
293
294 public function enableRegistrationWaitingList($a_stat)
295 {
296 $this->reg_waiting_list = $a_stat;
297 }
298
299
300
307 public function enabledRegistration()
308 {
309 return $this->reg_type != ilMembershipRegistrationSettings::TYPE_NONE;
310 }
311
318 public function getAppointments()
319 {
320 return $this->appointments ? $this->appointments : array();
321 }
322
330 public function addAppointment($appointment)
331 {
332 $this->appointments[] = $appointment;
333 }
334
343 {
344 $this->appointments = $appointments;
345 }
346
353 public function getFirstAppointment()
354 {
355 return is_object($this->appointments[0]) ? $this->appointments[0] : ($this->appointments[0] = new ilSessionAppointment());
356 }
357
365 public function getFiles()
366 {
367 return $this->files ? $this->files : array();
368 }
369
377 public function validate()
378 {
379 return true;
380 }
381
390 public function cloneObject($a_target_id,$a_copy_id = 0)
391 {
392 global $ilDB,$ilUser,$ilAppEventHandler;
393
394 $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
395
396 $this->read();
397
398 // Copy settings
399 $this->cloneSettings($new_obj);
400
401 // Clone appointment
402 $new_app = $this->getFirstAppointment()->cloneObject($new_obj->getId());
403 $new_obj->setAppointments(array($new_app));
404 $new_obj->update();
405
406 // Clone session files
407 foreach($this->files as $file)
408 {
409 $file->cloneFiles($new_obj->getEventId());
410 }
411
412 // Raise update forn new appointments
413
414
415
416 // Copy learning progress settings
417 include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
418 $obj_settings = new ilLPObjSettings($this->getId());
419 $obj_settings->cloneSettings($new_obj->getId());
420 unset($obj_settings);
421
422 return $new_obj;
423 }
424
432 public function cloneSettings(ilObjSession $new_obj)
433 {
434 // @var
435 $new_obj->setLocation($this->getLocation());
436 $new_obj->setName($this->getName());
437 $new_obj->setPhone($this->getPhone());
438 $new_obj->setEmail($this->getEmail());
439 $new_obj->setDetails($this->getDetails());
440
441 $new_obj->setRegistrationType($this->getRegistrationType());
445
446 $new_obj->update();
447
448 return true;
449 }
450
458 public function cloneDependencies($a_target_id,$a_copy_id)
459 {
460 global $ilObjDataCache;
461
462 parent::cloneDependencies($a_target_id,$a_copy_id);
463
464 $target_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
465
466 include_once('./Modules/Session/classes/class.ilEventItems.php');
467 $session_materials = new ilEventItems($target_obj_id);
468 $session_materials->cloneItems($this->getId(),$a_copy_id);
469
470 return true;
471 }
472
473
474
480 public function create()
481 {
482 global $ilDB;
483 global $ilAppEventHandler;
484
485 parent::create();
486
487 $next_id = $ilDB->nextId('event');
488 $query = "INSERT INTO event (event_id,obj_id,location,tutor_name,tutor_phone,tutor_email,details,registration, ".
489 'reg_type, reg_limit_users, reg_limited,reg_waiting_list) '.
490 "VALUES( ".
491 $ilDB->quote($next_id,'integer').", ".
492 $this->db->quote($this->getId() ,'integer').", ".
493 $this->db->quote($this->getLocation() ,'text').",".
494 $this->db->quote($this->getName() ,'text').", ".
495 $this->db->quote($this->getPhone() ,'text').", ".
496 $this->db->quote($this->getEmail() ,'text').", ".
497 $this->db->quote($this->getDetails() ,'text').",".
498 $this->db->quote($this->enabledRegistration() ,'integer').", ".
499 $this->db->quote($this->getRegistrationType(),'integer').', '.
500 $this->db->quote($this->getRegistrationMaxUsers(),'integer').', '.
501 $this->db->quote($this->isRegistrationUserLimitEnabled(),'integer').', '.
502 $this->db->quote($this->isRegistrationWaitingListEnabled(),'integer').' '.
503 ")";
504 $res = $ilDB->manipulate($query);
505 $this->event_id = $next_id;
506
507 $ilAppEventHandler->raise('Modules/Session',
508 'create',
509 array('object' => $this,
510 'obj_id' => $this->getId(),
511 'appointments' => $this->prepareCalendarAppointments('create')));
512
513 return $this->getId();
514 }
515
523 public function update()
524 {
525 global $ilDB;
526 global $ilAppEventHandler;
527
528 if(!parent::update())
529 {
530 return false;
531 }
532 $query = "UPDATE event SET ".
533 "location = ".$this->db->quote($this->getLocation() ,'text').",".
534 "tutor_name = ".$this->db->quote($this->getName() ,'text').", ".
535 "tutor_phone = ".$this->db->quote($this->getPhone() ,'text').", ".
536 "tutor_email = ".$this->db->quote($this->getEmail() ,'text').", ".
537 "details = ".$this->db->quote($this->getDetails() ,'text').", ".
538 "registration = ".$this->db->quote($this->enabledRegistration() ,'integer').", ".
539 "reg_type = ".$this->db->quote($this->getRegistrationType() ,'integer').", ".
540 "reg_limited = ".$this->db->quote($this->isRegistrationUserLimitEnabled() ,'integer').", ".
541 "reg_limit_users = ".$this->db->quote($this->getRegistrationMaxUsers() ,'integer').", ".
542 "reg_waiting_list = ".$this->db->quote($this->isRegistrationWaitingListEnabled(),'integer')." ".
543 "WHERE obj_id = ".$this->db->quote($this->getId() ,'integer')." ";
544 $res = $ilDB->manipulate($query);
545
546 $ilAppEventHandler->raise('Modules/Session',
547 'update',
548 array('object' => $this,
549 'obj_id' => $this->getId(),
550 'appointments' => $this->prepareCalendarAppointments('update')));
551 return true;
552 }
553
560 public function delete()
561 {
562 global $ilDB;
563 global $ilAppEventHandler;
564
565 if(!parent::delete())
566 {
567 return false;
568 }
569 $query = "DELETE FROM event ".
570 "WHERE obj_id = ".$this->db->quote($this->getId() ,'integer')." ";
571 $res = $ilDB->manipulate($query);
572
573 include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
575
576 include_once('./Modules/Session/classes/class.ilEventItems.php');
578
579 include_once('./Modules/Session/classes/class.ilEventParticipants.php');
581
582 foreach($this->getFiles() as $file)
583 {
584 $file->delete();
585 }
586
587 $ilAppEventHandler->raise('Modules/Session',
588 'delete',
589 array('object' => $this,
590 'obj_id' => $this->getId(),
591 'appointments' => $this->prepareCalendarAppointments('delete')));
592
593
594 return true;
595 }
596
604 public function read()
605 {
606 parent::read();
607
608 $query = "SELECT * FROM event WHERE ".
609 "obj_id = ".$this->db->quote($this->getId() ,'integer')." ";
610 $res = $this->db->query($query);
611
612 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
613 {
614 $this->setLocation($row->location);
615 $this->setName($row->tutor_name);
616 $this->setPhone($row->tutor_phone);
617 $this->setEmail($row->tutor_email);
618 $this->setDetails($row->details);
619 $this->setRegistrationType($row->reg_type);
620 $this->enableRegistrationUserLimit($row->reg_limited);
621 $this->enableRegistrationWaitingList($row->reg_waiting_list);
622 $this->setRegistrationMaxUsers($row->reg_limit_users);
623 $this->event_id = $row->event_id;
624 }
625
626 $this->initAppointments();
627 $this->initFiles();
628 }
629
637 protected function initAppointments()
638 {
639 // get assigned appointments
640 include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
641 $this->appointments = ilSessionAppointment::_readAppointmentsBySession($this->getId());
642 }
643
651 public function initFiles()
652 {
653 include_once('./Modules/Session/classes/class.ilSessionFile.php');
654 $this->files = ilSessionFile::_readFilesByEvent($this->getEventId());
655 }
656
657
665 public function prepareCalendarAppointments($a_mode = 'create')
666 {
667 include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
668
669 switch($a_mode)
670 {
671 case 'create':
672 case 'update':
673
674 $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
675 $app->setTranslationType(IL_CAL_TRANSLATION_NONE);
676 $app->setTitle($this->getTitle() ? $this->getTitle() : $this->lng->txt('obj_sess'));
677 $app->setDescription($this->getLongDescription());
678
679 $sess_app = $this->getFirstAppointment();
680 $app->setFullday($sess_app->isFullday());
681 $app->setStart($sess_app->getStart());
682 $app->setEnd($sess_app->getEnd());
683 $apps[] = $app;
684
685 return $apps;
686
687 case 'delete':
688 // Nothing to do: The category and all assigned appointments will be deleted.
689 return array();
690 }
691 }
692
693}
694
695?>
print $file
const IL_CAL_TRANSLATION_NONE
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
const IL_CAL_UNIX
Apointment templates are used for automatic generated apointments.
static formatDate(ilDateTime $date)
Format a date @access public.
Class for single dates.
class ilEvent
_delete($a_event_id)
__construct($a_id=0, $a_call_by_reference=true)
Constructor @access public.
getFirstAppointment()
get first appointment
enabledRegistration()
is registration enabled
static _lookupRegistrationEnabled($a_obj_id)
lookup registration enabled
create()
create new session
setLocation($a_location)
set location
setEmail($a_email)
set email
getDetails()
get details
read()
read session data
getLocation()
get location
getEventId()
sget event id
setRegistrationType($a_type)
setName($a_name)
set name
initAppointments()
init appointments
setPhone($a_phone)
set phone
setDetails($a_details)
set details
getAppointments()
get appointments
prepareCalendarAppointments($a_mode='create')
Prepare calendar appointments.
setAppointments($appointments)
set appointments
cloneDependencies($a_target_id, $a_copy_id)
Clone dependencies.
initFiles()
init files
cloneObject($a_target_id, $a_copy_id=0)
Clone course (no member data)
getPresentationTitle()
get title (overwritten from base class)
enableRegistrationUserLimit($a_limit)
cloneSettings(ilObjSession $new_obj)
clone settings
static lookupSession($a_obj_id)
Get session data.
enableRegistrationWaitingList($a_stat)
addAppointment($appointment)
add appointment
hasTutorSettings()
check if there any tutor settings
setRegistrationMaxUsers($a_users)
update()
update object
Class ilObject Basic functions for all objects.
getLongDescription()
get object long description (stored in object_description)
getId()
get object id @access public
getTitle()
get object title @access public
class ilSessionAppointment
_readFilesByEvent($a_event_id)
global $ilDB
global $ilUser
Definition: imgupload.php:15