PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_menus/models/items.php

https://github.com/joebushi/joomla
PHP | 172 lines | 88 code | 29 blank | 55 comment | 14 complexity | b6a60b7f876512352c7377becdcf92d8 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  5. * @license GNU General Public License version 2 or later; see LICENSE.txt
  6. */
  7. defined('_JEXEC') or die;
  8. jimport('joomla.application.component.modellist');
  9. jimport('joomla.database.query');
  10. /**
  11. * Menu Item List Model for Menus.
  12. *
  13. * @package Joomla.Administrator
  14. * @subpackage com_menus
  15. * @since 1.6
  16. */
  17. class MenusModelItems extends JModelList
  18. {
  19. /**
  20. * Model context string.
  21. *
  22. * @var string
  23. */
  24. protected $_context = 'com_menus.items';
  25. /**
  26. * Method to auto-populate the model state.
  27. *
  28. * @return void
  29. */
  30. protected function _populateState()
  31. {
  32. $app = JFactory::getApplication('administrator');
  33. $search = $app->getUserStateFromRequest($this->_context.'.search', 'search');
  34. $this->setState('filter.search', $search);
  35. $published = $app->getUserStateFromRequest($this->_context.'.published', 'filter_published', '');
  36. $this->setState('filter.published', $published);
  37. $access = $app->getUserStateFromRequest($this->_context.'.filter.access', 'filter_access', 0, 'int');
  38. $this->setState('filter.access', $access);
  39. $parentId = $app->getUserStateFromRequest($this->_context.'.filter.parent_id', 'filter_parent_id', 0, 'int');
  40. $this->setState('filter.parent_id', $parentId);
  41. $level = $app->getUserStateFromRequest($this->_context.'.filter.level', 'filter_level', 0, 'int');
  42. $this->setState('filter.level', $level);
  43. $menuType = $app->getUserStateFromRequest($this->_context.'.filter.menutype', 'menutype', 'mainmenu');
  44. $this->setState('filter.menutype', $menuType);
  45. // Component parameters.
  46. $params = JComponentHelper::getParams('com_menus');
  47. $this->setState('params', $params);
  48. // List state information.
  49. parent::_populateState('a.lft', 'asc');
  50. }
  51. /**
  52. * Method to get a store id based on model configuration state.
  53. *
  54. * This is necessary because the model is used by the component and
  55. * different modules that might need different sets of data or different
  56. * ordering requirements.
  57. *
  58. * @param string $id A prefix for the store id.
  59. * @return string A store id.
  60. */
  61. protected function _getStoreId($id = '')
  62. {
  63. // Compile the store id.
  64. $id .= ':'.$this->getState('filter.access');
  65. $id .= ':'.$this->getState('filter.published');
  66. $id .= ':'.$this->getState('filter.search');
  67. $id .= ':'.$this->getState('filter.parent_id');
  68. $id .= ':'.$this->getState('filter.menu_id');
  69. return parent::_getStoreId($id);
  70. }
  71. /**
  72. * Builds an SQL query to load the list data.
  73. *
  74. * @return JQuery A query object.
  75. */
  76. protected function _getListQuery()
  77. {
  78. // Create a new query object.
  79. $query = new JQuery;
  80. // Select all fields from the table.
  81. $query->select($this->getState('list.select', 'a.*'));
  82. $query->from('`#__menu` AS a');
  83. // Join over the users.
  84. $query->select('u.name AS editor');
  85. $query->join('LEFT', '`#__users` AS u ON u.id = a.checked_out');
  86. //Join over components
  87. $query->select('c.name AS componentname');
  88. $query->join('LEFT', '`#__extensions` AS c ON c.extension_id = a.component_id');
  89. // Join over the asset groups.
  90. $query->select('ag.title AS access_level');
  91. $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
  92. // Exclude the root category.
  93. $query->where('a.id > 1');
  94. // Filter on the published state.
  95. $published = $this->getState('filter.published');
  96. if (is_numeric($published)) {
  97. $query->where('a.published = '.(int) $published);
  98. } else if ($published === '') {
  99. $query->where('(a.published IN (0, 1))');
  100. }
  101. // Filter by search in title, alias or id
  102. if ($search = trim($this->getState('filter.search'))) {
  103. if (stripos($search, 'id:') === 0) {
  104. $query->where('a.id = '.(int) substr($search, 3));
  105. } else if (stripos($search, 'link:') === 0) {
  106. if ($search = substr($search, 5)) {
  107. $search = $this->_db->Quote('%'.$this->_db->getEscaped($search, true).'%');
  108. $query->where('a.link LIKE '.$search);
  109. }
  110. } else {
  111. $search = $this->_db->Quote('%'.$this->_db->getEscaped($search, true).'%');
  112. $query->where('a.title LIKE '.$search.' OR a.alias LIKE '.$search);
  113. }
  114. }
  115. // Filter the items over the parent id if set.
  116. $parentId = $this->getState('filter.parent_id');
  117. if (!empty($parentId)) {
  118. $query->where('p.id = '.(int)$parentId);
  119. }
  120. // Filter the items over the menu id if set.
  121. $menuId = $this->getState('filter.menu_id');
  122. if (!empty($menuId)) {
  123. $query->where('a.menu_id = '.(int) $menuId);
  124. }
  125. // Filter the items over the menu id if set.
  126. $menuType = $this->getState('filter.menutype');
  127. if (!empty($menuType)) {
  128. $query->where('a.menutype = '.$this->_db->quote($menuType));
  129. }
  130. // Filter on the access level.
  131. if ($access = $this->getState('filter.access')) {
  132. $query->where('a.access = '.(int) $access);
  133. }
  134. // Filter on the level.
  135. if ($level = $this->getState('filter.level')) {
  136. $query->where('a.level <= '.(int) $level);
  137. }
  138. // Add the list ordering clause.
  139. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.lft')).' '.$this->_db->getEscaped($this->getState('list.direction', 'ASC')));
  140. //echo nl2br(str_replace('#__','jos_',$query->toString())).'<hr/>';
  141. return $query;
  142. }
  143. }