Source for file style.php

Documentation is available at style.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_templates
  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.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Template style table class.
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_templates
  17.  * @since       1.6
  18.  */
  19. class TemplatesTableStyle extends JTable
  20. {
  21.     /**
  22.      * Constructor
  23.      *
  24.      * @param   JDatabaseDriver  &$db  A database connector object
  25.      *
  26.      * @since   1.6
  27.      */
  28.     public function __construct(&$db)
  29.     {
  30.         parent::__construct('#__template_styles''id'$db);
  31.     }
  32.  
  33.     /**
  34.      * Overloaded bind function to pre-process the params.
  35.      *
  36.      * @param   array  $array   Named array
  37.      * @param   mixed  $ignore  An optional array or space separated list of properties to ignore while binding.
  38.      *
  39.      * @return  null|string   null if operation was satisfactory, otherwise returns an error
  40.      *
  41.      * @since   1.6
  42.      */
  43.     public function bind($array$ignore '')
  44.     {
  45.         if (isset($array['params']&& is_array($array['params']))
  46.         {
  47.             $registry new JRegistry;
  48.             $registry->loadArray($array['params']);
  49.             $array['params'= (string) $registry;
  50.         }
  51.  
  52.         // Verify that the default style is not unset
  53.         if ($array['home'== '0' && $this->home == '1')
  54.         {
  55.             $this->setError(JText::_('COM_TEMPLATES_ERROR_CANNOT_UNSET_DEFAULT_STYLE'));
  56.  
  57.             return false;
  58.         }
  59.  
  60.         return parent::bind($array$ignore);
  61.     }
  62.  
  63.     /**
  64.      * Overloaded check method to ensure data integrity.
  65.      *
  66.      * @return  boolean  True on success.
  67.      *
  68.      * @since   1.6
  69.      */
  70.     public function check()
  71.     {
  72.         if (empty($this->title))
  73.         {
  74.             $this->setError(JText::_('COM_TEMPLATES_ERROR_STYLE_REQUIRES_TITLE'));
  75.  
  76.             return false;
  77.         }
  78.  
  79.         return true;
  80.     }
  81.  
  82.     /**
  83.      * Overloaded store method to ensure unicity of default style.
  84.      *
  85.      * @param   boolean  $updateNulls  True to update fields even if they are null.
  86.      *
  87.      * @return  boolean  True on success.
  88.      *
  89.      * @since   1.6
  90.      */
  91.     public function store($updateNulls false)
  92.     {
  93.         if ($this->home != '0')
  94.         {
  95.             $query $this->_db->getQuery(true)
  96.                 ->update('#__template_styles')
  97.                 ->set('home=\'0\'')
  98.                 ->where('client_id=' . (int) $this->client_id)
  99.                 ->where('home=' $this->_db->quote($this->home));
  100.             $this->_db->setQuery($query);
  101.             $this->_db->execute();
  102.         }
  103.  
  104.         return parent::store($updateNulls);
  105.     }
  106.  
  107.     /**
  108.      * Overloaded store method to unsure existence of a default style for a template.
  109.      *
  110.      * @param   mixed  $pk  An optional primary key value to delete.  If not set the instance property value is used.
  111.      *
  112.      * @return  boolean  True on success.
  113.      *
  114.      * @since   1.6
  115.      */
  116.     public function delete($pk null)
  117.     {
  118.         $k $this->_tbl_key;
  119.         $pk (is_null($pk)) $this->$k $pk;
  120.  
  121.         if (!is_null($pk))
  122.         {
  123.             $query $this->_db->getQuery(true)
  124.                 ->from('#__template_styles')
  125.                 ->select('id')
  126.                 ->where('client_id=' . (int) $this->client_id)
  127.                 ->where('template=' $this->_db->quote($this->template));
  128.             $this->_db->setQuery($query);
  129.             $results $this->_db->loadColumn();
  130.  
  131.             if (count($results== && $results[0== $pk)
  132.             {
  133.                 $this->setError(JText::_('COM_TEMPLATES_ERROR_CANNOT_DELETE_LAST_STYLE'));
  134.  
  135.                 return false;
  136.             }
  137.         }
  138.  
  139.         return parent::delete($pk);
  140.     }
  141. }

Documentation generated on Tue, 19 Nov 2013 15:14:37 +0100 by phpDocumentor 1.4.3