On branch master
[event_calendar.git] / eventcalendar.class.php
blob0985cfaa17d993c9284443ca79d923d73e18764a
1 <?php
3 /*
4 * Event Calendar for Elxis CMS 2008.x and 2009.x
6 * Event handler
8 * @version 1.1
9 * @package eventCalendar
10 * @author Apostolos Koutsoulelos <akoutsoulelos@yahoo.gr>
11 * @copyright Copyright (C) 2009-2010 Apostolos Koutsoulelos. All rights reserved.
12 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
13 * @link
16 // Prevent direct inclusion of this file
17 defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
19 if (!defined('EVCALBASE')) {
20 global $_VERSION;
21 if ($_VERSION->RELEASE > 2008) {
22 define('EVCALBASE', 'events');
23 } else {
24 define('EVCALBASE', 'com_eventcalendar');
28 /*********************************************************/
29 /* THE CLASS THAT WILL CONTAIN THE EVENT FUNCTIONALITY */
30 /*********************************************************/
31 class mosEventCalendar_Event extends mosDBTable {
33 // Declare variables
34 public $id;
35 public $title;
36 public $seotitle;
37 public $language;
38 public $description;
39 public $contact;
40 public $url;
41 public $email;
42 public $catid;
43 public $published;
44 public $start_date;
45 public $end_date;
46 public $recur_type;
47 public $recur_week;
48 public $recur_month;
49 public $recur_year_d;
50 public $recur_year_m;
51 public $recur_except;
52 public $checked_out = '0';
53 public $checked_out_time = '1979-12-19 00:00:00';
54 public $rsv = '';
55 public $pp_price = '';
57 public $category; // Extended fields not in eventcalendar-database
58 public $cat_params;
60 /*****************/
61 /* Constructor */
62 /*****************/
63 public function __construct($database) {
64 $this->mosDBTable( '#__eventcalendar', 'id', $database);
67 /******************************************************/
68 /* Implement load function to have additional stuff */
69 /* like category and color loaded as well as type */
70 /******************************************************/
71 function load( $oid = null ) {
73 $k = $this->_tbl_key;
74 if ($oid !== null) {
75 $this->$k = $oid;
78 $oid = $this->$k;
79 if ($oid === null) {
80 return false;
83 $class_vars = get_class_vars( get_class( $this ) );
84 foreach ($class_vars as $name => $value) {
85 if (($name != $k) and ($name != "_db") and ($name != "_tbl") and ($name != "_tbl_key")) {
86 $this->$name = $value;
90 $query = "SELECT e.*, c.name AS category, c.params AS cat_params"
91 . "\n FROM $this->_tbl e"
92 . "\n LEFT JOIN #__categories c ON c.id = e.catid"
93 . "\n WHERE e.$this->_tbl_key = $oid";
94 $this->_db->setQuery( $query );
96 return $this->_db->loadObject( $this );
99 /****************************************************/
100 /* Encode the color of a category from its params */
101 /****************************************************/
102 function getColor() {
103 $params = new mosParameters( $this->cat_params );
104 return $params->get( 'color' , '');
107 /*******************************************/
108 /* Implement the database check function */
109 /*******************************************/
110 function check( $error_msg ) {
111 $error_msg = "";
113 return true;
116 /*******************************************/
117 /* Implement the database store function */
118 /*******************************************/
119 function store( $updateNulls=false ) {
120 $k = $this->_tbl_key;
122 //eliminate the unvalid params
123 $this->category = null;
124 $this->cat_params = null;
126 if ($this->$k) {
127 $ret = $this->_db->updateObject( $this->_tbl, $this, $this->_tbl_key, $updateNulls );
128 } else {
129 $ret = $this->_db->insertObject( $this->_tbl, $this, $this->_tbl_key );
131 if( !$ret ) {
132 $this->_error = strtolower( get_class( $this ) ) . '::store failed <br />' . $this->_db->getErrorMsg();
133 return false;
134 } else {
135 return true;
139 /******************************************/
140 /* Implement the database bind function */
141 /******************************************/
142 //de- / encoding of some passed variables as dates to timestamps and arrays to strings is necessary
143 function bind( $array, $ignore='' ) {
144 global $database;
146 if (!is_array( $array )) {
147 $this->_error = strtolower(get_class( $this ))."::bind failed.";
148 return false;
151 // recur_week array to string conversion
152 if (array_key_exists( 'recur_week', $array )) {
153 if (is_array( $array['recur_week'] )) {
154 $array['recur_week'] = implode( $array['recur_week'] );
156 // Conversion to string, otherwise Joomla! will set it to an empty string when only sunday is selected
157 $array['recur_week'] = (string) intval( $array['recur_week'] );
160 // recur exception needs to be imploded for saving as params-string in recur_excepts
161 $recur_except = split( ',', $array['recur_except'] );
162 // if the first item of the array is empty that item has to be deleted
163 if (is_array( $recur_except ) && (count( $recur_except ) >= 1) && $recur_except[0] == '') {
164 array_shift($recur_except);
167 $array['recur_except'] = isset( $recur_except ) ? implode( "\n", $recur_except ) : '';
169 //check if events for this category have to be published by an administrator
170 $category = new mosCategory ( $database );
171 $category->load( $array['catid'] );
172 $parameter = new mosParameters( $category->params );
173 if ($parameter->get( 'autopublish' )) {
174 $array['published'] = '1';
177 return mosBindArrayToObject( $array, $this, $ignore );
180 /***********************************************************/
181 /* Bind this object to an array of a raw database result */
182 /***********************************************************/
183 function bindRaw( $array, $ignore='' ) {
184 return mosBindArrayToObject( $array, $this, $ignore, null, false );