| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: weblink.php 14401 2010-01-26 14:10:00Z louis $ 4 * @package Joomla 5 * @subpackage Content 6 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 7 * @license GNU/GPL, see LICENSE.php 8 * Joomla! is free software. This version may have been modified pursuant to the 9 * GNU General Public License, and as distributed it includes or is derivative 10 * of works licensed under the GNU General Public License or other free or open 11 * source software licenses. See COPYRIGHT.php for copyright notices and 12 * details. 13 */ 14 15 // Check to ensure this file is included in Joomla! 16 defined('_JEXEC') or die( 'Restricted access' ); 17 18 jimport('joomla.application.component.model'); 19 20 /** 21 * Weblinks Component Weblink Model 22 * 23 * @package Joomla 24 * @subpackage Weblinks 25 * @since 1.5 26 */ 27 class WeblinksModelWeblink extends JModel 28 { 29 /** 30 * Weblink id 31 * 32 * @var int 33 */ 34 var $_id = null; 35 36 /** 37 * Weblink data 38 * 39 * @var array 40 */ 41 var $_data = null; 42 43 /** 44 * Constructor 45 * 46 * @since 1.5 47 */ 48 function __construct() 49 { 50 parent::__construct(); 51 52 $id = JRequest::getVar('id', 0, '', 'int'); 53 $this->setId((int)$id); 54 } 55 56 /** 57 * Method to set the weblink identifier 58 * 59 * @access public 60 * @param int Weblink identifier 61 */ 62 function setId($id) 63 { 64 // Set weblink id and wipe data 65 $this->_id = $id; 66 $this->_data = null; 67 } 68 69 /** 70 * Method to get a weblink 71 * 72 * @since 1.5 73 */ 74 function &getData() 75 { 76 // Load the weblink data 77 if ($this->_loadData()) 78 { 79 // Initialize some variables 80 $user = &JFactory::getUser(); 81 82 // Make sure the weblink is published 83 if (!$this->_data->published) { 84 JError::raiseError(404, JText::_("Resource Not Found")); 85 return false; 86 } 87 88 // Check to see if the category is published 89 if (!$this->_data->cat_pub) { 90 JError::raiseError( 404, JText::_("Resource Not Found") ); 91 return; 92 } 93 94 // Check whether category access level allows access 95 if ($this->_data->cat_access > $user->get('aid', 0)) { 96 JError::raiseError( 403, JText::_('ALERTNOTAUTH') ); 97 return; 98 } 99 } 100 else $this->_initData(); 101 102 return $this->_data; 103 } 104 105 /** 106 * Method to increment the hit counter for the weblink 107 * 108 * @access public 109 * @return boolean True on success 110 * @since 1.5 111 */ 112 function hit() 113 { 114 global $mainframe; 115 116 if ($this->_id) 117 { 118 $weblink = & $this->getTable(); 119 $weblink->hit($this->_id); 120 return true; 121 } 122 return false; 123 } 124 125 /** 126 * Tests if weblink is checked out 127 * 128 * @access public 129 * @param int A user id 130 * @return boolean True if checked out 131 * @since 1.5 132 */ 133 function isCheckedOut( $uid=0 ) 134 { 135 if ($this->_loadData()) 136 { 137 if ($uid) { 138 return ($this->_data->checked_out && $this->_data->checked_out != $uid); 139 } else { 140 return $this->_data->checked_out; 141 } 142 } 143 } 144 145 /** 146 * Method to checkin/unlock the weblink 147 * 148 * @access public 149 * @return boolean True on success 150 * @since 1.5 151 */ 152 function checkin() 153 { 154 if ($this->_id) 155 { 156 $weblink = & $this->getTable(); 157 if(! $weblink->checkin($this->_id)) { 158 $this->setError($this->_db->getErrorMsg()); 159 return false; 160 } 161 return true; 162 } 163 return false; 164 } 165 166 /** 167 * Method to checkout/lock the weblink 168 * 169 * @access public 170 * @param int $uid User ID of the user checking the article out 171 * @return boolean True on success 172 * @since 1.5 173 */ 174 function checkout($uid = null) 175 { 176 if ($this->_id) 177 { 178 // Make sure we have a user id to checkout the article with 179 if (is_null($uid)) { 180 $user =& JFactory::getUser(); 181 $uid = $user->get('id'); 182 } 183 // Lets get to it and checkout the thing... 184 $weblink = & $this->getTable(); 185 if(!$weblink->checkout($uid, $this->_id)) { 186 $this->setError($this->_db->getErrorMsg()); 187 return false; 188 } 189 190 return true; 191 } 192 return false; 193 } 194 195 /** 196 * Method to store the weblink 197 * 198 * @access public 199 * @return boolean True on success 200 * @since 1.5 201 */ 202 function store($data) 203 { 204 $row =& $this->getTable(); 205 206 // Bind the form fields to the web link table 207 if (!$row->bind($data)) { 208 $this->setError($this->_db->getErrorMsg()); 209 return false; 210 } 211 212 // Create the timestamp for the date 213 $row->date = gmdate('Y-m-d H:i:s'); 214 215 // if new item, order last in appropriate group 216 if (!$row->id) { 217 $where = 'catid = ' . (int) $row->catid ; 218 $row->ordering = $row->getNextOrder( $where ); 219 } 220 // Make sure the web link table is valid 221 if (!$row->check()) { 222 $this->setError($this->_db->getErrorMsg()); 223 return false; 224 } 225 226 // Store the web link table to the database 227 if (!$row->store()) { 228 $this->setError($this->_db->getErrorMsg()); 229 return false; 230 } 231 232 return true; 233 } 234 235 /** 236 * Method to load content weblink data 237 * 238 * @access private 239 * @return boolean True on success 240 * @since 1.5 241 */ 242 function _loadData() 243 { 244 // Lets load the content if it doesn't already exist 245 if (empty($this->_data)) 246 { 247 $query = 'SELECT w.*, cc.title AS category,' . 248 ' cc.published AS cat_pub, cc.access AS cat_access'. 249 ' FROM #__weblinks AS w' . 250 ' LEFT JOIN #__categories AS cc ON cc.id = w.catid' . 251 ' WHERE w.id = '. (int) $this->_id; 252 $this->_db->setQuery($query); 253 $this->_data = $this->_db->loadObject(); 254 return (boolean) $this->_data; 255 } 256 return true; 257 } 258 259 /** 260 * Method to initialise the weblink data 261 * 262 * @access private 263 * @return boolean True on success 264 * @since 1.5 265 */ 266 function _initData() 267 { 268 // Lets load the content if it doesn't already exist 269 if (empty($this->_data)) 270 { 271 $weblink = new stdClass(); 272 $weblink->id = 0; 273 $weblink->catid = 0; 274 $weblink->sid = 0; 275 $weblink->title = null; 276 $weblink->url = null; 277 $weblink->description = null; 278 $weblink->date = null; 279 $weblink->hits = 0; 280 $weblink->published = 0; 281 $weblink->checked_out = 0; 282 $weblink->checked_out_time = 0; 283 $weblink->ordering = 0; 284 $weblink->archived = 0; 285 $weblink->approved = 0; 286 $weblink->params = null; 287 $weblink->category = null; 288 $this->_data = $weblink; 289 return (boolean) $this->_data; 290 } 291 return true; 292 } 293 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |