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