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

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 
00035 include_once 'course/classes/Event/class.ilEventAppointment.php';
00036 include_once 'course/classes/Event/class.ilEventFile.php';
00037 
00038 class ilEvent
00039 {
00040         var $ilErr;
00041         var $ilDB;
00042         var $tree;
00043         var $lng;
00044 
00045         var $event_id = null;
00046         var $appointments = array();
00047 
00048 
00049         function ilEvent($a_event_id)
00050         {
00051                 global $ilErr,$ilDB,$lng,$tree;
00052 
00053                 $this->ilErr =& $ilErr;
00054                 $this->db  =& $ilDB;
00055                 $this->lng =& $lng;
00056 
00057                 $this->event_id = $a_event_id;
00058                 $this->__read();
00059         }
00060 
00061         function setObjId($a_obj_id)
00062         {
00063                 $this->obj_id = $a_obj_id;
00064         }
00065         function getObjId()
00066         {
00067                 return $this->obj_id;
00068         }
00069 
00070         function getEventId()
00071         {
00072                 return $this->event_id;
00073         }
00074         function setEventId($a_event_id)
00075         {
00076                 $this->event_id = $a_event_id;
00077         }
00078         function getTitle()
00079         {
00080                 return $this->title;
00081         }
00082         function setTitle($a_title)
00083         {
00084                 $this->title = $a_title;
00085         }
00086         function getDescription()
00087         {
00088                 return $this->description;
00089         }
00090         function setDescription($a_description)
00091         {
00092                 $this->description = $a_description;
00093         }
00094 
00095         function getLocation()
00096         {
00097                 return $this->location;
00098         }
00099         function setLocation($a_location)
00100         {
00101                 $this->location = $a_location;
00102         }
00103         function setName($a_name)
00104         {
00105                 $this->name = $a_name;
00106         }
00107         function getName()
00108         {
00109                 return $this->name;
00110         }
00111 
00112         function getFirstname()
00113         {
00114                 return $this->firstname;
00115         }
00116         function setFirstname($a_firstname)
00117         {
00118                 $this->firstname = $a_firstname;
00119         }
00120         function getLastname()
00121         {
00122                 return $this->lastname;
00123         }
00124         function setLastname($a_lastname)
00125         {
00126                 $this->lastname = $a_lastname;
00127         }
00128         function getPTitle()
00129         {
00130                 return $this->ptitle;
00131         }
00132         function setPTitle($a_ptitle)
00133         {
00134                 $this->ptitle = $a_ptitle;
00135         }
00136         function getEmail()
00137         {
00138                 return $this->mail;
00139         }
00140         function setEmail($a_mail)
00141         {
00142                 $this->mail = $a_mail;
00143         }
00144         function getPhone()
00145         {
00146                 return $this->phone;
00147         }
00148         function setPhone($a_phone)
00149         {
00150                 $this->phone = $a_phone;
00151         }
00152         function setDetails($a_details)
00153         {
00154                 $this->details = $a_details;
00155         }
00156         function getDetails()
00157         {
00158                 return $this->details;
00159         }
00160         function enabledRegistration()
00161         {
00162                 return (bool) $this->registration;
00163         }
00164         function enableRegistration($a_status)
00165         {
00166                 $this->registration = $a_status;
00167         }
00168         function enabledParticipation()
00169         {
00170                 return true;
00171                 return (bool) $this->participation;
00172         }
00173         function enableParticipation($a_status)
00174         {
00175                 $this->participation = $a_status;
00176         }
00177         
00178 
00179         function &getAppointments()
00180         {
00181                 return $this->appointments ? $this->appointments : array();
00182         }
00183         function addAppointment(&$appointment)
00184         {
00185                 $this->appointments[] =& $appointment;
00186         }
00187         function setAppointments(&$appointments)
00188         {
00189                 $this->appointments =& $appointments;
00190         }
00191         function &getFirstAppointment()
00192         {
00193                 return is_object($this->appointments[0]) ? $this->appointments[0] : ($this->appointments[0] =& new ilEventAppointment());
00194         }
00195 
00196         function validate()
00197         {
00198                 if(!strlen($this->getTitle()))
00199                 {
00200                         $this->ilErr->appendMessage($this->lng->txt('fill_out_all_required_fields'));
00201                         return false;
00202                 }
00203                 return true;
00204         }
00205 
00206         function getFiles()
00207         {
00208                 return $this->files ? $this->files : array();
00209         }
00210 
00211         function create()
00212         {
00213                 $query = "INSERT INTO event SET ".
00214                         "obj_id = '".$this->getObjId()."', ".
00215                         "title = '".ilUtil::prepareDBString($this->getTitle())."', ".
00216                         "description = '".ilUtil::prepareDBString($this->getDescription())."', ".
00217                         "location = '".ilUtil::prepareDBString($this->getLocation())."',".
00218                         #"tutor_firstname = '".ilUtil::prepareDBString($this->getFirstname())."', ".
00219                         #"tutor_lastname = '".ilUtil::prepareDBString($this->getLastname())."', ".
00220                         "tutor_name = '".ilUtil::prepareDBString($this->getName())."', ".
00221                         #"tutor_title = '".ilUtil::prepareDBString($this->getPTitle())."', ".
00222                         "tutor_phone = '".ilUtil::prepareDBString($this->getPhone())."', ".
00223                         "tutor_email = '".ilUtil::prepareDBString($this->getEmail())."', ".
00224                         "details = '".ilUtil::prepareDBString($this->getDetails())."',".
00225                         "registration = '".(int) $this->enabledRegistration()."', ".
00226                         "participation = '".(int) $this->enabledParticipation()."'";
00227 
00228                 $this->db->query($query);
00229                 $this->setEventId($this->db->getLastInsertId());
00230 
00231                 return $this->getEventId();
00232         }
00233 
00234         function update()
00235         {
00236                 if(!$this->event_id)
00237                 {
00238                         return false;
00239                 }
00240 
00241                 $query = "UPDATE event SET ".
00242                         "title = '".ilUtil::prepareDBString($this->getTitle())."', ".
00243                         "description = '".ilUtil::prepareDBString($this->getDescription())."', ".
00244                         "location = '".ilUtil::prepareDBString($this->getLocation())."',".
00245                         #"tutor_firstname = '".ilUtil::prepareDBString($this->getFirstname())."', ".
00246                         "tutor_name = '".ilUtil::prepareDBString($this->getName())."', ".
00247                         #"tutor_title = '".ilUtil::prepareDBString($this->getPTitle())."', ".
00248                         "tutor_phone = '".ilUtil::prepareDBString($this->getPhone())."', ".
00249                         "tutor_email = '".ilUtil::prepareDBString($this->getEmail())."', ".
00250                         "details = '".ilUtil::prepareDBString($this->getDetails())."', ".
00251                         "registration = '".(int) $this->enabledRegistration()."', ".
00252                         "participation = '".(int) $this->enabledParticipation()."' ".
00253                         "WHERE event_id = '".$this->getEventId()."'";
00254 
00255                 $this->db->query($query);
00256                 return true;
00257         }
00258 
00259         function delete()
00260         {
00261                 ilEvent::_delete($this->getEventId());
00262                 return true;
00263         }
00264 
00265         function readFiles()
00266         {
00267                 $this->files = ilEventFile::_readFilesByEvent($this->getEventId());
00268         }
00269 
00270         function hasTutorSettings()
00271         {
00272                 return strlen($this->getFullname()) or 
00273                         strlen($this->getEmail()) or
00274                         strlen($this->getPhone());
00275         }
00276 
00277         function getFullname()
00278         {
00279                 return $this->getName();
00280 
00281                 if(strlen($this->getPTitle()) or strlen($this->getFirstname()) or strlen($this->getLastname()))
00282                 {
00283                         return $this->getPTitle().' '.$this->getFirstname().' '.$this->getLastname();
00284                 }
00285                 return '';
00286         }
00287 
00288         function _delete($a_event_id)
00289         {
00290                 global $ilDB;
00291 
00292                 $query = "DELETE FROM event WHERE event_id = '".$a_event_id."'";
00293                 $ilDB->query($query);
00294 
00295                 ilEventAppointment::_deleteByEvent($a_event_id);
00296                 ilEventFile::_deleteByEvent($a_event_id);
00297                 
00298                 include_once 'course/classes/Event/class.ilEventItems.php';
00299                 ilEventItems::_delete($a_event_id);
00300 
00301                 include_once 'course/classes/Event/class.ilEventParticipants.php';
00302                 ilEventParticipants::_deleteByEvent($a_event_id);
00303 
00304                 return true;
00305         }
00306         
00307         function _deleteAll($a_obj_id)
00308         {
00309                 global $ilDB;
00310 
00311                 $query = "SELECT * FROM event ".
00312                         "WHERE obj_id = '".$a_obj_id."'";
00313                 $res = $ilDB->query($query);
00314                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00315                 {
00316                         ilEvent::_delete($row->event_id);
00317                 }
00318                 return true;
00319         }
00320 
00321         function _exists($a_event_id)
00322         {
00323                 global $ilDB;
00324 
00325                 $query = "SELECT * FROM event WHERE event_id = '".$a_event_id."'";
00326                 $res = $ilDB->query($query);
00327                 return $res->numRows() ? true : false;
00328         }
00329 
00330         function _lookupCourseId()
00331         {
00332                 global $ilDB;
00333 
00334                 $query = "SELECT * FROM event WHERE event_id = '".$a_event_id."'";
00335                 $res = $ilDB->query($query);
00336                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00337                 {
00338                         return $row->obj_id;
00339                 }
00340                 return false;
00341         }
00342 
00343         function &_getEvents($a_obj_id)
00344         {
00345                 global $ilDB;
00346 
00347                 $query = "SELECT * FROM event ".
00348                         "JOIN event_appointment ON event.event_id = event_appointment.event_id ".
00349                         "WHERE event.obj_id = '".$a_obj_id."' ".
00350                         "ORDER BY starting_time";
00351 
00352                 $res = $ilDB->query($query);
00353                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00354                 {
00355                         $events[] =& new ilEvent($row->event_id);
00356                 }
00357                 return $events ? $events : array();
00358         }
00359 
00360         function &_getEventsAsArray($a_obj_id)
00361         {
00362                 foreach(ilEvent::_getEvents($a_obj_id) as $event_obj)
00363                 {
00364                         $item[$event_obj->getEventId()]['title'] = $event_obj->getTitle();
00365                         $item[$event_obj->getEventId()]['description'] = $event_obj->getDescription();
00366                         $item[$event_obj->getEventId()]['type'] = 'event';
00367                         $item[$event_obj->getEventId()]['event_id'] = $event_obj->getEventId();
00368 
00369                         $event_appointment =& $event_obj->getFirstAppointment();
00370                         $item[$event_obj->getEventId()]['start'] = $event_appointment->getStartingTime();
00371                         $item[$event_obj->getEventId()]['end'] = $event_appointment->getEndingTime();
00372                         $item[$event_obj->getEventId()]['fulltime'] = $event_appointment->enabledFullTime();
00373                 }
00374 
00375                 return $item ? $item : array();
00376         }
00377 
00378         // PRIVATE
00379         function __read()
00380         {
00381                 if(!$this->event_id)
00382                 {
00383                         return true;
00384                 }
00385 
00386                 // read event data
00387                 $query = "SELECT * FROM event WHERE event_id = '".$this->event_id."'";
00388                 $res = $this->db->query($query);
00389                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00390                 {
00391                         $this->setObjId($row->obj_id);
00392                         $this->setTitle($row->title);
00393                         $this->setDescription($row->description);
00394                         $this->setLocation($row->location);
00395                         
00396                         #$this->setPTitle($row->tutor_title);
00397                         #$this->setFirstname($row->tutor_firstname);
00398                         $this->setName($row->tutor_name);
00399                         $this->setPhone($row->tutor_phone);
00400                         $this->setEmail($row->tutor_email);
00401                         $this->setDetails($row->details);
00402                         $this->enableRegistration($row->registration);
00403                         $this->enableParticipation($row->participation);
00404                 }
00405 
00406                 // get assigned appointments
00407                 $this->appointments =& ilEventAppointment::_readAppointmentsByEvent($this->event_id);
00408 
00409                 // get assigned files
00410                 $this->readFiles();
00411 
00412                 return true;
00413         }
00414                 
00415 }
00416 ?>

Generated on Fri Dec 13 2013 13:52:10 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1