[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_templates/tables/ -> style.php (source)

   1  <?php
   2  /**
   3   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   4   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   5   */
   6  
   7  // No direct access
   8  defined('_JEXEC') or die;
   9  
  10  /**
  11   * @package        Joomla.Administrator
  12   * @subpackage    com_templates
  13   */
  14  class TemplatesTableStyle extends JTable
  15  {
  16      /**
  17       * Constructor
  18       *
  19       * @param JDatabase A database connector object
  20       */
  21  	public function __construct(&$db)
  22      {
  23          parent::__construct('#__template_styles', 'id', $db);
  24      }
  25  
  26      /**
  27       * Overloaded bind function to pre-process the params.
  28       *
  29       * @param    array        Named array
  30       * @return    null|string    null is operation was satisfactory, otherwise returns an error
  31       * @see JTable:bind
  32       * @since 1.5
  33       */
  34  	public function bind($array, $ignore = '')
  35      {
  36          if (isset($array['params']) && is_array($array['params']))
  37          {
  38              $registry = new JRegistry();
  39              $registry->loadArray($array['params']);
  40              $array['params'] = (string)$registry;
  41          }
  42  
  43          // Verify that the default style is not unset
  44          if ($array['home']=='0' && $this->home=='1') {
  45              $this->setError(JText::_('COM_TEMPLATES_ERROR_CANNOT_UNSET_DEFAULT_STYLE'));
  46              return false;
  47          }
  48  
  49          return parent::bind($array, $ignore);
  50      }
  51  
  52      /**
  53       * Overloaded check method to ensure data integrity.
  54       *
  55       * @return    boolean    True on success.
  56       */
  57  	function check()
  58      {
  59          if (empty($this->title))
  60          {
  61              $this->setError(JText::_('COM_TEMPLATES_ERROR_STYLE_REQUIRES_TITLE'));
  62              return false;
  63          }
  64  
  65          return true;
  66      }
  67      /**
  68       * Overloaded store method to ensure unicity of default style.
  69       *
  70       * @param    boolean True to update fields even if they are null.
  71       * @return    boolean    True on success.
  72       * @since    1.0
  73       * @link    http://docs.joomla.org/JTable/store
  74       */
  75  	public function store($updateNulls = false)
  76      {
  77          if ($this->home!='0') {
  78              $query = $this->_db->getQuery(true);
  79              $query->update('#__template_styles');
  80              $query->set('home=\'0\'');
  81              $query->where('client_id='.(int)$this->client_id);
  82              $query->where('home='.$this->_db->quote($this->home));
  83              $this->_db->setQuery($query);
  84              $this->_db->query();
  85          }
  86          return parent::store($updateNulls);
  87      }
  88  
  89      /**
  90       * Overloaded store method to unsure existence of a default style for a template.
  91       *
  92       * @param    mixed    An optional primary key value to delete.  If not set the
  93       *                    instance property value is used.
  94       * @return    boolean    True on success.
  95       * @since    1.0
  96       * @link    http://docs.joomla.org/JTable/delete
  97       */
  98  	public function delete($pk = null)
  99      {
 100          $k = $this->_tbl_key;
 101          $pk = (is_null($pk)) ? $this->$k : $pk;
 102          if (!is_null($pk)) {
 103              $query = $this->_db->getQuery(true);
 104              $query->from('#__template_styles');
 105              $query->select('id');
 106              $query->where('client_id='.(int)$this->client_id);
 107              $query->where('template='.$this->_db->quote($this->template));
 108              $this->_db->setQuery($query);
 109              $results = $this->_db->loadColumn();
 110              if (count($results)==1 && $results[0]==$pk) {
 111                  $this->setError(JText::_('COM_TEMPLATES_ERROR_CANNOT_DELETE_LAST_STYLE'));
 112                  return false;
 113              }
 114          }
 115          return parent::delete($pk);
 116      }
 117  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1