Source for file category.php

Documentation is available at category.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Legacy
  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.  * Category table
  14.  *
  15.  * @package     Joomla.Legacy
  16.  * @subpackage  Table
  17.  * @since       11.1
  18.  */
  19. class JTableCategory extends JTableNested
  20. {
  21.     /**
  22.      * Constructor
  23.      *
  24.      * @param   JDatabaseDriver  $db  Database driver object.
  25.      *
  26.      * @since   11.1
  27.      */
  28.     public function __construct(JDatabaseDriver $db)
  29.     {
  30.         parent::__construct('#__categories''id'$db);
  31.  
  32.         $this->access = (int) JFactory::getConfig()->get('access');
  33.     }
  34.  
  35.     /**
  36.      * Method to compute the default name of the asset.
  37.      * The default name is in the form table_name.id
  38.      * where id is the value of the primary key of the table.
  39.      *
  40.      * @return  string 
  41.      *
  42.      * @since   11.1
  43.      */
  44.     protected function _getAssetName()
  45.     {
  46.         $k $this->_tbl_key;
  47.  
  48.         return $this->extension '.category.' . (int) $this->$k;
  49.     }
  50.  
  51.     /**
  52.      * Method to return the title to use for the asset table.
  53.      *
  54.      * @return  string 
  55.      *
  56.      * @since   11.1
  57.      */
  58.     protected function _getAssetTitle()
  59.     {
  60.         return $this->title;
  61.     }
  62.  
  63.     /**
  64.      * Get the parent asset id for the record
  65.      *
  66.      * @param   JTable   $table  A JTable object for the asset parent.
  67.      * @param   integer  $id     The id for the asset
  68.      *
  69.      * @return  integer  The id of the asset's parent
  70.      *
  71.      * @since   11.1
  72.      */
  73.     protected function _getAssetParentId(JTable $table null$id null)
  74.     {
  75.         $assetId null;
  76.  
  77.         // This is a category under a category.
  78.         if ($this->parent_id > 1)
  79.         {
  80.             // Build the query to get the asset id for the parent category.
  81.             $query $this->_db->getQuery(true)
  82.                 ->select($this->_db->quoteName('asset_id'))
  83.                 ->from($this->_db->quoteName('#__categories'))
  84.                 ->where($this->_db->quoteName('id'' = ' $this->parent_id);
  85.  
  86.             // Get the asset id from the database.
  87.             $this->_db->setQuery($query);
  88.  
  89.             if ($result $this->_db->loadResult())
  90.             {
  91.                 $assetId = (int) $result;
  92.             }
  93.         }
  94.         // This is a category that needs to parent with the extension.
  95.         elseif ($assetId === null)
  96.         {
  97.             // Build the query to get the asset id for the parent category.
  98.             $query $this->_db->getQuery(true)
  99.                 ->select($this->_db->quoteName('id'))
  100.                 ->from($this->_db->quoteName('#__assets'))
  101.                 ->where($this->_db->quoteName('name'' = ' $this->_db->quote($this->extension));
  102.  
  103.             // Get the asset id from the database.
  104.             $this->_db->setQuery($query);
  105.  
  106.             if ($result $this->_db->loadResult())
  107.             {
  108.                 $assetId = (int) $result;
  109.             }
  110.         }
  111.  
  112.         // Return the asset id.
  113.         if ($assetId)
  114.         {
  115.             return $assetId;
  116.         }
  117.         else
  118.         {
  119.             return parent::_getAssetParentId($table$id);
  120.         }
  121.     }
  122.  
  123.     /**
  124.      * Override check function
  125.      *
  126.      * @return  boolean 
  127.      *
  128.      * @see     JTable::check()
  129.      * @since   11.1
  130.      */
  131.     public function check()
  132.     {
  133.         // Check for a title.
  134.         if (trim($this->title== '')
  135.         {
  136.             $this->setError(JText::_('JLIB_DATABASE_ERROR_MUSTCONTAIN_A_TITLE_CATEGORY'));
  137.  
  138.             return false;
  139.         }
  140.  
  141.         $this->alias = trim($this->alias);
  142.  
  143.         if (empty($this->alias))
  144.         {
  145.             $this->alias = $this->title;
  146.         }
  147.  
  148.         $this->alias = JApplication::stringURLSafe($this->alias);
  149.  
  150.         if (trim(str_replace('-'''$this->alias)) == '')
  151.         {
  152.             $this->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
  153.         }
  154.  
  155.         return true;
  156.     }
  157.  
  158.     /**
  159.      * Overloaded bind function.
  160.      *
  161.      * @param   array   $array   named array
  162.      * @param   string  $ignore  An optional array or space separated list of properties
  163.      *                            to ignore while binding.
  164.      *
  165.      * @return  mixed   Null if operation was satisfactory, otherwise returns an error
  166.      *
  167.      * @see     JTable::bind()
  168.      * @since   11.1
  169.      */
  170.     public function bind($array$ignore '')
  171.     {
  172.         if (isset($array['params']&& is_array($array['params']))
  173.         {
  174.             $registry new JRegistry;
  175.             $registry->loadArray($array['params']);
  176.             $array['params'= (string) $registry;
  177.         }
  178.  
  179.         if (isset($array['metadata']&& is_array($array['metadata']))
  180.         {
  181.             $registry new JRegistry;
  182.             $registry->loadArray($array['metadata']);
  183.             $array['metadata'= (string) $registry;
  184.         }
  185.  
  186.         // Bind the rules.
  187.         if (isset($array['rules']&& is_array($array['rules']))
  188.         {
  189.             $rules new JAccessRules($array['rules']);
  190.             $this->setRules($rules);
  191.         }
  192.  
  193.         return parent::bind($array$ignore);
  194.     }
  195.  
  196.     /**
  197.      * Overridden JTable::store to set created/modified and user id.
  198.      *
  199.      * @param   boolean  $updateNulls  True to update fields even if they are null.
  200.      *
  201.      * @return  boolean  True on success.
  202.      *
  203.      * @since   11.1
  204.      */
  205.     public function store($updateNulls false)
  206.     {
  207.         $date JFactory::getDate();
  208.         $user JFactory::getUser();
  209.  
  210.         if ($this->id)
  211.         {
  212.             // Existing category
  213.             $this->modified_time $date->toSql();
  214.             $this->modified_user_id $user->get('id');
  215.         }
  216.         else
  217.         {
  218.             // New category
  219.             $this->created_time $date->toSql();
  220.             $this->created_user_id $user->get('id');
  221.         }
  222.  
  223.         // Verify that the alias is unique
  224.         $table JTable::getInstance('Category''JTable'array('dbo' => $this->getDbo()));
  225.  
  226.         if ($table->load(array('alias' => $this->alias'parent_id' => $this->parent_id'extension' => $this->extension))
  227.             && ($table->id != $this->id || $this->id == 0))
  228.         {
  229.             $this->setError(JText::_('JLIB_DATABASE_ERROR_CATEGORY_UNIQUE_ALIAS'));
  230.  
  231.             return false;
  232.         }
  233.  
  234.         return parent::store($updateNulls);
  235.     }
  236. }

Documentation generated on Tue, 19 Nov 2013 14:55:18 +0100 by phpDocumentor 1.4.3