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

Modules/Course/classes/Event/class.ilEventAppointment.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 class ilEventAppointment
00036 {
00037         var $ilErr;
00038         var $ilDB;
00039         var $tree;
00040         var $lng;
00041 
00042         var $starting_time = null;
00043         var $ending_time = null;
00044 
00045         function ilEventAppointment($a_appointment_id = null)
00046         {
00047                 global $ilErr,$ilDB,$lng,$tree;
00048 
00049                 $this->ilErr =& $ilErr;
00050                 $this->db  =& $ilDB;
00051                 $this->lng =& $lng;
00052 
00053                 $this->appointment_id = $a_appointment_id;
00054                 $this->__read();
00055         }
00056 
00057         function setAppointmentId($a_appointment_id)
00058         {
00059                 $this->appointment_id = $a_appointment_id;
00060         }
00061         function getAppointmentId()
00062         {
00063                 return $this->appointment_id;
00064         }
00065 
00066         function setEventId($a_event_id)
00067         {
00068                 $this->event_id = $a_event_id;
00069         }
00070         function getEventId()
00071         {
00072                 return $this->event_id;
00073         }
00074 
00075         function setStartingTime($a_starting_time)
00076         {
00077                 $this->starting_time = $a_starting_time;
00078         }
00079         function getStartingTime()
00080         {
00081                 return isset($this->starting_time) ? $this->starting_time : mktime(8,0,0,date('n',time()),date('d',time()),date('Y',time()));
00082         }
00083         
00084         function setEndingTime($a_ending_time)
00085         {
00086                 $this->ending_time = $a_ending_time;
00087         }
00088         function getEndingTime()
00089         {
00090                 return isset($this->ending_time) ? $this->ending_time : mktime(16,0,0,date('n',time()),date('d',time()),date('Y',time()));
00091         }
00092 
00093         function toggleFullTime($a_status)
00094         {
00095                 $this->fulltime = $a_status;
00096         }
00097         function enabledFullTime()
00098         {
00099                 return $this->fulltime;
00100         }
00101 
00102         function formatTime()
00103         {
00104                 return ilEventAppointment::_timeToString($this->getStartingTime(),$this->getEndingTime());
00105         }
00106 
00107         function _timeToString($start,$end)
00108         {
00109                 $start = date($this->lng->txt('lang_timeformat_no_sec'),$start);
00110                 $end = date($this->lng->txt('lang_timeformat_no_sec'),$end);
00111         
00112                 return $start.' - '. $end;
00113         }
00114 
00115         function _appointmentToString($start,$end,$fulltime)
00116         {
00117                 global $lng;
00118 
00119                 $start_day = date('j',$start);
00120                 $start_month = date('n',$start);
00121                 $start_year = date('Y',$start);
00122 
00123                 $end_day = date('j',$end);
00124                 $end_month = date('n',$end);
00125                 $end_year = date('Y',$end);
00126 
00127                 if($start_day == $end_day and
00128                    $start_month == $end_month and
00129                    $start_year == $end_year)
00130                 {
00131                         $date_time = ilFormat::formatUnixTime($start,false);
00132                         if(!$fulltime)
00133                         {
00134                                 $date_time .= (' '.ilEventAppointment::_timeToString($start,$end));
00135                         }
00136                         else
00137                         {
00138                                 $date_time .= (' ('.$lng->txt('event_full_time_info').')');
00139                         }
00140                 }
00141                 else
00142                 {
00143                         if(!$fulltime)
00144                         {
00145                                 $date_time = ilFormat::formatUnixTime($start,true) . ' - '.
00146                                         ilFormat::formatUnixTime($end,true);
00147                         }
00148                         else
00149                         {
00150                                 $date_time = ilFormat::formatUnixTime($start,false) . ' - '.
00151                                         ilFormat::formatUnixTime($end,false);
00152                                 $date_time .= (' ('.$lng->txt('event_full_time_info').')');
00153                         }
00154                 }
00155                 return $date_time;
00156         }
00157         function appointmentToString()
00158         {
00159                 return ilEventAppointment::_appointmentToString($this->getStartingTime(),$this->getEndingTime(),$this->enabledFullTime());
00160         }
00161 
00162         function create()
00163         {
00164                 global $ilDB;
00165                 
00166                 if(!$this->getEventId())
00167                 {
00168                         return false;
00169                 }
00170                 $query = "INSERT INTO event_appointment ".
00171                         "SET event_id = ".$ilDB->quote($this->getEventId()).", ".
00172                         "starting_time = ".$ilDB->quote($this->getStartingTime()).", ".
00173                         "ending_time = ".$ilDB->quote($this->getEndingTime()).", ".
00174                         "fulltime = ".$ilDB->quote($this->enabledFullTime())." ";
00175 
00176                 $this->db->query($query);
00177                 return true;
00178         }
00179 
00180         function update()
00181         {
00182                 global $ilDB;
00183                 
00184                 if(!$this->getEventId())
00185                 {
00186                         return false;
00187                 }
00188                 $query = "UPDATE event_appointment ".
00189                         "SET event_id = ".$ilDB->quote($this->getEventId()).", ".
00190                         "starting_time = ".$ilDB->quote($this->getStartingTime()).", ".
00191                         "ending_time = ".$ilDB->quote($this->getEndingTime()).", ".
00192                         "fulltime = ".$ilDB->quote($this->enabledFullTime())." ".
00193                         "WHERE appointment_id = ".$ilDB->quote($this->getAppointmentId())." ";
00194 
00195                 $this->db->query($query);
00196                 return true;
00197         }
00198 
00199         function delete()
00200         {
00201                 return ilEventAppointment::_delete($this->getAppointmentId());
00202         }
00203 
00204         function _delete($a_appointment_id)
00205         {
00206                 global $ilDB;
00207 
00208                 $query = "DELETE FROM event_appointment ".
00209                         "WHERE appointment_id = ".$ilDB->quote($a_appointment_id)." ";
00210                 $this->db->query($query);
00211 
00212                 return true;
00213         }
00214 
00215         function _deleteByEvent($a_event_id)
00216         {
00217                 global $ilDB;
00218 
00219                 $query = "DELETE FROM event_appointment ".
00220                         "WHERE event_id = ".$ilDB->quote($a_event_id)." ";
00221                 $ilDB->query($query);
00222 
00223                 return true;
00224         }
00225 
00226         function &_readAppointmentsByEvent($a_event_id)
00227         {
00228                 global $ilDB;
00229 
00230                 $query = "SELECT * FROM event_appointment ".
00231                         "WHERE event_id = ".$ilDB->quote($a_event_id)." ".
00232                         "ORDER BY starting_time";
00233 
00234                 $res = $ilDB->query($query);
00235                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00236                 {
00237                         $appointments[] =& new ilEventAppointment($row->appointment_id);
00238                 }
00239                 return is_array($appointments) ? $appointments : array();
00240         }
00241                         
00242         function validate()
00243         {
00244                 if($this->starting_time > $this->ending_time)
00245                 {
00246                         $this->ilErr->appendMessage($this->lng->txt('event_etime_smaller_stime'));
00247                         return false;
00248                 }
00249                 return true;
00250         }
00251 
00252         // PRIVATE
00253         function __read()
00254         {
00255                 global $ilDB;
00256                 
00257                 if(!$this->getAppointmentId())
00258                 {
00259                         return null;
00260                 }
00261 
00262                 $query = "SELECT * FROM event_appointment ".
00263                         "WHERE appointment_id = ".$ilDB->quote($this->getAppointmentId())." ";
00264                 $res = $this->db->query($query);
00265                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00266                 {
00267                         $this->setEventId($row->event_id);
00268                         $this->setStartingTime($row->starting_time);
00269                         $this->setEndingTime($row->ending_time);
00270                         $this->toggleFullTime($row->fulltime);
00271                 }
00272                 return true;
00273         }
00274 
00275 }
00276 ?>

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