• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Modules/Course/classes/Event/class.ilEvent.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00034 include_once 'Modules/Course/classes/Event/class.ilEventAppointment.php';
00035 include_once 'Modules/Course/classes/Event/class.ilEventFile.php';
00036 
00037 class ilEvent
00038 {
00039         var $ilErr;
00040         var $ilDB;
00041         var $tree;
00042         var $lng;
00043 
00044         var $event_id = null;
00045         var $appointments = array();
00046 
00047 
00048         function ilEvent($a_event_id = 0)
00049         {
00050                 global $ilErr,$ilDB,$lng,$tree;
00051 
00052                 $this->ilErr =& $ilErr;
00053                 $this->db  =& $ilDB;
00054                 $this->lng =& $lng;
00055 
00056                 $this->event_id = $a_event_id;
00057                 $this->__read();
00058         }
00059 
00060         function setObjId($a_obj_id)
00061         {
00062                 $this->obj_id = $a_obj_id;
00063         }
00064         function getObjId()
00065         {
00066                 return $this->obj_id;
00067         }
00068 
00069         function getEventId()
00070         {
00071                 return $this->event_id;
00072         }
00073         function setEventId($a_event_id)
00074         {
00075                 $this->event_id = $a_event_id;
00076         }
00077         function getTitle()
00078         {
00079                 return $this->title;
00080         }
00081         function setTitle($a_title)
00082         {
00083                 $this->title = $a_title;
00084         }
00085         function getDescription()
00086         {
00087                 return $this->description;
00088         }
00089         function setDescription($a_description)
00090         {
00091                 $this->description = $a_description;
00092         }
00093 
00094         function getLocation()
00095         {
00096                 return $this->location;
00097         }
00098         function setLocation($a_location)
00099         {
00100                 $this->location = $a_location;
00101         }
00102         function setName($a_name)
00103         {
00104                 $this->name = $a_name;
00105         }
00106         function getName()
00107         {
00108                 return $this->name;
00109         }
00110 
00111         function getFirstname()
00112         {
00113                 return $this->firstname;
00114         }
00115         function setFirstname($a_firstname)
00116         {
00117                 $this->firstname = $a_firstname;
00118         }
00119         function getLastname()
00120         {
00121                 return $this->lastname;
00122         }
00123         function setLastname($a_lastname)
00124         {
00125                 $this->lastname = $a_lastname;
00126         }
00127         function getPTitle()
00128         {
00129                 return $this->ptitle;
00130         }
00131         function setPTitle($a_ptitle)
00132         {
00133                 $this->ptitle = $a_ptitle;
00134         }
00135         function getEmail()
00136         {
00137                 return $this->mail;
00138         }
00139         function setEmail($a_mail)
00140         {
00141                 $this->mail = $a_mail;
00142         }
00143         function getPhone()
00144         {
00145                 return $this->phone;
00146         }
00147         function setPhone($a_phone)
00148         {
00149                 $this->phone = $a_phone;
00150         }
00151         function setDetails($a_details)
00152         {
00153                 $this->details = $a_details;
00154         }
00155         function getDetails()
00156         {
00157                 return $this->details;
00158         }
00159         function enabledRegistration()
00160         {
00161                 return (bool) $this->registration;
00162         }
00163         function enableRegistration($a_status)
00164         {
00165                 $this->registration = $a_status;
00166         }
00167         function enabledParticipation()
00168         {
00169                 return true;
00170         }
00171         function enableParticipation($a_status)
00172         {
00173                 $this->participation = $a_status;
00174         }
00175         
00176 
00177         function &getAppointments()
00178         {
00179                 return $this->appointments ? $this->appointments : array();
00180         }
00181         function addAppointment(&$appointment)
00182         {
00183                 $this->appointments[] =& $appointment;
00184         }
00185         function setAppointments(&$appointments)
00186         {
00187                 $this->appointments =& $appointments;
00188         }
00189         function &getFirstAppointment()
00190         {
00191                 return is_object($this->appointments[0]) ? $this->appointments[0] : ($this->appointments[0] =& new ilEventAppointment());
00192         }
00193 
00194         function validate()
00195         {
00196                 if(!strlen($this->getTitle()))
00197                 {
00198                         $this->ilErr->appendMessage($this->lng->txt('fill_out_all_required_fields'));
00199                         return false;
00200                 }
00201                 return true;
00202         }
00203 
00204         function getFiles()
00205         {
00206                 return $this->files ? $this->files : array();
00207         }
00208         
00219         public static function _cloneEvent($a_source_id,$a_target_id,$a_copy_id)
00220         {
00221                 include_once('Modules/Course/classes/Event/class.ilEventItems.php');
00222                 
00223                 include_once('Services/Tracking/classes/class.ilLPEventCollections.php');
00224                 $old_event_collection = new ilLPEventCollections($a_source_id);
00225                 $new_event_collection = new ilLPEventCollections($a_target_id);
00226                 
00227                 foreach(ilEvent::_getEvents($a_source_id) as $event_obj)
00228                 {
00229                         $new_event = new ilEvent();
00230                         $new_event->setObjId($a_target_id);
00231                         $new_event->setTitle($event_obj->getTitle());
00232                         $new_event->setDescription($event_obj->getDescription());
00233                         $new_event->setLocation($event_obj->getLocation());
00234                         $new_event->setName($event_obj->getName());
00235                         $new_event->setPhone($event_obj->getPhone());
00236                         $new_event->setEmail($event_obj->getEmail());
00237                         $new_event->setDetails($event_obj->getDetails());
00238                         $new_event->enableRegistration($event_obj->enabledRegistration());
00239                         $new_event->enableParticipation($event_obj->enabledParticipation());
00240                         $new_event->create();
00241                         
00242                         // Copy appointments
00243                         foreach($event_obj->getAppointments() as $app_obj)
00244                         {
00245                                 $new_app = new ilEventAppointment();
00246                                 $new_app->setEventId($new_event->getEventId());
00247                                 $new_app->setStartingTime($app_obj->getStartingTime());
00248                                 $new_app->setEndingTime($app_obj->getEndingTime());
00249                                 $new_app->toggleFullTime($app_obj->enabledFullTime());
00250                                 $new_app->create();
00251                         }
00252                         // Copy files
00253                         foreach($event_obj->getFiles() as $file_obj)
00254                         {
00255                                 $file_obj->cloneFiles($new_event->getEventId());
00256                         }
00257                         
00258                         // Copy lp collections
00259                         if($old_event_collection->isAssigned($event_obj->getEventId()))
00260                         {
00261                                 $new_event_collection->add($new_event->getEventId());
00262                         }
00263                         
00264                         // Copy assigned materials
00265                         $new_event_items = new ilEventItems($new_event->getEventId());
00266                         $new_event_items->cloneItems($event_obj->getEventId(),$a_copy_id);
00267                 }
00268         }
00269 
00270         function create()
00271         {
00272                 global $ilDB;
00273                 
00274                 $query = "INSERT INTO event SET ".
00275                         "obj_id = ".$ilDB->quote($this->getObjId()).", ".
00276                         "title = ".$ilDB->quote($this->getTitle()).", ".
00277                         "description = ".$ilDB->quote($this->getDescription()).", ".
00278                         "location = ".$ilDB->quote($this->getLocation()).",".
00279                         #"tutor_firstname = '".ilUtil::prepareDBString($this->getFirstname())."', ".
00280                         #"tutor_lastname = '".ilUtil::prepareDBString($this->getLastname())."', ".
00281                         "tutor_name = ".$ilDB->quote($this->getName()).", ".
00282                         #"tutor_title = '".ilUtil::prepareDBString($this->getPTitle())."', ".
00283                         "tutor_phone = ".$ilDB->quote($this->getPhone()).", ".
00284                         "tutor_email = ".$ilDB->quote($this->getEmail()).", ".
00285                         "details = ".$ilDB->quote($this->getDetails()).",".
00286                         "registration = ".$ilDB->quote($this->enabledRegistration()).", ".
00287                         "participation = ".$ilDB->quote($this->enabledParticipation())."";
00288 
00289                 $this->db->query($query);
00290                 $this->setEventId($this->db->getLastInsertId());
00291 
00292                 return $this->getEventId();
00293         }
00294 
00295         function update()
00296         {
00297                 global $ilDB;
00298                 
00299                 if(!$this->event_id)
00300                 {
00301                         return false;
00302                 }
00303 
00304                 $query = "UPDATE event SET ".
00305                         "title = ".$ilDB->quote($this->getTitle()).", ".
00306                         "description = ".$ilDB->quote($this->getDescription()).", ".
00307                         "location = ".$ilDB->quote($this->getLocation()).",".
00308                         #"tutor_firstname = '".ilUtil::prepareDBString($this->getFirstname())."', ".
00309                         "tutor_name = ".$ilDB->quote($this->getName()).", ".
00310                         #"tutor_title = '".ilUtil::prepareDBString($this->getPTitle())."', ".
00311                         "tutor_phone = ".$ilDB->quote($this->getPhone()).", ".
00312                         "tutor_email = ".$ilDB->quote($this->getEmail()).", ".
00313                         "details = ".$ilDB->quote($this->getDetails()).", ".
00314                         "registration = ".$ilDB->quote($this->enabledRegistration()).", ".
00315                         "participation = ".$ilDB->quote($this->enabledParticipation())." ".
00316                         "WHERE event_id = ".$ilDB->quote($this->getEventId())." ";
00317 
00318                 $this->db->query($query);
00319                 return true;
00320         }
00321 
00322         function delete()
00323         {
00324                 ilEvent::_delete($this->getEventId());
00325                 return true;
00326         }
00327 
00328         function readFiles()
00329         {
00330                 $this->files = ilEventFile::_readFilesByEvent($this->getEventId());
00331         }
00332 
00333         function hasTutorSettings()
00334         {
00335                 return strlen($this->getFullname()) or 
00336                         strlen($this->getEmail()) or
00337                         strlen($this->getPhone());
00338         }
00339 
00340         function getFullname()
00341         {
00342                 return $this->getName();
00343         }
00344 
00345         function _delete($a_event_id)
00346         {
00347                 global $ilDB;
00348 
00349                 $query = "DELETE FROM event WHERE event_id = ".$ilDB->quote($a_event_id)." ";
00350                 $ilDB->query($query);
00351 
00352                 ilEventAppointment::_deleteByEvent($a_event_id);
00353                 ilEventFile::_deleteByEvent($a_event_id);
00354                 
00355                 include_once 'Modules/Course/classes/Event/class.ilEventItems.php';
00356                 ilEventItems::_delete($a_event_id);
00357 
00358                 include_once 'Modules/Course/classes/Event/class.ilEventParticipants.php';
00359                 ilEventParticipants::_deleteByEvent($a_event_id);
00360 
00361                 return true;
00362         }
00363         
00364         function _deleteAll($a_obj_id)
00365         {
00366                 global $ilDB;
00367 
00368                 $query = "SELECT * FROM event ".
00369                         "WHERE obj_id = ".$ilDB->quote($a_obj_id)." ";
00370                 $res = $ilDB->query($query);
00371                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00372                 {
00373                         ilEvent::_delete($row->event_id);
00374                 }
00375                 return true;
00376         }
00377 
00378         function _exists($a_event_id)
00379         {
00380                 global $ilDB;
00381 
00382                 $query = "SELECT * FROM event WHERE event_id = ".$ilDB->quote($a_event_id)." ";
00383                 $res = $ilDB->query($query);
00384                 return $res->numRows() ? true : false;
00385         }
00386 
00387         function _lookupCourseId($a_event_id)
00388         {
00389                 global $ilDB;
00390 
00391                 $query = "SELECT * FROM event WHERE event_id = ".$ilDB->quote($a_event_id)."";
00392                 $res = $ilDB->query($query);
00393                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00394                 {
00395                         return $row->obj_id;
00396                 }
00397                 return false;
00398         }
00399 
00400         function &_getEvents($a_obj_id)
00401         {
00402                 global $ilDB;
00403 
00404                 $query = "SELECT * FROM event ".
00405                         "JOIN event_appointment ON event.event_id = event_appointment.event_id ".
00406                         "WHERE event.obj_id = ".$ilDB->quote($a_obj_id)." ".
00407                         "ORDER BY starting_time";
00408 
00409                 $res = $ilDB->query($query);
00410                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00411                 {
00412                         $events[] =& new ilEvent($row->event_id);
00413                 }
00414                 return $events ? $events : array();
00415         }
00416 
00417         function &_getEventsAsArray($a_obj_id)
00418         {
00419                 foreach(ilEvent::_getEvents($a_obj_id) as $event_obj)
00420                 {
00421                         $item[$event_obj->getEventId()]['title'] = $event_obj->getTitle();
00422                         $item[$event_obj->getEventId()]['description'] = $event_obj->getDescription();
00423                         $item[$event_obj->getEventId()]['type'] = 'event';
00424                         $item[$event_obj->getEventId()]['event_id'] = $event_obj->getEventId();
00425 
00426                         $event_appointment =& $event_obj->getFirstAppointment();
00427                         $item[$event_obj->getEventId()]['start'] = $event_appointment->getStartingTime();
00428                         $item[$event_obj->getEventId()]['end'] = $event_appointment->getEndingTime();
00429                         $item[$event_obj->getEventId()]['fulltime'] = $event_appointment->enabledFullTime();
00430                 }
00431 
00432                 return $item ? $item : array();
00433         }
00434 
00435         // PRIVATE
00436         function __read()
00437         {
00438                 global $ilDB;
00439                 
00440                 if(!$this->event_id)
00441                 {
00442                         return true;
00443                 }
00444 
00445                 // read event data
00446                 $query = "SELECT * FROM event WHERE event_id = ".$ilDB->quote($this->event_id)." ";
00447                 $res = $this->db->query($query);
00448                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00449                 {
00450                         $this->setObjId($row->obj_id);
00451                         $this->setTitle($row->title);
00452                         $this->setDescription($row->description);
00453                         $this->setLocation($row->location);
00454                         
00455                         #$this->setPTitle($row->tutor_title);
00456                         #$this->setFirstname($row->tutor_firstname);
00457                         $this->setName($row->tutor_name);
00458                         $this->setPhone($row->tutor_phone);
00459                         $this->setEmail($row->tutor_email);
00460                         $this->setDetails($row->details);
00461                         $this->enableRegistration($row->registration);
00462                         $this->enableParticipation($row->participation);
00463                 }
00464 
00465                 // get assigned appointments
00466                 $this->appointments =& ilEventAppointment::_readAppointmentsByEvent($this->event_id);
00467 
00468                 // get assigned files
00469                 $this->readFiles();
00470 
00471                 return true;
00472         }
00473                 
00474 }
00475 ?>

Generated on Fri Dec 13 2013 17:56:49 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1