ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
15 class ilObjSession extends ilObject
16 {
17  const CAL_REG_START = 1;
18 
19  protected $db;
20 
21  protected $location;
22  protected $name;
23  protected $phone;
24  protected $email;
25  protected $details;
26  protected $registration;
27  protected $event_id;
28 
29  protected $appointments;
30  protected $files = array();
31 
32 
39  public function __construct($a_id = 0,$a_call_by_reference = true)
40  {
41  global $ilDB;
42 
43  $this->db = $ilDB;
44  $this->type = "sess";
45  parent::__construct($a_id,$a_call_by_reference);
46  }
47 
56  public static function _lookupRegistrationEnabled($a_obj_id)
57  {
58  global $ilDB;
59 
60  $query = "SELECT registration FROM event ".
61  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
62  $res = $ilDB->query($query);
63  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
64  {
65  return (bool) $row->registration;
66  }
67  return false;
68  }
69 
75  public static function lookupSession($a_obj_id)
76  {
77  global $ilDB;
78 
79  $query = "SELECT * FROM event ".
80  "WHERE obj_id = ".$ilDB->quote($a_obj_id);
81  $res = $ilDB->query($query);
82  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
83  {
84  $data['location'] = $row->location ? $row->location : '';
85  $data['details'] = $row->details ? $row->details : '';
86  $data['name'] = $row->tutor_name ? $row->tutor_name : '';
87  $data['email'] = $row->tutor_email ? $row->tutor_email : '';
88  $data['phone'] = $row->tutor_phone ? $row->tutor_phone : '';
89  }
90  return (array) $data;
91  }
92 
100  public function getPresentationTitle()
101  {
102  $date = new ilDate($this->getFirstAppointment()->getStart()->getUnixTime(),IL_CAL_UNIX);
103  if($this->getTitle())
104  {
105  return ilDatePresentation::formatDate($this->getFirstAppointment()->getStart()).': '.$this->getTitle();
106  }
107  else
108  {
109  return ilDatePresentation::formatDate($date);
110  }
111 
112  }
113 
114 
115 
122  public function getEventId()
123  {
124  return $this->event_id;
125  }
126 
133  public function setLocation($a_location)
134  {
135  $this->location = $a_location;
136  }
137 
144  public function getLocation()
145  {
146  return $this->location;
147  }
148 
155  public function setName($a_name)
156  {
157  $this->name = $a_name;
158  }
159 
166  public function getName()
167  {
168  return $this->name;
169  }
170 
177  public function setPhone($a_phone)
178  {
179  $this->phone = $a_phone;
180  }
181 
188  public function getPhone()
189  {
190  return $this->phone;
191  }
192 
200  public function setEmail($a_email)
201  {
202  $this->email = $a_email;
203  }
204 
211  public function getEmail()
212  {
213  return $this->email;
214  }
215 
221  public function hasTutorSettings()
222  {
223  return strlen($this->getName()) or
224  strlen($this->getEmail()) or
225  strlen($this->getPhone());
226  }
227 
228 
235  public function setDetails($a_details)
236  {
237  $this->details = $a_details;
238  }
239 
246  public function getDetails()
247  {
248  return $this->details;
249  }
250 
258  public function enableRegistration($a_registration)
259  {
260  $this->registration = (bool) $a_registration;
261  }
262 
269  public function enabledRegistration()
270  {
271  return (bool) $this->registration;
272  }
273 
280  public function getAppointments()
281  {
282  return $this->appointments ? $this->appointments : array();
283  }
284 
292  public function addAppointment($appointment)
293  {
294  $this->appointments[] = $appointment;
295  }
296 
305  {
306  $this->appointments = $appointments;
307  }
308 
315  public function getFirstAppointment()
316  {
317  return is_object($this->appointments[0]) ? $this->appointments[0] : ($this->appointments[0] = new ilSessionAppointment());
318  }
319 
327  public function getFiles()
328  {
329  return $this->files ? $this->files : array();
330  }
331 
339  public function validate()
340  {
341  return true;
342  }
343 
352  public function cloneObject($a_target_id,$a_copy_id = 0)
353  {
354  global $ilDB,$ilUser,$ilAppEventHandler;
355 
356  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
357 
358  $this->read();
359 
360  // Copy settings
361  $this->cloneSettings($new_obj);
362 
363  // Clone appointment
364  $new_app = $this->getFirstAppointment()->cloneObject($new_obj->getId());
365  $new_obj->setAppointments(array($new_app));
366  $new_obj->update();
367 
368  // Clone session files
369  foreach($this->files as $file)
370  {
371  $file->cloneFiles($new_obj->getEventId());
372  }
373 
374  // Raise update forn new appointments
375 
376 
377 
378  // Copy learning progress settings
379  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
380  $obj_settings = new ilLPObjSettings($this->getId());
381  $obj_settings->cloneSettings($new_obj->getId());
382  unset($obj_settings);
383 
384  return $new_obj;
385  }
386 
394  public function cloneSettings($new_obj)
395  {
396  $new_obj->setLocation($this->getLocation());
397  $new_obj->setName($this->getName());
398  $new_obj->setPhone($this->getPhone());
399  $new_obj->setEmail($this->getEmail());
400  $new_obj->setDetails($this->getDetails());
401  $new_obj->enableRegistration($this->enabledRegistration());
402  $new_obj->update();
403 
404  return true;
405  }
406 
414  public function cloneDependencies($a_target_id,$a_copy_id)
415  {
416  global $ilObjDataCache;
417 
418  parent::cloneDependencies($a_target_id,$a_copy_id);
419 
420  $target_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
421 
422  include_once('./Modules/Session/classes/class.ilEventItems.php');
423  $session_materials = new ilEventItems($target_obj_id);
424  $session_materials->cloneItems($this->getId(),$a_copy_id);
425 
426  return true;
427  }
428 
429 
430 
436  public function create()
437  {
438  global $ilDB;
439  global $ilAppEventHandler;
440 
441  parent::create();
442 
443  $next_id = $ilDB->nextId('event');
444  $query = "INSERT INTO event (event_id,obj_id,location,tutor_name,tutor_phone,tutor_email,details,registration) ".
445  "VALUES( ".
446  $ilDB->quote($next_id,'integer').", ".
447  $this->db->quote($this->getId() ,'integer').", ".
448  $this->db->quote($this->getLocation() ,'text').",".
449  $this->db->quote($this->getName() ,'text').", ".
450  $this->db->quote($this->getPhone() ,'text').", ".
451  $this->db->quote($this->getEmail() ,'text').", ".
452  $this->db->quote($this->getDetails() ,'text').",".
453  $this->db->quote($this->enabledRegistration() ,'integer')." ".
454  ")";
455  $res = $ilDB->manipulate($query);
456  $this->event_id = $next_id;
457 
458  $ilAppEventHandler->raise('Modules/Session',
459  'create',
460  array('object' => $this,
461  'obj_id' => $this->getId(),
462  'appointments' => $this->prepareCalendarAppointments('create')));
463 
464  return $this->getId();
465  }
466 
474  public function update()
475  {
476  global $ilDB;
477  global $ilAppEventHandler;
478 
479  if(!parent::update())
480  {
481  return false;
482  }
483  $query = "UPDATE event SET ".
484  "location = ".$this->db->quote($this->getLocation() ,'text').",".
485  "tutor_name = ".$this->db->quote($this->getName() ,'text').", ".
486  "tutor_phone = ".$this->db->quote($this->getPhone() ,'text').", ".
487  "tutor_email = ".$this->db->quote($this->getEmail() ,'text').", ".
488  "details = ".$this->db->quote($this->getDetails() ,'text').", ".
489  "registration = ".$this->db->quote($this->enabledRegistration() ,'integer')." ".
490  "WHERE obj_id = ".$this->db->quote($this->getId() ,'integer')." ";
491  $res = $ilDB->manipulate($query);
492 
493  $ilAppEventHandler->raise('Modules/Session',
494  'update',
495  array('object' => $this,
496  'obj_id' => $this->getId(),
497  'appointments' => $this->prepareCalendarAppointments('update')));
498 
499  return true;
500  }
501 
508  public function delete()
509  {
510  global $ilDB;
511  global $ilAppEventHandler;
512 
513  if(!parent::delete())
514  {
515  return false;
516  }
517  $query = "DELETE FROM event ".
518  "WHERE obj_id = ".$this->db->quote($this->getId() ,'integer')." ";
519  $res = $ilDB->manipulate($query);
520 
521  include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
523 
524  include_once('./Modules/Session/classes/class.ilEventItems.php');
525  ilEventItems::_delete($this->getId());
526 
527  include_once('./Modules/Session/classes/class.ilEventParticipants.php');
529 
530  foreach($this->getFiles() as $file)
531  {
532  $file->delete();
533  }
534 
535  $ilAppEventHandler->raise('Modules/Session',
536  'delete',
537  array('object' => $this,
538  'obj_id' => $this->getId(),
539  'appointments' => $this->prepareCalendarAppointments('delete')));
540 
541 
542  return true;
543  }
544 
552  public function read()
553  {
554  parent::read();
555 
556  $query = "SELECT * FROM event WHERE ".
557  "obj_id = ".$this->db->quote($this->getId() ,'integer')." ";
558  $res = $this->db->query($query);
559 
560  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
561  {
562  $this->setLocation($row->location);
563  $this->setName($row->tutor_name);
564  $this->setPhone($row->tutor_phone);
565  $this->setEmail($row->tutor_email);
566  $this->setDetails($row->details);
567  $this->enableRegistration((bool) $row->registration);
568  $this->event_id = $row->event_id;
569  }
570 
571  $this->initAppointments();
572  $this->initFiles();
573  }
574 
582  protected function initAppointments()
583  {
584  // get assigned appointments
585  include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
586  $this->appointments = ilSessionAppointment::_readAppointmentsBySession($this->getId());
587  }
588 
596  public function initFiles()
597  {
598  include_once('./Modules/Session/classes/class.ilSessionFile.php');
599  $this->files = ilSessionFile::_readFilesByEvent($this->getEventId());
600  }
601 
602 
610  public function prepareCalendarAppointments($a_mode = 'create')
611  {
612  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
613 
614  switch($a_mode)
615  {
616  case 'create':
617  case 'update':
618 
619  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
620  $app->setTranslationType(IL_CAL_TRANSLATION_NONE);
621  $app->setTitle($this->getTitle() ? $this->getTitle() : $this->lng->txt('obj_sess'));
622  $app->setDescription($this->getLongDescription());
623 
624  $sess_app = $this->getFirstAppointment();
625  $app->setFullday($sess_app->isFullday());
626  $app->setStart($sess_app->getStart());
627  $app->setEnd($sess_app->getEnd());
628  $apps[] = $app;
629 
630  return $apps;
631 
632  case 'delete':
633  // Nothing to do: The category and all assigned appointments will be deleted.
634  return array();
635  }
636  }
637 
638 }
639 
640 ?>