Source for file asset.php

Documentation is available at asset.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Table
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 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. /**
  13.  * Table class supporting modified pre-order tree traversal behavior.
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Table
  17.  * @link        http://docs.joomla.org/JTableAsset
  18.  * @since       11.1
  19.  */
  20. class JTableAsset extends JTableNested
  21. {
  22.     /**
  23.      * The primary key of the asset.
  24.      *
  25.      * @var    integer 
  26.      * @since  11.1
  27.      */
  28.     public $id = null;
  29.  
  30.     /**
  31.      * The unique name of the asset.
  32.      *
  33.      * @var    string 
  34.      * @since  11.1
  35.      */
  36.     public $name = null;
  37.  
  38.     /**
  39.      * The human readable title of the asset.
  40.      *
  41.      * @var    string 
  42.      * @since  11.1
  43.      */
  44.     public $title = null;
  45.  
  46.     /**
  47.      * The rules for the asset stored in a JSON string
  48.      *
  49.      * @var    string 
  50.      * @since  11.1
  51.      */
  52.     public $rules = null;
  53.  
  54.     /**
  55.      * Constructor
  56.      *
  57.      * @param   JDatabaseDriver  $db  Database driver object.
  58.      *
  59.      * @since   11.1
  60.      */
  61.     public function __construct(JDatabaseDriver $db)
  62.     {
  63.         parent::__construct('#__assets''id'$db);
  64.     }
  65.  
  66.     /**
  67.      * Method to load an asset by its name.
  68.      *
  69.      * @param   string  $name  The name of the asset.
  70.      *
  71.      * @return  integer 
  72.      *
  73.      * @since   11.1
  74.      */
  75.     public function loadByName($name)
  76.     {
  77.         $query $this->_db->getQuery(true)
  78.             ->select($this->_db->quoteName('id'))
  79.             ->from($this->_db->quoteName('#__assets'))
  80.             ->where($this->_db->quoteName('name'' = ' $this->_db->quote($name));
  81.         $this->_db->setQuery($query);
  82.         $assetId = (int) $this->_db->loadResult();
  83.  
  84.         if (empty($assetId))
  85.         {
  86.             return false;
  87.         }
  88.  
  89.         return $this->load($assetId);
  90.     }
  91.  
  92.     /**
  93.      * Assert that the nested set data is valid.
  94.      *
  95.      * @return  boolean  True if the instance is sane and able to be stored in the database.
  96.      *
  97.      * @link    http://docs.joomla.org/JTable/check
  98.      * @since   11.1
  99.      */
  100.     public function check()
  101.     {
  102.         $this->parent_id = (int) $this->parent_id;
  103.  
  104.         // JTableNested does not allow parent_id = 0, override this.
  105.         if ($this->parent_id > 0)
  106.         {
  107.             // Get the JDatabaseQuery object
  108.             $query $this->_db->getQuery(true)
  109.                 ->select('COUNT(id)')
  110.                 ->from($this->_db->quoteName($this->_tbl))
  111.                 ->where($this->_db->quoteName('id'' = ' $this->parent_id);
  112.             $this->_db->setQuery($query);
  113.  
  114.             if ($this->_db->loadResult())
  115.             {
  116.                 return true;
  117.             }
  118.             else
  119.             {
  120.                 $this->setError('Invalid Parent ID');
  121.  
  122.                 return false;
  123.             }
  124.         }
  125.  
  126.         return true;
  127.     }
  128. }

Documentation generated on Tue, 19 Nov 2013 14:54:05 +0100 by phpDocumentor 1.4.3