[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/libraries/joomla/database/table/ -> menu.php (source)

   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   * Menu table
  16   *
  17   * @package     Joomla.Platform
  18   * @subpackage  Table
  19   * @since       11.1
  20   */
  21  class JTableMenu extends JTableNested
  22  {
  23      /**
  24       * Constructor
  25       *
  26       * @param   JDatabase  &$db  A database connector object
  27       *
  28       * @since   11.1
  29       */
  30  	public function __construct(&$db)
  31      {
  32          parent::__construct('#__menu', 'id', $db);
  33  
  34          // Set the default access level.
  35          $this->access = (int) JFactory::getConfig()->get('access');
  36      }
  37  
  38      /**
  39       * Overloaded bind function
  40       *
  41       * @param   array  $array   Named array
  42       * @param   mixed  $ignore  An optional array or space separated list of properties to ignore while binding.
  43       *
  44       * @return  mixed  Null if operation was satisfactory, otherwise returns an error
  45       *
  46       * @see     JTable::bind
  47       * @since   11.1
  48       */
  49  	public function bind($array, $ignore = '')
  50      {
  51          // Verify that the default home menu is not unset
  52          if ($this->home == '1' && $this->language == '*' && ($array['home'] == '0'))
  53          {
  54              $this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_CANNOT_UNSET_DEFAULT_DEFAULT'));
  55              return false;
  56          }
  57          //Verify that the default home menu set to "all" languages" is not unset
  58          if ($this->home == '1' && $this->language == '*' && ($array['language'] != '*'))
  59          {
  60              $this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_CANNOT_UNSET_DEFAULT'));
  61              return false;
  62          }
  63  
  64          // Verify that the default home menu is not unpublished
  65          if ($this->home == '1' && $this->language == '*' && $array['published'] != '1')
  66          {
  67              $this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_UNPUBLISH_DEFAULT_HOME'));
  68              return false;
  69          }
  70  
  71          if (isset($array['params']) && is_array($array['params']))
  72          {
  73              $registry = new JRegistry;
  74              $registry->loadArray($array['params']);
  75              $array['params'] = (string) $registry;
  76          }
  77  
  78          return parent::bind($array, $ignore);
  79      }
  80  
  81      /**
  82       * Overloaded check function
  83       *
  84       * @return  boolean  True on success
  85       *
  86       * @see     JTable::check
  87       * @since   11.1
  88       */
  89  	public function check()
  90      {
  91          // If the alias field is empty, set it to the title.
  92          $this->alias = trim($this->alias);
  93          if ((empty($this->alias)) && ($this->type != 'alias' && $this->type != 'url'))
  94          {
  95              $this->alias = $this->title;
  96          }
  97  
  98          // Make the alias URL safe.
  99          $this->alias = JApplication::stringURLSafe($this->alias);
 100          if (trim(str_replace('-', '', $this->alias)) == '')
 101          {
 102              $this->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
 103          }
 104  
 105          // Cast the home property to an int for checking.
 106          $this->home = (int) $this->home;
 107  
 108          // Verify that a first level menu item alias is not 'component'.
 109          if ($this->parent_id == 1 && $this->alias == 'component')
 110          {
 111              $this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_ROOT_ALIAS_COMPONENT'));
 112              return false;
 113          }
 114  
 115          // Verify that a first level menu item alias is not the name of a folder.
 116          jimport('joomla.filesystem.folders');
 117          if ($this->parent_id == 1 && in_array($this->alias, JFolder::folders(JPATH_ROOT)))
 118          {
 119              $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_MENU_ROOT_ALIAS_FOLDER', $this->alias, $this->alias));
 120              return false;
 121          }
 122  
 123          // Verify that the home item a component.
 124          if ($this->home && $this->type != 'component')
 125          {
 126              $this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_HOME_NOT_COMPONENT'));
 127              return false;
 128          }
 129  
 130          return true;
 131      }
 132  
 133      /**
 134       * Overloaded store function
 135       *
 136       * @param   boolean  $updateNulls  True to update fields even if they are null.
 137       *
 138       * @return  mixed  False on failure, positive integer on success.
 139       *
 140       * @see     JTable::store
 141       * @since   11.1
 142       */
 143  	public function store($updateNulls = false)
 144      {
 145          $db = JFactory::getDBO();
 146          // Verify that the alias is unique
 147          $table = JTable::getInstance('Menu', 'JTable');
 148          if ($table->load(array('alias' => $this->alias, 'parent_id' => $this->parent_id, 'client_id' => $this->client_id, 'language' => $this->language))
 149              && ($table->id != $this->id || $this->id == 0))
 150          {
 151              if ($this->menutype == $table->menutype)
 152              {
 153                  $this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_UNIQUE_ALIAS'));
 154              }
 155              else
 156              {
 157                  $this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_UNIQUE_ALIAS_ROOT'));
 158              }
 159              return false;
 160          }
 161          // Verify that the home page for this language is unique
 162          if ($this->home == '1')
 163          {
 164              $table = JTable::getInstance('Menu', 'JTable');
 165              if ($table->load(array('home' => '1', 'language' => $this->language)))
 166              {
 167                  if ($table->checked_out && $table->checked_out != $this->checked_out)
 168                  {
 169                      $this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_DEFAULT_CHECKIN_USER_MISMATCH'));
 170                      return false;
 171                  }
 172                  $table->home = 0;
 173                  $table->checked_out = 0;
 174                  $table->checked_out_time = $db->getNullDate();
 175                  $table->store();
 176              }
 177              // Verify that the home page for this menu is unique.
 178              if ($table->load(array('home' => '1', 'menutype' => $this->menutype)) && ($table->id != $this->id || $this->id == 0))
 179              {
 180                  $this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_HOME_NOT_UNIQUE_IN_MENU'));
 181                  return false;
 182              }
 183          }
 184          if (!parent::store($updateNulls))
 185          {
 186              return false;
 187          }
 188          // Get the new path in case the node was moved
 189          $pathNodes = $this->getPath();
 190          $segments = array();
 191          foreach ($pathNodes as $node)
 192          {
 193              // Don't include root in path
 194              if ($node->alias != 'root')
 195              {
 196                  $segments[] = $node->alias;
 197              }
 198          }
 199          $newPath = trim(implode('/', $segments), ' /\\');
 200          // Use new path for partial rebuild of table
 201          // Rebuild will return positive integer on success, false on failure
 202          return ($this->rebuild($this->{$this->_tbl_key}, $this->lft, $this->level, $newPath) > 0);
 203      }
 204  }


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