| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Platform 4 * @subpackage Database 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 8 */ 9 10 defined('JPATH_PLATFORM') or die; 11 12 jimport('joomla.database.tablenested'); 13 14 /** 15 * Table class supporting modified pre-order tree traversal behavior. 16 * 17 * @package Joomla.Platform 18 * @subpackage Database 19 * @link http://docs.joomla.org/JTableAsset 20 * @since 11.1 21 */ 22 class JTableAsset extends JTableNested 23 { 24 /** 25 * The primary key of the asset. 26 * 27 * @var integer 28 * @since 11.1 29 */ 30 public $id = null; 31 32 /** 33 * The unique name of the asset. 34 * 35 * @var string 36 * @since 11.1 37 */ 38 public $name = null; 39 40 /** 41 * The human readable title of the asset. 42 * 43 * @var string 44 * @since 11.1 45 */ 46 public $title = null; 47 48 /** 49 * The rules for the asset stored in a JSON string 50 * 51 * @var string 52 * @since 11.1 53 */ 54 public $rules = null; 55 56 /** 57 * Constructor 58 * 59 * @param JDatabase &$db A database connector object 60 * 61 * @since 11.1 62 */ 63 public function __construct(&$db) 64 { 65 parent::__construct('#__assets', 'id', $db); 66 } 67 68 /** 69 * Method to load an asset by it's name. 70 * 71 * @param string $name The name of the asset. 72 * 73 * @return integer 74 * 75 * @since 11.1 76 */ 77 public function loadByName($name) 78 { 79 // Get the JDatabaseQuery object 80 $query = $this->_db->getQuery(true); 81 82 // Get the asset id for the asset. 83 $query->select($this->_db->quoteName('id')); 84 $query->from($this->_db->quoteName('#__assets')); 85 $query->where($this->_db->quoteName('name') . ' = ' . $this->_db->quote($name)); 86 $this->_db->setQuery($query); 87 $assetId = (int) $this->_db->loadResult(); 88 if (empty($assetId)) 89 { 90 return false; 91 } 92 // Check for a database error. 93 if ($error = $this->_db->getErrorMsg()) 94 { 95 $this->setError($error); 96 return false; 97 } 98 return $this->load($assetId); 99 } 100 101 /** 102 * Asset that the nested set data is valid. 103 * 104 * @return boolean True if the instance is sane and able to be stored in the database. 105 * 106 * @link http://docs.joomla.org/JTable/check 107 * @since 11.1 108 */ 109 public function check() 110 { 111 $this->parent_id = (int) $this->parent_id; 112 113 // JTableNested does not allow parent_id = 0, override this. 114 if ($this->parent_id > 0) 115 { 116 // Get the JDatabaseQuery object 117 $query = $this->_db->getQuery(true); 118 119 $query->select('COUNT(id)'); 120 $query->from($this->_db->quoteName($this->_tbl)); 121 $query->where($this->_db->quoteName('id') . ' = ' . $this->parent_id); 122 $this->_db->setQuery($query); 123 if ($this->_db->loadResult()) 124 { 125 return true; 126 } 127 else 128 { 129 if ($error = $this->_db->getErrorMsg()) 130 { 131 $this->setError($error); 132 } 133 else 134 { 135 $this->setError(JText::_('JLIB_DATABASE_ERROR_INVALID_PARENT_ID')); 136 } 137 return false; 138 } 139 } 140 141 return true; 142 } 143 }
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 |