| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 4 * @license GNU General Public License version 2 or later; see LICENSE.txt 5 */ 6 7 // No direct access. 8 defined('_JEXEC') or die; 9 10 /** 11 * Banner table 12 * 13 * @package Joomla.Administrator 14 * @subpackage com_banners 15 * @since 1.5 16 */ 17 class BannersTableBanner extends JTable 18 { 19 /** 20 * Constructor 21 * 22 * @since 1.5 23 */ 24 function __construct(&$_db) 25 { 26 parent::__construct('#__banners', 'id', $_db); 27 $date = JFactory::getDate(); 28 $this->created = $date->toSql(); 29 } 30 31 function clicks() 32 { 33 $query = 'UPDATE #__banners' 34 . ' SET clicks = (clicks + 1)' 35 . ' WHERE id = ' . (int) $this->id 36 ; 37 $this->_db->setQuery($query); 38 $this->_db->query(); 39 } 40 41 /** 42 * Overloaded check function 43 * 44 * @return boolean 45 * @see JTable::check 46 * @since 1.5 47 */ 48 function check() 49 { 50 // Set name 51 $this->name = htmlspecialchars_decode($this->name, ENT_QUOTES); 52 53 // Set alias 54 $this->alias = JApplication::stringURLSafe($this->alias); 55 if (empty($this->alias)) { 56 $this->alias = JApplication::stringURLSafe($this->name); 57 } 58 59 // Check the publish down date is not earlier than publish up. 60 if ($this->publish_down > $this->_db->getNullDate() && $this->publish_down < $this->publish_up) { 61 $this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH')); 62 return false; 63 } 64 65 // Set ordering 66 if ($this->state < 0) { 67 // Set ordering to 0 if state is archived or trashed 68 $this->ordering = 0; 69 } elseif (empty($this->ordering)) { 70 // Set ordering to last if ordering was 0 71 $this->ordering = self::getNextOrder($this->_db->quoteName('catid').'=' . $this->_db->Quote($this->catid).' AND state>=0'); 72 } 73 74 return true; 75 } 76 /** 77 * Overloaded bind function 78 * 79 * @param array $hash named array 80 * @return null|string null is operation was satisfactory, otherwise returns an error 81 * @see JTable:bind 82 * @since 1.5 83 */ 84 public function bind($array, $ignore = array()) 85 { 86 if (isset($array['params']) && is_array($array['params'])) { 87 $registry = new JRegistry(); 88 $registry->loadArray($array['params']); 89 90 if((int) $registry->get('width', 0) < 0){ 91 $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_NEGATIVE_NOT_PERMITTED', JText::_('COM_BANNERS_FIELD_WIDTH_LABEL'))); 92 return false; 93 } 94 95 if((int) $registry->get('height', 0) < 0){ 96 $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_NEGATIVE_NOT_PERMITTED', JText::_('COM_BANNERS_FIELD_HEIGHT_LABEL'))); 97 return false; 98 } 99 100 // Converts the width and height to an absolute numeric value: 101 $width = abs((int) $registry->get('width', 0)); 102 $height = abs((int) $registry->get('height', 0)); 103 104 // Sets the width and height to an empty string if = 0 105 $registry->set('width', ($width ? $width : '')); 106 $registry->set('height', ($height ? $height : '')); 107 108 $array['params'] = (string)$registry; 109 } 110 111 if (isset($array['imptotal'])) { 112 $array['imptotal'] = abs((int) $array['imptotal']); 113 } 114 115 return parent::bind($array, $ignore); 116 } 117 /** 118 * method to store a row 119 * 120 * @param boolean $updateNulls True to update fields even if they are null. 121 */ 122 function store($updateNulls = false) 123 { 124 if (empty($this->id)) 125 { 126 $purchase_type = $this->purchase_type; 127 if ($purchase_type < 0 && $this->cid) 128 { 129 $client = JTable::getInstance('Client', 'BannersTable'); 130 $client->load($this->cid); 131 $purchase_type = $client->purchase_type; 132 } 133 if ($purchase_type < 0) 134 { 135 $params = JComponentHelper::getParams('com_banners'); 136 $purchase_type = $params->get('purchase_type'); 137 } 138 139 switch($purchase_type) 140 { 141 case 1: 142 $this->reset=$this->_db->getNullDate(); 143 break; 144 case 2: 145 $date = JFactory::getDate('+1 year '.date('Y-m-d', strtotime('now'))); 146 $reset = $this->_db->Quote($date->toSql()); 147 break; 148 case 3: 149 $date = JFactory::getDate('+1 month '.date('Y-m-d', strtotime('now'))); 150 $reset = $this->_db->Quote($date->toSql()); 151 break; 152 case 4: 153 $date = JFactory::getDate('+7 day '.date('Y-m-d', strtotime('now'))); 154 $reset = $this->_db->Quote($date->toSql()); 155 break; 156 case 5: 157 $date = JFactory::getDate('+1 day '.date('Y-m-d', strtotime('now'))); 158 $reset = $this->_db->Quote($date->toSql()); 159 break; 160 } 161 // Store the row 162 parent::store($updateNulls); 163 } 164 else 165 { 166 // Get the old row 167 $oldrow = JTable::getInstance('Banner', 'BannersTable'); 168 if (!$oldrow->load($this->id) && $oldrow->getError()) 169 { 170 $this->setError($oldrow->getError()); 171 } 172 173 // Verify that the alias is unique 174 $table = JTable::getInstance('Banner', 'BannersTable'); 175 if ($table->load(array('alias'=>$this->alias, 'catid'=>$this->catid)) && ($table->id != $this->id || $this->id==0)) { 176 $this->setError(JText::_('COM_BANNERS_ERROR_UNIQUE_ALIAS')); 177 return false; 178 } 179 180 // Store the new row 181 parent::store($updateNulls); 182 183 // Need to reorder ? 184 if ($oldrow->state>=0 && ($this->state < 0 || $oldrow->catid != $this->catid)) 185 { 186 // Reorder the oldrow 187 $this->reorder($this->_db->quoteName('catid').'=' . $this->_db->Quote($oldrow->catid).' AND state>=0'); 188 } 189 } 190 return count($this->getErrors())==0; 191 } 192 193 /** 194 * Method to set the publishing state for a row or list of rows in the database 195 * table. The method respects checked out rows by other users and will attempt 196 * to checkin rows that it can after adjustments are made. 197 * 198 * @param mixed An optional array of primary key values to update. If not 199 * set the instance property value is used. 200 * @param integer The publishing state. eg. [0 = unpublished, 1 = published, 2=archived, -2=trashed] 201 * @param integer The user id of the user performing the operation. 202 * @return boolean True on success. 203 * @since 1.6 204 */ 205 public function publish($pks = null, $state = 1, $userId = 0) 206 { 207 // Initialise variables. 208 $k = $this->_tbl_key; 209 210 // Sanitize input. 211 JArrayHelper::toInteger($pks); 212 $userId = (int) $userId; 213 $state = (int) $state; 214 215 // If there are no primary keys set check to see if the instance key is set. 216 if (empty($pks)) 217 { 218 if ($this->$k) { 219 $pks = array($this->$k); 220 } 221 // Nothing to set publishing state on, return false. 222 else { 223 $this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED')); 224 return false; 225 } 226 } 227 228 // Get an instance of the table 229 $table = JTable::getInstance('Banner', 'BannersTable'); 230 231 // For all keys 232 foreach ($pks as $pk) 233 { 234 // Load the banner 235 if(!$table->load($pk)) 236 { 237 $this->setError($table->getError()); 238 } 239 240 // Verify checkout 241 if($table->checked_out==0 || $table->checked_out==$userId) 242 { 243 // Change the state 244 $table->state = $state; 245 $table->checked_out=0; 246 $table->checked_out_time=$this->_db->getNullDate(); 247 248 // Check the row 249 $table->check(); 250 251 // Store the row 252 if (!$table->store()) 253 { 254 $this->setError($table->getError()); 255 } 256 } 257 } 258 return count($this->getErrors())==0; 259 } 260 /** 261 * Method to set the sticky state for a row or list of rows in the database 262 * table. The method respects checked out rows by other users and will attempt 263 * to checkin rows that it can after adjustments are made. 264 * 265 * @param mixed An optional array of primary key values to update. If not 266 * set the instance property value is used. 267 * @param integer The sticky state. eg. [0 = unsticked, 1 = sticked] 268 * @param integer The user id of the user performing the operation. 269 * @return boolean True on success. 270 * @since 1.6 271 */ 272 public function stick($pks = null, $state = 1, $userId = 0) 273 { 274 // Initialise variables. 275 $k = $this->_tbl_key; 276 277 // Sanitize input. 278 JArrayHelper::toInteger($pks); 279 $userId = (int) $userId; 280 $state = (int) $state; 281 282 // If there are no primary keys set check to see if the instance key is set. 283 if (empty($pks)) 284 { 285 if ($this->$k) { 286 $pks = array($this->$k); 287 } 288 // Nothing to set publishing state on, return false. 289 else { 290 $this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED')); 291 return false; 292 } 293 } 294 295 // Get an instance of the table 296 $table = JTable::getInstance('Banner', 'BannersTable'); 297 298 // For all keys 299 foreach ($pks as $pk) 300 { 301 // Load the banner 302 if(!$table->load($pk)) 303 { 304 $this->setError($table->getError()); 305 } 306 307 // Verify checkout 308 if($table->checked_out==0 || $table->checked_out==$userId) 309 { 310 // Change the state 311 $table->sticky = $state; 312 $table->checked_out=0; 313 $table->checked_out_time=$this->_db->getNullDate(); 314 315 // Check the row 316 $table->check(); 317 318 // Store the row 319 if (!$table->store()) 320 { 321 $this->setError($table->getError()); 322 } 323 } 324 } 325 return count($this->getErrors())==0; 326 } 327 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |