4 * Event Calendar for Elxis CMS 2008.x and 2009.x
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
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')) {
21 if ($_VERSION->RELEASE
> 2008) {
22 define('EVCALBASE', 'events');
24 define('EVCALBASE', 'com_eventcalendar');
28 /*********************************************************/
29 /* THE CLASS THAT WILL CONTAIN THE EVENT FUNCTIONALITY */
30 /*********************************************************/
31 class mosEventCalendar_Event
extends mosDBTable
{
52 public $checked_out = '0';
53 public $checked_out_time = '1979-12-19 00:00:00';
55 public $pp_price = '';
57 public $category; // Extended fields not in eventcalendar-database
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 ) {
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 ) {
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;
127 $ret = $this->_db
->updateObject( $this->_tbl
, $this, $this->_tbl_key
, $updateNulls );
129 $ret = $this->_db
->insertObject( $this->_tbl
, $this, $this->_tbl_key
);
132 $this->_error
= strtolower( get_class( $this ) ) . '::store failed <br />' . $this->_db
->getErrorMsg();
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='' ) {
146 if (!is_array( $array )) {
147 $this->_error
= strtolower(get_class( $this ))."::bind failed.";
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 );