ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 LOCAL_ROLE_PARTICIPANT_PREFIX = 'il_sess_participant';
19
20 const CAL_REG_START = 1;
21
22 protected $db;
23
24 protected $location;
25 protected $name;
26 protected $phone;
27 protected $email;
28 protected $details;
29 protected $registration;
30 protected $event_id;
31
33 protected $reg_limited = 0;
34 protected $reg_min_users = 0;
35 protected $reg_limited_users = 0;
36 protected $reg_waiting_list = 0;
37 protected $reg_waiting_list_autofill; // [bool]
38
39 protected $appointments;
40 protected $files = array();
41
45 protected $session_logger = null;
46
47
48
55 public function __construct($a_id = 0, $a_call_by_reference = true)
56 {
57 global $ilDB;
58
59 $this->session_logger = $GLOBALS['DIC']->logger()->sess();
60
61 $this->db = $ilDB;
62 $this->type = "sess";
63 parent::__construct($a_id, $a_call_by_reference);
64 }
65
74 public static function _lookupRegistrationEnabled($a_obj_id)
75 {
76 global $ilDB;
77
78 $query = "SELECT reg_type FROM event " .
79 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
80 $res = $ilDB->query($query);
81 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
82 return (bool) $row->reg_type != ilMembershipRegistrationSettings::TYPE_NONE;
83 }
84 return false;
85 }
86
92 public static function lookupSession($a_obj_id)
93 {
94 global $ilDB;
95
96 $query = "SELECT * FROM event " .
97 "WHERE obj_id = " . $ilDB->quote($a_obj_id);
98 $res = $ilDB->query($query);
99 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
100 $data['location'] = $row->location ? $row->location : '';
101 $data['details'] = $row->details ? $row->details : '';
102 $data['name'] = $row->tutor_name ? $row->tutor_name : '';
103 $data['email'] = $row->tutor_email ? $row->tutor_email : '';
104 $data['phone'] = $row->tutor_phone ? $row->tutor_phone : '';
105 }
106 return (array) $data;
107 }
108
116 public function getPresentationTitle()
117 {
118 $date = new ilDate($this->getFirstAppointment()->getStart()->getUnixTime(), IL_CAL_UNIX);
119 if ($this->getTitle()) {
120 return ilDatePresentation::formatDate($this->getFirstAppointment()->getStart()) . ': ' . $this->getTitle();
121 } else {
122 return ilDatePresentation::formatDate($date);
123 }
124 }
125
129 public function initDefaultRoles()
130 {
131 include_once './Services/AccessControl/classes/class.ilObjRole.php';
133 self::LOCAL_ROLE_PARTICIPANT_PREFIX . '_' . $this->getRefId(),
134 'Participant of session obj_no.' . $this->getId(),
135 self::LOCAL_ROLE_PARTICIPANT_PREFIX,
136 $this->getRefId()
137 );
138
139 if (!$role instanceof ilObjRole) {
140 $this->session_logger->warning('Could not create default session role.');
141 $this->session_logger->logStack(ilLogLevel::WARNING);
142 }
143 return array();
144 }
145
152 public function getEventId()
153 {
154 return $this->event_id;
155 }
156
163 public function setLocation($a_location)
164 {
165 $this->location = $a_location;
166 }
167
174 public function getLocation()
175 {
176 return $this->location;
177 }
178
185 public function setName($a_name)
186 {
187 $this->name = $a_name;
188 }
189
196 public function getName()
197 {
198 return $this->name;
199 }
200
207 public function setPhone($a_phone)
208 {
209 $this->phone = $a_phone;
210 }
211
218 public function getPhone()
219 {
220 return $this->phone;
221 }
222
230 public function setEmail($a_email)
231 {
232 $this->email = $a_email;
233 }
234
241 public function getEmail()
242 {
243 return $this->email;
244 }
245
251 public function hasTutorSettings()
252 {
253 return strlen($this->getName()) or
254 strlen($this->getEmail()) or
255 strlen($this->getPhone());
256 }
257
258
265 public function setDetails($a_details)
266 {
267 $this->details = $a_details;
268 }
269
276 public function getDetails()
277 {
278 return $this->details;
279 }
280
282 {
283 $this->reg_type = $a_type;
284 }
285
286 public function getRegistrationType()
287 {
288 return $this->reg_type;
289 }
290
292 {
293 return $this->reg_limited;
294 }
295
296 public function enableRegistrationUserLimit($a_limit)
297 {
298 $this->reg_limited = $a_limit;
299 }
300
301 public function getRegistrationMinUsers()
302 {
304 }
305
306 public function setRegistrationMinUsers($a_users)
307 {
308 $this->reg_min_users = $a_users;
309 }
310
311 public function getRegistrationMaxUsers()
312 {
314 }
315
316 public function setRegistrationMaxUsers($a_users)
317 {
318 $this->reg_limited_users = $a_users;
319 }
320
322 {
324 }
325
326 public function enableRegistrationWaitingList($a_stat)
327 {
328 $this->reg_waiting_list = $a_stat;
329 }
330
331 public function setWaitingListAutoFill($a_value)
332 {
333 $this->reg_waiting_list_autofill = (bool) $a_value;
334 }
335
336 public function hasWaitingListAutoFill()
337 {
339 }
340
347 public function enabledRegistration()
348 {
349 return $this->reg_type != ilMembershipRegistrationSettings::TYPE_NONE;
350 }
351
358 public function getAppointments()
359 {
360 return $this->appointments ? $this->appointments : array();
361 }
362
370 public function addAppointment($appointment)
371 {
372 $this->appointments[] = $appointment;
373 }
374
383 {
384 $this->appointments = $appointments;
385 }
386
393 public function getFirstAppointment()
394 {
395 return is_object($this->appointments[0]) ? $this->appointments[0] : ($this->appointments[0] = new ilSessionAppointment());
396 }
397
405 public function getFiles()
406 {
407 return $this->files ? $this->files : array();
408 }
409
417 public function validate()
418 {
419 global $ilErr;
420
421 // #17114
422 if ($this->isRegistrationUserLimitEnabled() &&
423 !$this->getRegistrationMaxUsers()) {
424 $ilErr->appendMessage($this->lng->txt("sess_max_members_needed"));
425 return false;
426 }
427
428 return true;
429 }
430
439 public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
440 {
441 $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
442
443 $this->read();
444
445 $this->cloneSettings($new_obj);
446 $this->cloneMetaData($new_obj);
447
448
449 // Clone appointment
450 $new_app = $this->getFirstAppointment()->cloneObject($new_obj->getId());
451 $new_obj->setAppointments(array($new_app));
452 $new_obj->update(true);
453
454 // Clone session files
455 foreach ($this->files as $file) {
456 $file->cloneFiles($new_obj->getEventId());
457 }
458
459 // Raise update forn new appointments
460
461
462
463 // Copy learning progress settings
464 include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
465 $obj_settings = new ilLPObjSettings($this->getId());
466 $obj_settings->cloneSettings($new_obj->getId());
467 unset($obj_settings);
468
469 return $new_obj;
470 }
471
479 public function cloneSettings(ilObjSession $new_obj)
480 {
481 // @var
482 $new_obj->setLocation($this->getLocation());
483 $new_obj->setName($this->getName());
484 $new_obj->setPhone($this->getPhone());
485 $new_obj->setEmail($this->getEmail());
486 $new_obj->setDetails($this->getDetails());
487
488 $new_obj->setRegistrationType($this->getRegistrationType());
494
495 $new_obj->update(true);
496
497 return true;
498 }
499
507 public function cloneDependencies($a_target_id, $a_copy_id)
508 {
509 global $ilObjDataCache;
510
511 parent::cloneDependencies($a_target_id, $a_copy_id);
512
513 $target_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
514
515 include_once('./Modules/Session/classes/class.ilEventItems.php');
516 $session_materials = new ilEventItems($target_obj_id);
517 $session_materials->cloneItems($this->getId(), $a_copy_id);
518
519 return true;
520 }
521
522
523
529 public function create($a_skip_meta_data = false)
530 {
531 global $ilDB;
532 global $ilAppEventHandler;
533
534 parent::create();
535
536 if (!$a_skip_meta_data) {
537 $this->createMetaData();
538 }
539
540 $next_id = $ilDB->nextId('event');
541 $query = "INSERT INTO event (event_id,obj_id,location,tutor_name,tutor_phone,tutor_email,details,registration, " .
542 'reg_type, reg_limit_users, reg_limited, reg_waiting_list, reg_min_users, reg_auto_wait) ' .
543 "VALUES( " .
544 $ilDB->quote($next_id, 'integer') . ", " .
545 $this->db->quote($this->getId(), 'integer') . ", " .
546 $this->db->quote($this->getLocation(), 'text') . "," .
547 $this->db->quote($this->getName(), 'text') . ", " .
548 $this->db->quote($this->getPhone(), 'text') . ", " .
549 $this->db->quote($this->getEmail(), 'text') . ", " .
550 $this->db->quote($this->getDetails(), 'text') . "," .
551 $this->db->quote($this->enabledRegistration(), 'integer') . ", " .
552 $this->db->quote($this->getRegistrationType(), 'integer') . ', ' .
553 $this->db->quote($this->getRegistrationMaxUsers(), 'integer') . ', ' .
554 $this->db->quote($this->isRegistrationUserLimitEnabled(), 'integer') . ', ' .
555 $this->db->quote($this->isRegistrationWaitingListEnabled(), 'integer') . ', ' .
556 $this->db->quote($this->getRegistrationMinUsers(), 'integer') . ', ' .
557 $this->db->quote($this->hasWaitingListAutoFill(), 'integer') . ' ' .
558 ")";
559 $res = $ilDB->manipulate($query);
560 $this->event_id = $next_id;
561
562 $ilAppEventHandler->raise(
563 'Modules/Session',
564 'create',
565 array('object' => $this,
566 'obj_id' => $this->getId(),
567 'appointments' => $this->prepareCalendarAppointments('create'))
568 );
569
570 return $this->getId();
571 }
572
580 public function update($a_skip_meta_update = false)
581 {
582 global $ilDB;
583 global $ilAppEventHandler;
584
585 if (!parent::update()) {
586 return false;
587 }
588 if (!$a_skip_meta_update) {
589 $this->updateMetaData();
590 }
591
592 $query = "UPDATE event SET " .
593 "location = " . $this->db->quote($this->getLocation(), 'text') . "," .
594 "tutor_name = " . $this->db->quote($this->getName(), 'text') . ", " .
595 "tutor_phone = " . $this->db->quote($this->getPhone(), 'text') . ", " .
596 "tutor_email = " . $this->db->quote($this->getEmail(), 'text') . ", " .
597 "details = " . $this->db->quote($this->getDetails(), 'text') . ", " .
598 "registration = " . $this->db->quote($this->enabledRegistration(), 'integer') . ", " .
599 "reg_type = " . $this->db->quote($this->getRegistrationType(), 'integer') . ", " .
600 "reg_limited = " . $this->db->quote($this->isRegistrationUserLimitEnabled(), 'integer') . ", " .
601 "reg_limit_users = " . $this->db->quote($this->getRegistrationMaxUsers(), 'integer') . ", " .
602 "reg_min_users = " . $this->db->quote($this->getRegistrationMinUsers(), 'integer') . ", " .
603 "reg_waiting_list = " . $this->db->quote($this->isRegistrationWaitingListEnabled(), 'integer') . ", " .
604 "reg_auto_wait = " . $this->db->quote($this->hasWaitingListAutoFill(), 'integer') . " " .
605 "WHERE obj_id = " . $this->db->quote($this->getId(), 'integer') . " ";
606 $res = $ilDB->manipulate($query);
607
608 $ilAppEventHandler->raise(
609 'Modules/Session',
610 'update',
611 array('object' => $this,
612 'obj_id' => $this->getId(),
613 'appointments' => $this->prepareCalendarAppointments('update'))
614 );
615 return true;
616 }
617
624 public function delete()
625 {
626 global $ilDB;
627 global $ilAppEventHandler;
628
629 if (!parent::delete()) {
630 return false;
631 }
632
633 // delete meta data
634 $this->deleteMetaData();
635
636 $query = "DELETE FROM event " .
637 "WHERE obj_id = " . $this->db->quote($this->getId(), 'integer') . " ";
638 $res = $ilDB->manipulate($query);
639
640 include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
642
643 include_once('./Modules/Session/classes/class.ilEventItems.php');
645
646 include_once('./Modules/Session/classes/class.ilEventParticipants.php');
648
649 foreach ($this->getFiles() as $file) {
650 $file->delete();
651 }
652
653 $ilAppEventHandler->raise(
654 'Modules/Session',
655 'delete',
656 array('object' => $this,
657 'obj_id' => $this->getId(),
658 'appointments' => $this->prepareCalendarAppointments('delete'))
659 );
660
661
662 return true;
663 }
664
672 public function read()
673 {
674 parent::read();
675
676 $query = "SELECT * FROM event WHERE " .
677 "obj_id = " . $this->db->quote($this->getId(), 'integer') . " ";
678 $res = $this->db->query($query);
679
680 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
681 $this->setLocation($row->location);
682 $this->setName($row->tutor_name);
683 $this->setPhone($row->tutor_phone);
684 $this->setEmail($row->tutor_email);
685 $this->setDetails($row->details);
686 $this->setRegistrationType($row->reg_type);
687 $this->enableRegistrationUserLimit($row->reg_limited);
688 $this->enableRegistrationWaitingList($row->reg_waiting_list);
689 $this->setWaitingListAutoFill($row->reg_auto_wait);
690 $this->setRegistrationMaxUsers($row->reg_limit_users);
691 $this->setRegistrationMinUsers($row->reg_min_users);
692 $this->event_id = $row->event_id;
693 }
694
695 $this->initAppointments();
696 $this->initFiles();
697 }
698
706 protected function initAppointments()
707 {
708 // get assigned appointments
709 include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
710 $this->appointments = ilSessionAppointment::_readAppointmentsBySession($this->getId());
711 }
712
720 public function initFiles()
721 {
722 include_once('./Modules/Session/classes/class.ilSessionFile.php');
723 $this->files = ilSessionFile::_readFilesByEvent($this->getEventId());
724 }
725
726
734 public function prepareCalendarAppointments($a_mode = 'create')
735 {
736 include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
737
738 switch ($a_mode) {
739 case 'create':
740 case 'update':
741
742 $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
743 $app->setTranslationType(IL_CAL_TRANSLATION_NONE);
744 $app->setTitle($this->getTitle() ? $this->getTitle() : $this->lng->txt('obj_sess'));
745 $app->setDescription($this->getLongDescription());
746
747 $sess_app = $this->getFirstAppointment();
748 $app->setFullday($sess_app->isFullday());
749 $app->setStart($sess_app->getStart());
750 $app->setEnd($sess_app->getEnd());
751 $apps[] = $app;
752
753 return $apps;
754
755 case 'delete':
756 // Nothing to do: The category and all assigned appointments will be deleted.
757 return array();
758 }
759 }
760
764 public function handleAutoFill()
765 {
766 if (
768 !$this->hasWaitingListAutoFill()
769 ) {
770 $this->session_logger->debug('Waiting list or auto fill is disabled.');
771 return true;
772 }
773
775 $current = $parts->getCountParticipants();
776 $max = $this->getRegistrationMaxUsers();
777
778 if ($max <= $current) {
779 $this->session_logger->debug('Maximum number of participants not reached.');
780 $this->session_logger->debug('Maximum number of members: ' . $max);
781 $this->session_logger->debug('Current number of members: ' . $current);
782 return true;
783 }
784
785 $session_waiting_list = new ilSessionWaitingList($this->getId());
786 foreach ($session_waiting_list->getUserIds() as $user_id) {
787 $user = ilObjectFactory::getInstanceByObjId($user_id);
788 if (!$user instanceof ilObjUser) {
789 $this->session_logger->warning('Found invalid user id on waiting list: ' . $user_id);
790 continue;
791 }
792 if (in_array($user_id, $parts->getParticipants())) {
793 $this->session_logger->notice('User on waiting list already session member: ' . $user_id);
794 continue;
795 }
796
797 if ($this->enabledRegistration()) {
798 $this->session_logger->debug('Registration enabled: register user');
799 $parts->register($user_id);
800 $parts->sendNotification(
802 $user_id
803 );
804 } else {
805 $this->session_logger->debug('Registration disabled: set user status to participated.');
806 $parts->getEventParticipants()->updateParticipation($user_id, true);
807 $parts->sendNotification(
809 $user_id
810 );
811 }
812
813 $session_waiting_list->removeFromList($user_id);
814
815 $current++;
816 if ($current >= $max) {
817 break;
818 }
819 }
820 }
821
826 public function getMailToMembersType()
827 {
828 return false;
829 }
830
838 protected function initParticipants()
839 {
840 include_once('./Modules/Session/classes/class.ilSessionParticipants.php');
841 $this->members_obj = ilSessionParticipants::_getInstanceByObjId($this->getId());
842 }
843
849 public function getMembersObject()
850 {
851 // #17886
852 if (!$this->members_obj instanceof ilGroupParticipants) {
853 $this->initParticipants();
854 }
855 return $this->members_obj;
856 }
857}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_TRANSLATION_NONE
const IL_CAL_UNIX
Apointment templates are used for automatic generated apointments.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date @access public.
Class for single dates.
class ilEvent
static _delete($a_event_id)
static _deleteByEvent($a_event_id)
Class ilObjRole.
static createDefaultRole($a_title, $a_description, $a_tpl_name, $a_ref_id)
__construct($a_id=0, $a_call_by_reference=true)
Constructor @access public.
getFirstAppointment()
get first appointment
const LOCAL_ROLE_PARTICIPANT_PREFIX
enabledRegistration()
is registration enabled
static _lookupRegistrationEnabled($a_obj_id)
lookup registration enabled
getMailToMembersType()
Get mail to members type.
setLocation($a_location)
set location
setEmail($a_email)
set email
getDetails()
get details
read()
read session data
getLocation()
get location
initDefaultRoles()
Create local session participant role.
update($a_skip_meta_update=false)
update object
getEventId()
sget event id
setRegistrationType($a_type)
setName($a_name)
set name
setRegistrationMinUsers($a_users)
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
setWaitingListAutoFill($a_value)
cloneDependencies($a_target_id, $a_copy_id)
Clone dependencies.
initFiles()
init files
getPresentationTitle()
get title (overwritten from base class)
enableRegistrationUserLimit($a_limit)
cloneSettings(ilObjSession $new_obj)
clone settings
static lookupSession($a_obj_id)
Get session data.
initParticipants()
init participants object
create($a_skip_meta_data=false)
create new session
getMembersObject()
Get members objects.
enableRegistrationWaitingList($a_stat)
addAppointment($appointment)
add appointment
handleAutoFill()
Handle auto fill for session members.
hasTutorSettings()
check if there any tutor settings
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Clone course (no member data)
setRegistrationMaxUsers($a_users)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Class ilObject Basic functions for all objects.
deleteMetaData()
delete meta data entry
updateMetaData()
update meta data entry
createMetaData()
create meta data entry
getRefId()
get reference id @access public
getLongDescription()
get object long description (stored in object_description)
cloneMetaData($target_obj)
Copy meta data.
getId()
get object id @access public
getTitle()
get object title @access public
class ilSessionAppointment
static _readAppointmentsBySession($a_event_id)
static _deleteBySession($a_event_id)
static _readFilesByEvent($a_event_id)
static _getInstanceByObjId($a_obj_id)
Get instance.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
update($pash, $contents, Config $config)
$query
global $ilErr
Definition: raiseError.php:16
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
foreach($_POST as $key=> $value) $res
global $ilDB
$a_type
Definition: workflow.php:92