PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/jplatform/joomla/database/table/menu.php

https://github.com/ot2sen/Molajo
PHP | 177 lines | 104 code | 15 blank | 58 comment | 51 complexity | 0439af4ec75157c4c60e6c1d1fcaf931 MD5 | raw file
  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage Database
  5. *
  6. * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. defined('JPATH_PLATFORM') or die;
  10. jimport('joomla.database.tablenested');
  11. /**
  12. * Menu table
  13. *
  14. * @package Joomla.Platform
  15. * @subpackage Table
  16. * @since 11.1
  17. */
  18. class JTableMenu extends JTableNested
  19. {
  20. /**
  21. * Constructor
  22. *
  23. * @param database A database connector object
  24. */
  25. public function __construct(&$db)
  26. {
  27. parent::__construct('#__menu_items', 'id', $db);
  28. // Set the default access level.
  29. $this->access = (int) JFactory::getConfig()->get('access');
  30. }
  31. /**
  32. * Overloaded bind function
  33. *
  34. * @param array $hash named array
  35. *
  36. * @return mixed null is operation was satisfactory, otherwise returns an error
  37. *
  38. * @see JTable:bind
  39. * @since 11.1
  40. */
  41. public function bind($array, $ignore = '')
  42. {
  43. // Verify that the default home menu is not unset
  44. if ($this->home == '1' && $this->language == '*' && ($array['home'] == '0')) {
  45. $this->setError(JText::_('MOLAJO_DATABASE_ERROR_MENU_CANNOT_UNSET_DEFAULT_DEFAULT'));
  46. return false;
  47. }
  48. //Verify that the default home menu set to "all" languages" is not unset
  49. if ($this->home == '1' && $this->language == '*' && ($array['language'] != '*')) {
  50. $this->setError(JText::_('MOLAJO_DATABASE_ERROR_MENU_CANNOT_UNSET_DEFAULT'));
  51. return false;
  52. }
  53. // Verify that the default home menu is not unpublished
  54. if ($this->home == '1' && $this->language == '*' && $array['published'] != '1') {
  55. $this->setError(JText::_('MOLAJO_DATABASE_ERROR_MENU_UNPUBLISH_DEFAULT_HOME'));
  56. return false;
  57. }
  58. if (isset($array['params']) && is_array($array['params']))
  59. {
  60. $registry = new JRegistry();
  61. $registry->loadArray($array['params']);
  62. $array['params'] = (string)$registry;
  63. }
  64. return parent::bind($array, $ignore);
  65. }
  66. /**
  67. * Overloaded check function
  68. *
  69. * @return boolean
  70. * @see JTable::check
  71. * @since 11.1
  72. */
  73. public function check()
  74. {
  75. // If the alias field is empty, set it to the title.
  76. $this->alias = trim($this->alias);
  77. if ((empty($this->alias)) && ($this->type != 'alias' && $this->type !='url')) {
  78. $this->alias = $this->title;
  79. }
  80. // Make the alias URL safe.
  81. $this->alias = JApplication::stringURLSafe($this->alias);
  82. if (trim(str_replace('-', '', $this->alias)) == '') {
  83. $this->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
  84. }
  85. // Cast the home property to an int for checking.
  86. $this->home = (int) $this->home;
  87. // Verify that a first level menu item alias is not 'component'.
  88. if ($this->parent_id==1 && $this->alias == 'component') {
  89. $this->setError(JText::_('MOLAJO_DATABASE_ERROR_MENU_ROOT_ALIAS_COMPONENT'));
  90. return false;
  91. }
  92. // Verify that a first level menu item alias is not the name of a folder.
  93. jimport('joomla.filesystem.folders');
  94. if ($this->parent_id==1 && in_array($this->alias, JFolder::folders(JPATH_ROOT))) {
  95. $this->setError(JText::sprintf('MOLAJO_DATABASE_ERROR_MENU_ROOT_ALIAS_FOLDER', $this->alias, $this->alias));
  96. return false;
  97. }
  98. // Verify that the home item a component.
  99. if ($this->home && $this->type != 'component') {
  100. $this->setError(JText::_('MOLAJO_DATABASE_ERROR_MENU_HOME_NOT_COMPONENT'));
  101. return false;
  102. }
  103. return true;
  104. }
  105. /**
  106. * Overloaded store function
  107. *
  108. * @return boolean
  109. * @see JTable::store
  110. * @since 11.1
  111. */
  112. public function store($updateNulls = false)
  113. {
  114. $db = JFactory::getDBO();
  115. // Verify that the alias is unique
  116. $table = JTable::getInstance('Menu','JTable');
  117. if ($table->load(array('alias'=>$this->alias,'parent_id'=>$this->parent_id,'client_id'=>$this->client_id)) && ($table->id != $this->id || $this->id==0)) {
  118. if ($this->menu_id==$table->menu_id) {
  119. $this->setError(JText::_('MOLAJO_DATABASE_ERROR_MENU_UNIQUE_ALIAS'));
  120. }
  121. else {
  122. $this->setError(JText::_('MOLAJO_DATABASE_ERROR_MENU_UNIQUE_ALIAS_ROOT'));
  123. }
  124. return false;
  125. }
  126. // Verify that the home page for this language is unique
  127. if ($this->home=='1') {
  128. $table = JTable::getInstance('Menu','JTable');
  129. if ($table->load(array('home'=>'1','language'=>$this->language))) {
  130. if ($table->checked_out && $table->checked_out!=$this->checked_out) {
  131. $this->setError(JText::_('MOLAJO_DATABASE_ERROR_MENU_DEFAULT_CHECKIN_USER_MISMATCH'));
  132. return false;
  133. }
  134. $table->home = 0;
  135. $table->checked_out = 0;
  136. $table->checked_out_time = $db->getNullDate();
  137. $table->store();
  138. }
  139. // Verify that the home page for this menu is unique.
  140. if ($table->load(array('home'=>'1', 'menu_id'=>$this->menu_id)) && ($table->id != $this->id || $this->id==0)) {
  141. $this->setError(JText::_('MOLAJO_DATABASE_ERROR_MENU_HOME_NOT_UNIQUE_IN_MENU'));
  142. return false;
  143. }
  144. }
  145. if(!parent::store($updateNulls)) {
  146. return false;
  147. }
  148. // Get the new path in case the node was moved
  149. $pathNodes = $this->getPath();
  150. $segments = array();
  151. foreach ($pathNodes as $node) {
  152. // Don't include root in path
  153. if ($node->alias != 'root') {
  154. $segments[] = $node->alias;
  155. }
  156. }
  157. $newPath = trim(implode('/', $segments), ' /\\');
  158. // Use new path for partial rebuild of table
  159. // rebuild will return positive integer on success, false on failure
  160. return ($this->rebuild($this->{$this->_tbl_key}, $this->lft, $this->level, $newPath) > 0);
  161. }
  162. }