ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
5 include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
6 include_once './Services/Membership/classes/class.ilMembershipRegistrationSettings.php';
7 
16 class ilObjSession extends ilObject
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_min_users = 0;
33  protected $reg_limited_users = 0;
34  protected $reg_waiting_list = 0;
35  protected $reg_waiting_list_autofill; // [bool]
36 
37  protected $appointments;
38  protected $files = array();
39 
40 
41 
48  public function __construct($a_id = 0,$a_call_by_reference = true)
49  {
50  global $ilDB;
51 
52  $this->db = $ilDB;
53  $this->type = "sess";
54  parent::__construct($a_id,$a_call_by_reference);
55  }
56 
65  public static function _lookupRegistrationEnabled($a_obj_id)
66  {
67  global $ilDB;
68 
69  $query = "SELECT reg_type FROM event ".
70  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
71  $res = $ilDB->query($query);
72  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
73  {
74  return (bool) $row->reg_type != ilMembershipRegistrationSettings::TYPE_NONE;
75  }
76  return false;
77  }
78 
84  public static function lookupSession($a_obj_id)
85  {
86  global $ilDB;
87 
88  $query = "SELECT * FROM event ".
89  "WHERE obj_id = ".$ilDB->quote($a_obj_id);
90  $res = $ilDB->query($query);
91  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
92  {
93  $data['location'] = $row->location ? $row->location : '';
94  $data['details'] = $row->details ? $row->details : '';
95  $data['name'] = $row->tutor_name ? $row->tutor_name : '';
96  $data['email'] = $row->tutor_email ? $row->tutor_email : '';
97  $data['phone'] = $row->tutor_phone ? $row->tutor_phone : '';
98  }
99  return (array) $data;
100  }
101 
109  public function getPresentationTitle()
110  {
111  $date = new ilDate($this->getFirstAppointment()->getStart()->getUnixTime(),IL_CAL_UNIX);
112  if($this->getTitle())
113  {
114  return ilDatePresentation::formatDate($this->getFirstAppointment()->getStart()).': '.$this->getTitle();
115  }
116  else
117  {
118  return ilDatePresentation::formatDate($date);
119  }
120 
121  }
122 
123 
124 
131  public function getEventId()
132  {
133  return $this->event_id;
134  }
135 
142  public function setLocation($a_location)
143  {
144  $this->location = $a_location;
145  }
146 
153  public function getLocation()
154  {
155  return $this->location;
156  }
157 
164  public function setName($a_name)
165  {
166  $this->name = $a_name;
167  }
168 
175  public function getName()
176  {
177  return $this->name;
178  }
179 
186  public function setPhone($a_phone)
187  {
188  $this->phone = $a_phone;
189  }
190 
197  public function getPhone()
198  {
199  return $this->phone;
200  }
201 
209  public function setEmail($a_email)
210  {
211  $this->email = $a_email;
212  }
213 
220  public function getEmail()
221  {
222  return $this->email;
223  }
224 
230  public function hasTutorSettings()
231  {
232  return strlen($this->getName()) or
233  strlen($this->getEmail()) or
234  strlen($this->getPhone());
235  }
236 
237 
244  public function setDetails($a_details)
245  {
246  $this->details = $a_details;
247  }
248 
255  public function getDetails()
256  {
257  return $this->details;
258  }
259 
260  public function setRegistrationType($a_type)
261  {
262  $this->reg_type = $a_type;
263  }
264 
265  public function getRegistrationType()
266  {
267  return $this->reg_type;
268  }
269 
271  {
272  return $this->reg_limited;
273  }
274 
275  public function enableRegistrationUserLimit($a_limit)
276  {
277  $this->reg_limited = $a_limit;
278  }
279 
280  public function getRegistrationMinUsers()
281  {
282  return $this->reg_min_users;
283  }
284 
285  public function setRegistrationMinUsers($a_users)
286  {
287  $this->reg_min_users = $a_users;
288  }
289 
290  public function getRegistrationMaxUsers()
291  {
293  }
294 
295  public function setRegistrationMaxUsers($a_users)
296  {
297  $this->reg_limited_users = $a_users;
298  }
299 
301  {
303  }
304 
305  public function enableRegistrationWaitingList($a_stat)
306  {
307  $this->reg_waiting_list = $a_stat;
308  }
309 
310  public function setWaitingListAutoFill($a_value)
311  {
312  $this->reg_waiting_list_autofill = (bool)$a_value;
313  }
314 
315  public function hasWaitingListAutoFill()
316  {
318  }
319 
326  public function enabledRegistration()
327  {
328  return $this->reg_type != ilMembershipRegistrationSettings::TYPE_NONE;
329  }
330 
337  public function getAppointments()
338  {
339  return $this->appointments ? $this->appointments : array();
340  }
341 
349  public function addAppointment($appointment)
350  {
351  $this->appointments[] = $appointment;
352  }
353 
362  {
363  $this->appointments = $appointments;
364  }
365 
372  public function getFirstAppointment()
373  {
374  return is_object($this->appointments[0]) ? $this->appointments[0] : ($this->appointments[0] = new ilSessionAppointment());
375  }
376 
384  public function getFiles()
385  {
386  return $this->files ? $this->files : array();
387  }
388 
396  public function validate()
397  {
398  global $ilErr;
399 
400  // #17114
401  if($this->isRegistrationUserLimitEnabled() &&
402  !$this->getRegistrationMaxUsers())
403  {
404  $ilErr->appendMessage($this->lng->txt("sess_max_members_needed"));
405  return false;
406  }
407 
408  return true;
409  }
410 
419  public function cloneObject($a_target_id,$a_copy_id = 0, $a_omit_tree = false)
420  {
421  global $ilDB,$ilUser,$ilAppEventHandler;
422 
423  $new_obj = parent::cloneObject($a_target_id,$a_copy_id, $a_omit_tree);
424 
425  $this->read();
426 
427  // Copy settings
428  $this->cloneSettings($new_obj);
429 
430  // Clone appointment
431  $new_app = $this->getFirstAppointment()->cloneObject($new_obj->getId());
432  $new_obj->setAppointments(array($new_app));
433  $new_obj->update();
434 
435  // Clone session files
436  foreach($this->files as $file)
437  {
438  $file->cloneFiles($new_obj->getEventId());
439  }
440 
441  // Raise update forn new appointments
442 
443 
444 
445  // Copy learning progress settings
446  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
447  $obj_settings = new ilLPObjSettings($this->getId());
448  $obj_settings->cloneSettings($new_obj->getId());
449  unset($obj_settings);
450 
451  return $new_obj;
452  }
453 
461  public function cloneSettings(ilObjSession $new_obj)
462  {
463  // @var
464  $new_obj->setLocation($this->getLocation());
465  $new_obj->setName($this->getName());
466  $new_obj->setPhone($this->getPhone());
467  $new_obj->setEmail($this->getEmail());
468  $new_obj->setDetails($this->getDetails());
469 
470  $new_obj->setRegistrationType($this->getRegistrationType());
476 
477  $new_obj->update();
478 
479  return true;
480  }
481 
489  public function cloneDependencies($a_target_id,$a_copy_id)
490  {
491  global $ilObjDataCache;
492 
493  parent::cloneDependencies($a_target_id,$a_copy_id);
494 
495  $target_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
496 
497  include_once('./Modules/Session/classes/class.ilEventItems.php');
498  $session_materials = new ilEventItems($target_obj_id);
499  $session_materials->cloneItems($this->getId(),$a_copy_id);
500 
501  return true;
502  }
503 
504 
505 
511  public function create()
512  {
513  global $ilDB;
514  global $ilAppEventHandler;
515 
516  parent::create();
517 
518  $next_id = $ilDB->nextId('event');
519  $query = "INSERT INTO event (event_id,obj_id,location,tutor_name,tutor_phone,tutor_email,details,registration, ".
520  'reg_type, reg_limit_users, reg_limited, reg_waiting_list, reg_min_users, reg_auto_wait) '.
521  "VALUES( ".
522  $ilDB->quote($next_id,'integer').", ".
523  $this->db->quote($this->getId() ,'integer').", ".
524  $this->db->quote($this->getLocation() ,'text').",".
525  $this->db->quote($this->getName() ,'text').", ".
526  $this->db->quote($this->getPhone() ,'text').", ".
527  $this->db->quote($this->getEmail() ,'text').", ".
528  $this->db->quote($this->getDetails() ,'text').",".
529  $this->db->quote($this->enabledRegistration() ,'integer').", ".
530  $this->db->quote($this->getRegistrationType(),'integer').', '.
531  $this->db->quote($this->getRegistrationMaxUsers(),'integer').', '.
532  $this->db->quote($this->isRegistrationUserLimitEnabled(),'integer').', '.
533  $this->db->quote($this->isRegistrationWaitingListEnabled(),'integer').', '.
534  $this->db->quote($this->getRegistrationMinUsers(),'integer').', '.
535  $this->db->quote($this->hasWaitingListAutoFill(),'integer').' '.
536  ")";
537  $res = $ilDB->manipulate($query);
538  $this->event_id = $next_id;
539 
540  $ilAppEventHandler->raise('Modules/Session',
541  'create',
542  array('object' => $this,
543  'obj_id' => $this->getId(),
544  'appointments' => $this->prepareCalendarAppointments('create')));
545 
546  return $this->getId();
547  }
548 
556  public function update()
557  {
558  global $ilDB;
559  global $ilAppEventHandler;
560 
561  if(!parent::update())
562  {
563  return false;
564  }
565  $query = "UPDATE event SET ".
566  "location = ".$this->db->quote($this->getLocation() ,'text').",".
567  "tutor_name = ".$this->db->quote($this->getName() ,'text').", ".
568  "tutor_phone = ".$this->db->quote($this->getPhone() ,'text').", ".
569  "tutor_email = ".$this->db->quote($this->getEmail() ,'text').", ".
570  "details = ".$this->db->quote($this->getDetails() ,'text').", ".
571  "registration = ".$this->db->quote($this->enabledRegistration() ,'integer').", ".
572  "reg_type = ".$this->db->quote($this->getRegistrationType() ,'integer').", ".
573  "reg_limited = ".$this->db->quote($this->isRegistrationUserLimitEnabled() ,'integer').", ".
574  "reg_limit_users = ".$this->db->quote($this->getRegistrationMaxUsers() ,'integer').", ".
575  "reg_min_users = ".$this->db->quote($this->getRegistrationMinUsers() ,'integer').", ".
576  "reg_waiting_list = ".$this->db->quote($this->isRegistrationWaitingListEnabled(),'integer').", ".
577  "reg_auto_wait = ".$this->db->quote($this->hasWaitingListAutoFill(),'integer')." ".
578  "WHERE obj_id = ".$this->db->quote($this->getId() ,'integer')." ";
579  $res = $ilDB->manipulate($query);
580 
581  $ilAppEventHandler->raise('Modules/Session',
582  'update',
583  array('object' => $this,
584  'obj_id' => $this->getId(),
585  'appointments' => $this->prepareCalendarAppointments('update')));
586  return true;
587  }
588 
595  public function delete()
596  {
597  global $ilDB;
598  global $ilAppEventHandler;
599 
600  if(!parent::delete())
601  {
602  return false;
603  }
604  $query = "DELETE FROM event ".
605  "WHERE obj_id = ".$this->db->quote($this->getId() ,'integer')." ";
606  $res = $ilDB->manipulate($query);
607 
608  include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
610 
611  include_once('./Modules/Session/classes/class.ilEventItems.php');
612  ilEventItems::_delete($this->getId());
613 
614  include_once('./Modules/Session/classes/class.ilEventParticipants.php');
616 
617  foreach($this->getFiles() as $file)
618  {
619  $file->delete();
620  }
621 
622  $ilAppEventHandler->raise('Modules/Session',
623  'delete',
624  array('object' => $this,
625  'obj_id' => $this->getId(),
626  'appointments' => $this->prepareCalendarAppointments('delete')));
627 
628 
629  return true;
630  }
631 
639  public function read()
640  {
641  parent::read();
642 
643  $query = "SELECT * FROM event WHERE ".
644  "obj_id = ".$this->db->quote($this->getId() ,'integer')." ";
645  $res = $this->db->query($query);
646 
647  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
648  {
649  $this->setLocation($row->location);
650  $this->setName($row->tutor_name);
651  $this->setPhone($row->tutor_phone);
652  $this->setEmail($row->tutor_email);
653  $this->setDetails($row->details);
654  $this->setRegistrationType($row->reg_type);
655  $this->enableRegistrationUserLimit($row->reg_limited);
656  $this->enableRegistrationWaitingList($row->reg_waiting_list);
657  $this->setWaitingListAutoFill($row->reg_auto_wait);
658  $this->setRegistrationMaxUsers($row->reg_limit_users);
659  $this->setRegistrationMinUsers($row->reg_min_users);
660  $this->event_id = $row->event_id;
661  }
662 
663  $this->initAppointments();
664  $this->initFiles();
665  }
666 
674  protected function initAppointments()
675  {
676  // get assigned appointments
677  include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
678  $this->appointments = ilSessionAppointment::_readAppointmentsBySession($this->getId());
679  }
680 
688  public function initFiles()
689  {
690  include_once('./Modules/Session/classes/class.ilSessionFile.php');
692  }
693 
694 
702  public function prepareCalendarAppointments($a_mode = 'create')
703  {
704  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
705 
706  switch($a_mode)
707  {
708  case 'create':
709  case 'update':
710 
711  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
712  $app->setTranslationType(IL_CAL_TRANSLATION_NONE);
713  $app->setTitle($this->getTitle() ? $this->getTitle() : $this->lng->txt('obj_sess'));
714  $app->setDescription($this->getLongDescription());
715 
716  $sess_app = $this->getFirstAppointment();
717  $app->setFullday($sess_app->isFullday());
718  $app->setStart($sess_app->getStart());
719  $app->setEnd($sess_app->getEnd());
720  $apps[] = $app;
721 
722  return $apps;
723 
724  case 'delete':
725  // Nothing to do: The category and all assigned appointments will be deleted.
726  return array();
727  }
728  }
729 
730  public function handleAutoFill()
731  {
732  if($this->isRegistrationWaitingListEnabled() &&
733  $this->hasWaitingListAutoFill())
734  {
735  // :TODO: what about ilSessionParticipants?
736 
737  include_once './Modules/Session/classes/class.ilEventParticipants.php';
738  $part_obj = new ilEventParticipants($this->getId());
739  $all_reg = $part_obj->getRegistered();
740  $now = sizeof($all_reg);
741  $max = $this->getRegistrationMaxUsers();
742  if($max > $now)
743  {
744  include_once('./Modules/Session/classes/class.ilSessionWaitingList.php');
745  $waiting_list = new ilSessionWaitingList($this->getId());
746 
747  foreach($waiting_list->getUserIds() as $user_id)
748  {
749  if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($user_id,false))
750  {
751  continue;
752  }
753  if(in_array($user_id, $all_reg))
754  {
755  continue;
756  }
757 
758  ilEventParticipants::_register($user_id, $this->getId());
759  $waiting_list->removeFromList($user_id);
760 
761  $now++;
762  if($now >= $max)
763  {
764  break;
765  }
766  }
767  }
768  }
769  }
770 }
771 
772 ?>
getPresentationTitle()
get title (overwritten from base class)
enabledRegistration()
is registration enabled
global $ilErr
Definition: raiseError.php:16
enableRegistrationUserLimit($a_limit)
initFiles()
init files
addAppointment($appointment)
add appointment
getEmail()
get email
const IL_CAL_TRANSLATION_NONE
getEventId()
sget event id
getLocation()
get location
setLocation($a_location)
set location
cloneSettings(ilObjSession $new_obj)
clone settings
__construct($a_id=0, $a_call_by_reference=true)
Constructor public.
read()
read session data
setPhone($a_phone)
set phone
Class ilObject Basic functions for all objects.
initAppointments()
init appointments
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Clone course (no member data)
setWaitingListAutoFill($a_value)
setName($a_name)
set name
setEmail($a_email)
set email
Apointment templates are used for automatic generated apointments.
const IL_CAL_UNIX
getAppointments()
get appointments
static lookupSession($a_obj_id)
Get session data.
$a_type
Definition: workflow.php:93
static _deleteBySession($a_event_id)
cloneDependencies($a_target_id, $a_copy_id)
Clone dependencies.
setRegistrationMinUsers($a_users)
Class for single dates.
getId()
get object id public
static _lookupRegistrationEnabled($a_obj_id)
lookup registration enabled
setRegistrationType($a_type)
hasTutorSettings()
check if there any tutor settings
prepareCalendarAppointments($a_mode='create')
Prepare calendar appointments.
static formatDate(ilDateTime $date)
Format a date public.
getTitle()
get object title public
$ilUser
Definition: imgupload.php:18
getFiles()
get files
static _register($a_usr_id, $a_event_id)
getPhone()
get phone
static _deleteByEvent($a_event_id)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Create styles array
The data for the language used.
setAppointments($appointments)
set appointments
setDetails($a_details)
set details
getDetails()
get details
Done writing files
global $ilDB
getLongDescription()
get object long description (stored in object_description)
update()
update object
static _readAppointmentsBySession($a_event_id)
setRegistrationMaxUsers($a_users)
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
create()
create new session
static _readFilesByEvent($a_event_id)
enableRegistrationWaitingList($a_stat)
class ilEvent
class ilSessionAppointment
static _delete($a_event_id)
getFirstAppointment()
get first appointment