ILIAS  Release_3_10_x_branch Revision 61812
 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)." ";
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 
91 
99  public function getPresentationTitle()
100  {
101  $date = new ilDate($this->getFirstAppointment()->getStart()->getUnixTime(),IL_CAL_UNIX);
102  if($this->getTitle())
103  {
104  return ilDatePresentation::formatDate($this->getFirstAppointment()->getStart()).': '.$this->getTitle();
105  }
106  else
107  {
108  return ilDatePresentation::formatDate($date);
109  }
110 
111  }
112 
113 
114 
121  public function getEventId()
122  {
123  return $this->event_id;
124  }
125 
132  public function setLocation($a_location)
133  {
134  $this->location = $a_location;
135  }
136 
143  public function getLocation()
144  {
145  return $this->location;
146  }
147 
154  public function setName($a_name)
155  {
156  $this->name = $a_name;
157  }
158 
165  public function getName()
166  {
167  return $this->name;
168  }
169 
176  public function setPhone($a_phone)
177  {
178  $this->phone = $a_phone;
179  }
180 
187  public function getPhone()
188  {
189  return $this->phone;
190  }
191 
199  public function setEmail($a_email)
200  {
201  $this->email = $a_email;
202  }
203 
210  public function getEmail()
211  {
212  return $this->email;
213  }
214 
220  public function hasTutorSettings()
221  {
222  return strlen($this->getName()) or
223  strlen($this->getEmail()) or
224  strlen($this->getPhone());
225  }
226 
227 
234  public function setDetails($a_details)
235  {
236  $this->details = $a_details;
237  }
238 
245  public function getDetails()
246  {
247  return $this->details;
248  }
249 
257  public function enableRegistration($a_registration)
258  {
259  $this->registration = (bool) $a_registration;
260  }
261 
268  public function enabledRegistration()
269  {
270  return (bool) $this->registration;
271  }
272 
279  public function getAppointments()
280  {
281  return $this->appointments ? $this->appointments : array();
282  }
283 
291  public function addAppointment($appointment)
292  {
293  $this->appointments[] = $appointment;
294  }
295 
304  {
305  $this->appointments = $appointments;
306  }
307 
314  public function getFirstAppointment()
315  {
316  return is_object($this->appointments[0]) ? $this->appointments[0] : ($this->appointments[0] = new ilSessionAppointment());
317  }
318 
326  public function getFiles()
327  {
328  return $this->files ? $this->files : array();
329  }
330 
338  public function validate()
339  {
340  global $ilErr;
341 
342  if(!strlen($this->getTitle()))
343  {
344  $ilErr->appendMessage($this->lng->txt('fill_out_all_required_fields'));
345  return false;
346  }
347  return true;
348  }
349 
358  public function cloneObject($a_target_id,$a_copy_id = 0)
359  {
360  global $ilDB,$ilUser,$ilAppEventHandler;
361 
362  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
363 
364  $this->read();
365 
366  // Copy settings
367  $this->cloneSettings($new_obj);
368 
369  // Clone appointment
370  $new_app = $this->getFirstAppointment()->cloneObject($new_obj->getId());
371  $new_obj->setAppointments(array($new_app));
372  $new_obj->update();
373 
374  // Clone session files
375  foreach($this->files as $file)
376  {
377  $file->cloneFiles($new_obj->getEventId());
378  }
379 
380  // Raise update forn new appointments
381 
382 
383 
384  // Copy learning progress settings
385  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
386  $obj_settings = new ilLPObjSettings($this->getId());
387  $obj_settings->cloneSettings($new_obj->getId());
388  unset($obj_settings);
389 
390  return $new_obj;
391  }
392 
400  public function cloneSettings($new_obj)
401  {
402  $new_obj->setLocation($this->getLocation());
403  $new_obj->setName($this->getName());
404  $new_obj->setPhone($this->getPhone());
405  $new_obj->setEmail($this->getEmail());
406  $new_obj->setDetails($this->getDetails());
407  $new_obj->enableRegistration($this->enabledRegistration());
408  $new_obj->update();
409 
410  return true;
411  }
412 
420  public function cloneDependencies($a_target_id,$a_copy_id)
421  {
422  global $ilObjDataCache;
423 
424  parent::cloneDependencies($a_target_id,$a_copy_id);
425 
426  $target_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
427 
428  include_once('./Modules/Session/classes/class.ilEventItems.php');
429  $session_materials = new ilEventItems($target_obj_id);
430  $session_materials->cloneItems($this->getId(),$a_copy_id);
431 
432  return true;
433  }
434 
435 
436 
442  public function create()
443  {
444  global $ilAppEventHandler;
445 
446  parent::create();
447 
448  $query = "INSERT INTO event SET ".
449  "obj_id = ".$this->db->quote($this->getId()).", ".
450  "location = ".$this->db->quote($this->getLocation()).",".
451  "tutor_name = ".$this->db->quote($this->getName()).", ".
452  "tutor_phone = ".$this->db->quote($this->getPhone()).", ".
453  "tutor_email = ".$this->db->quote($this->getEmail()).", ".
454  "details = ".$this->db->quote($this->getDetails()).",".
455  "registration = ".$this->db->quote($this->enabledRegistration())." ";
456 
457  $this->db->query($query);
458  $this->event_id = $this->db->getLastInsertId();
459 
460  $ilAppEventHandler->raise('Modules/Session',
461  'create',
462  array('object' => $this,
463  'obj_id' => $this->getId(),
464  'appointments' => $this->prepareCalendarAppointments('create')));
465 
466  return $this->getId();
467  }
468 
476  public function update()
477  {
478  global $ilAppEventHandler;
479 
480  if(!parent::update())
481  {
482  return false;
483  }
484  $query = "UPDATE event SET ".
485  "location = ".$this->db->quote($this->getLocation()).",".
486  "tutor_name = ".$this->db->quote($this->getName()).", ".
487  "tutor_phone = ".$this->db->quote($this->getPhone()).", ".
488  "tutor_email = ".$this->db->quote($this->getEmail()).", ".
489  "details = ".$this->db->quote($this->getDetails()).", ".
490  "registration = ".$this->db->quote($this->enabledRegistration())." ".
491  "WHERE obj_id = ".$this->db->quote($this->getId())." ";
492 
493  $this->db->query($query);
494 
495  $ilAppEventHandler->raise('Modules/Session',
496  'update',
497  array('object' => $this,
498  'obj_id' => $this->getId(),
499  'appointments' => $this->prepareCalendarAppointments('update')));
500 
501  return true;
502  }
503 
510  public function delete()
511  {
512  global $ilAppEventHandler;
513 
514  if(!parent::delete())
515  {
516  return false;
517  }
518  $query = "DELETE FROM event ".
519  "WHERE obj_id = ".$this->db->quote($this->getId())." ";
520  $this->db->query($query);
521 
522  include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
524 
525  include_once('./Modules/Session/classes/class.ilEventItems.php');
526  ilEventItems::_delete($this->getId());
527 
528  include_once('./Modules/Session/classes/class.ilEventParticipants.php');
530 
531  foreach($this->getFiles() as $file)
532  {
533  $file->delete();
534  }
535 
536  $ilAppEventHandler->raise('Modules/Session',
537  'delete',
538  array('object' => $this,
539  'obj_id' => $this->getId(),
540  'appointments' => $this->prepareCalendarAppointments('delete')));
541 
542 
543  return true;
544  }
545 
553  public function read()
554  {
555  parent::read();
556 
557  $query = "SELECT * FROM event WHERE ".
558  "obj_id = ".$this->db->quote($this->getId())." ";
559  $res = $this->db->query($query);
560 
561  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
562  {
563  $this->setLocation($row->location);
564  $this->setName($row->tutor_name);
565  $this->setPhone($row->tutor_phone);
566  $this->setEmail($row->tutor_email);
567  $this->setDetails($row->details);
568  $this->enableRegistration((bool) $row->registration);
569  $this->event_id = $row->event_id;
570  }
571 
572  $this->initAppointments();
573  $this->initFiles();
574  }
575 
583  protected function initAppointments()
584  {
585  // get assigned appointments
586  include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
587  $this->appointments = ilSessionAppointment::_readAppointmentsBySession($this->getId());
588  }
589 
597  public function initFiles()
598  {
599  include_once('./Modules/Session/classes/class.ilSessionFile.php');
600  $this->files = ilSessionFile::_readFilesByEvent($this->getEventId());
601  }
602 
603 
611  public function prepareCalendarAppointments($a_mode = 'create')
612  {
613  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
614 
615  switch($a_mode)
616  {
617  case 'create':
618  case 'update':
619 
620  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
621  $app->setTranslationType(IL_CAL_TRANSLATION_NONE);
622  $app->setTitle($this->getTitle());
623  $app->setDescription($this->getLongDescription());
624 
625  $sess_app = $this->getFirstAppointment();
626  $app->setFullday($sess_app->isFullday());
627  $app->setStart($sess_app->getStart());
628  $app->setEnd($sess_app->getEnd());
629  $apps[] = $app;
630 
631  return $apps;
632 
633  case 'delete':
634  // Nothing to do: The category and all assigned appointments will be deleted.
635  return array();
636  }
637  }
638 
639 }
640 
641 ?>