/components/com_weblinks/models/weblink.php
PHP | 108 lines | 48 code | 13 blank | 47 comment | 7 complexity | 4f905709171cbfaeb52c64a763c16977 MD5 | raw file
Possible License(s): LGPL-2.1
1<?php 2/** 3 * @package Joomla.Site 4 * @subpackage com_weblinks 5 * 6 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10defined('_JEXEC') or die; 11 12/** 13 * Weblinks Component Model for a Weblink record 14 * 15 * @package Joomla.Site 16 * @subpackage com_weblinks 17 * @since 1.5 18 */ 19class WeblinksModelWeblink extends JModelItem 20{ 21 /** 22 * Model context string. 23 * 24 * @access protected 25 * @var string 26 */ 27 protected $_context = 'com_weblinks.weblink'; 28 29 /** 30 * Method to auto-populate the model state. 31 * 32 * Note. Calling getState in this method will result in recursion. 33 * 34 * @since 1.6 35 */ 36 protected function populateState() 37 { 38 $app = JFactory::getApplication(); 39 $params = $app->getParams(); 40 41 // Load the object state. 42 $id = $app->input->getInt('id'); 43 $this->setState('weblink.id', $id); 44 45 // Load the parameters. 46 $this->setState('params', $params); 47 } 48 49 /** 50 * Method to get an object. 51 * 52 * @param integer The id of the object to get. 53 * 54 * @return mixed Object on success, false on failure. 55 */ 56 public function &getItem($id = null) 57 { 58 if ($this->_item === null) 59 { 60 $this->_item = false; 61 62 if (empty($id)) { 63 $id = $this->getState('weblink.id'); 64 } 65 66 // Get a level row instance. 67 $table = JTable::getInstance('Weblink', 'WeblinksTable'); 68 69 // Attempt to load the row. 70 if ($table->load($id)) 71 { 72 // Check published state. 73 if ($published = $this->getState('filter.published')) 74 { 75 if ($table->state != $published) { 76 return $this->_item; 77 } 78 } 79 80 // Convert the JTable to a clean JObject. 81 $properties = $table->getProperties(1); 82 $this->_item = JArrayHelper::toObject($properties, 'JObject'); 83 } 84 elseif ($error = $table->getError()) { 85 $this->setError($error); 86 } 87 } 88 89 return $this->_item; 90 } 91 92 /** 93 * Method to increment the hit counter for the weblink 94 * 95 * @param int Optional ID of the weblink. 96 * @return boolean True on success 97 * @since 1.5 98 */ 99 public function hit($id = null) 100 { 101 if (empty($id)) { 102 $id = $this->getState('weblink.id'); 103 } 104 105 $weblink = $this->getTable('Weblink', 'WeblinksTable'); 106 return $weblink->hit($id); 107 } 108}