ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjSession.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
25 
35 class ilObjSession extends ilObject
36 {
37  const CAL_REG_START = 1;
38 
39  protected $db;
40 
41  protected $location;
42  protected $name;
43  protected $phone;
44  protected $email;
45  protected $details;
46  protected $registration;
47  protected $event_id;
48 
49  protected $appointments;
50  protected $files = array();
51 
52 
59  public function __construct($a_id = 0,$a_call_by_reference = true)
60  {
61  global $ilDB;
62 
63  $this->type = "sess";
64  parent::__construct($a_id,$a_call_by_reference);
65 
66  $this->db = $ilDB;
67  }
68 
77  public static function _lookupRegistrationEnabled($a_obj_id)
78  {
79  global $ilDB;
80 
81  $query = "SELECT registration FROM event ".
82  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
83  $res = $ilDB->query($query);
84  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
85  {
86  return (bool) $row->registration;
87  }
88  return false;
89  }
90 
96  public static function lookupSession($a_obj_id)
97  {
98  global $ilDB;
99 
100  $query = "SELECT * FROM event ".
101  "WHERE obj_id = ".$ilDB->quote($a_obj_id);
102  $res = $ilDB->query($query);
103  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
104  {
105  $data['location'] = $row->location ? $row->location : '';
106  $data['details'] = $row->details ? $row->details : '';
107  $data['name'] = $row->tutor_name ? $row->tutor_name : '';
108  $data['email'] = $row->tutor_email ? $row->tutor_email : '';
109  $data['phone'] = $row->tutor_phone ? $row->tutor_phone : '';
110  }
111  return (array) $data;
112  }
113 
121  public function getPresentationTitle()
122  {
123  $date = new ilDate($this->getFirstAppointment()->getStart()->getUnixTime(),IL_CAL_UNIX);
124  if($this->getTitle())
125  {
126  return ilDatePresentation::formatDate($this->getFirstAppointment()->getStart()).': '.$this->getTitle();
127  }
128  else
129  {
130  return ilDatePresentation::formatDate($date);
131  }
132 
133  }
134 
135 
136 
143  public function getEventId()
144  {
145  return $this->event_id;
146  }
147 
154  public function setLocation($a_location)
155  {
156  $this->location = $a_location;
157  }
158 
165  public function getLocation()
166  {
167  return $this->location;
168  }
169 
176  public function setName($a_name)
177  {
178  $this->name = $a_name;
179  }
180 
187  public function getName()
188  {
189  return $this->name;
190  }
191 
198  public function setPhone($a_phone)
199  {
200  $this->phone = $a_phone;
201  }
202 
209  public function getPhone()
210  {
211  return $this->phone;
212  }
213 
221  public function setEmail($a_email)
222  {
223  $this->email = $a_email;
224  }
225 
232  public function getEmail()
233  {
234  return $this->email;
235  }
236 
242  public function hasTutorSettings()
243  {
244  return strlen($this->getName()) or
245  strlen($this->getEmail()) or
246  strlen($this->getPhone());
247  }
248 
249 
256  public function setDetails($a_details)
257  {
258  $this->details = $a_details;
259  }
260 
267  public function getDetails()
268  {
269  return $this->details;
270  }
271 
279  public function enableRegistration($a_registration)
280  {
281  $this->registration = (bool) $a_registration;
282  }
283 
290  public function enabledRegistration()
291  {
292  return (bool) $this->registration;
293  }
294 
301  public function getAppointments()
302  {
303  return $this->appointments ? $this->appointments : array();
304  }
305 
313  public function addAppointment($appointment)
314  {
315  $this->appointments[] = $appointment;
316  }
317 
326  {
327  $this->appointments = $appointments;
328  }
329 
336  public function getFirstAppointment()
337  {
338  return is_object($this->appointments[0]) ? $this->appointments[0] : ($this->appointments[0] = new ilSessionAppointment());
339  }
340 
348  public function getFiles()
349  {
350  return $this->files ? $this->files : array();
351  }
352 
360  public function validate()
361  {
362  return true;
363  }
364 
373  public function cloneObject($a_target_id,$a_copy_id = 0)
374  {
375  global $ilDB,$ilUser,$ilAppEventHandler;
376 
377  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
378 
379  $this->read();
380 
381  // Copy settings
382  $this->cloneSettings($new_obj);
383 
384  // Clone appointment
385  $new_app = $this->getFirstAppointment()->cloneObject($new_obj->getId());
386  $new_obj->setAppointments(array($new_app));
387  $new_obj->update();
388 
389  // Clone session files
390  foreach($this->files as $file)
391  {
392  $file->cloneFiles($new_obj->getEventId());
393  }
394 
395  // Raise update forn new appointments
396 
397 
398 
399  // Copy learning progress settings
400  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
401  $obj_settings = new ilLPObjSettings($this->getId());
402  $obj_settings->cloneSettings($new_obj->getId());
403  unset($obj_settings);
404 
405  return $new_obj;
406  }
407 
415  public function cloneSettings($new_obj)
416  {
417  $new_obj->setLocation($this->getLocation());
418  $new_obj->setName($this->getName());
419  $new_obj->setPhone($this->getPhone());
420  $new_obj->setEmail($this->getEmail());
421  $new_obj->setDetails($this->getDetails());
422  $new_obj->enableRegistration($this->enabledRegistration());
423  $new_obj->update();
424 
425  return true;
426  }
427 
435  public function cloneDependencies($a_target_id,$a_copy_id)
436  {
437  global $ilObjDataCache;
438 
439  parent::cloneDependencies($a_target_id,$a_copy_id);
440 
441  $target_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
442 
443  include_once('./Modules/Session/classes/class.ilEventItems.php');
444  $session_materials = new ilEventItems($target_obj_id);
445  $session_materials->cloneItems($this->getId(),$a_copy_id);
446 
447  return true;
448  }
449 
450 
451 
457  public function create()
458  {
459  global $ilDB;
460  global $ilAppEventHandler;
461 
462  parent::create();
463 
464  $next_id = $ilDB->nextId('event');
465  $query = "INSERT INTO event (event_id,obj_id,location,tutor_name,tutor_phone,tutor_email,details,registration) ".
466  "VALUES( ".
467  $ilDB->quote($next_id,'integer').", ".
468  $this->db->quote($this->getId() ,'integer').", ".
469  $this->db->quote($this->getLocation() ,'text').",".
470  $this->db->quote($this->getName() ,'text').", ".
471  $this->db->quote($this->getPhone() ,'text').", ".
472  $this->db->quote($this->getEmail() ,'text').", ".
473  $this->db->quote($this->getDetails() ,'text').",".
474  $this->db->quote($this->enabledRegistration() ,'integer')." ".
475  ")";
476  $res = $ilDB->manipulate($query);
477  $this->event_id = $next_id;
478 
479  $ilAppEventHandler->raise('Modules/Session',
480  'create',
481  array('object' => $this,
482  'obj_id' => $this->getId(),
483  'appointments' => $this->prepareCalendarAppointments('create')));
484 
485  return $this->getId();
486  }
487 
495  public function update()
496  {
497  global $ilDB;
498  global $ilAppEventHandler;
499 
500  if(!parent::update())
501  {
502  return false;
503  }
504  $query = "UPDATE event SET ".
505  "location = ".$this->db->quote($this->getLocation() ,'text').",".
506  "tutor_name = ".$this->db->quote($this->getName() ,'text').", ".
507  "tutor_phone = ".$this->db->quote($this->getPhone() ,'text').", ".
508  "tutor_email = ".$this->db->quote($this->getEmail() ,'text').", ".
509  "details = ".$this->db->quote($this->getDetails() ,'text').", ".
510  "registration = ".$this->db->quote($this->enabledRegistration() ,'integer')." ".
511  "WHERE obj_id = ".$this->db->quote($this->getId() ,'integer')." ";
512  $res = $ilDB->manipulate($query);
513 
514  $ilAppEventHandler->raise('Modules/Session',
515  'update',
516  array('object' => $this,
517  'obj_id' => $this->getId(),
518  'appointments' => $this->prepareCalendarAppointments('update')));
519 
520  return true;
521  }
522 
529  public function delete()
530  {
531  global $ilDB;
532  global $ilAppEventHandler;
533 
534  if(!parent::delete())
535  {
536  return false;
537  }
538  $query = "DELETE FROM event ".
539  "WHERE obj_id = ".$this->db->quote($this->getId() ,'integer')." ";
540  $res = $ilDB->manipulate($query);
541 
542  include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
544 
545  include_once('./Modules/Session/classes/class.ilEventItems.php');
546  ilEventItems::_delete($this->getId());
547 
548  include_once('./Modules/Session/classes/class.ilEventParticipants.php');
550 
551  foreach($this->getFiles() as $file)
552  {
553  $file->delete();
554  }
555 
556  $ilAppEventHandler->raise('Modules/Session',
557  'delete',
558  array('object' => $this,
559  'obj_id' => $this->getId(),
560  'appointments' => $this->prepareCalendarAppointments('delete')));
561 
562 
563  return true;
564  }
565 
573  public function read()
574  {
575  parent::read();
576 
577  $query = "SELECT * FROM event WHERE ".
578  "obj_id = ".$this->db->quote($this->getId() ,'integer')." ";
579  $res = $this->db->query($query);
580 
581  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
582  {
583  $this->setLocation($row->location);
584  $this->setName($row->tutor_name);
585  $this->setPhone($row->tutor_phone);
586  $this->setEmail($row->tutor_email);
587  $this->setDetails($row->details);
588  $this->enableRegistration((bool) $row->registration);
589  $this->event_id = $row->event_id;
590  }
591 
592  $this->initAppointments();
593  $this->initFiles();
594  }
595 
603  protected function initAppointments()
604  {
605  // get assigned appointments
606  include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
607  $this->appointments = ilSessionAppointment::_readAppointmentsBySession($this->getId());
608  }
609 
617  public function initFiles()
618  {
619  include_once('./Modules/Session/classes/class.ilSessionFile.php');
620  $this->files = ilSessionFile::_readFilesByEvent($this->getEventId());
621  }
622 
623 
631  public function prepareCalendarAppointments($a_mode = 'create')
632  {
633  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
634 
635  switch($a_mode)
636  {
637  case 'create':
638  case 'update':
639 
640  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
641  $app->setTranslationType(IL_CAL_TRANSLATION_NONE);
642  $app->setTitle($this->getTitle() ? $this->getTitle() : $this->lng->txt('obj_sess'));
643  $app->setDescription($this->getLongDescription());
644 
645  $sess_app = $this->getFirstAppointment();
646  $app->setFullday($sess_app->isFullday());
647  $app->setStart($sess_app->getStart());
648  $app->setEnd($sess_app->getEnd());
649  $apps[] = $app;
650 
651  return $apps;
652 
653  case 'delete':
654  // Nothing to do: The category and all assigned appointments will be deleted.
655  return array();
656  }
657  }
658 
659 }
660 
661 ?>