📄 list.php
字号:
<?php
/**
* @version $Id: list.php 8598 2007-08-28 08:44:08Z robs $
* @package Joomla
* @subpackage Menus
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights
* reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant to the
* GNU General Public License, and as distributed it includes or is derivative
* of works licensed under the GNU General Public License or other free or open
* source software licenses. See COPYRIGHT.php for copyright notices and
* details.
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();
jimport( 'joomla.application.component.model' );
/**
* @package Joomla
* @subpackage Menus
*/
class MenusModelList extends JModel
{
/** @var object JTable object */
var $_table = null;
var $_pagination = null;
/**
* Returns the internal table object
* @return JTable
*/
function &getTable()
{
if ($this->_table == null)
{
$this->_table =& JTable::getInstance( 'menu');
}
return $this->_table;
}
function &getItems()
{
global $mainframe;
static $items;
if (isset($items)) {
return $items;
}
$db =& $this->getDBO();
$menutype = $mainframe->getUserStateFromRequest( "com_menus.menutype", 'menutype', 'mainmenu', 'string' );
$filter_order = $mainframe->getUserStateFromRequest( 'com_menus.'.$menutype.'.filter_order', 'filter_order', 'm.ordering', 'cmd' );
$filter_order_Dir = $mainframe->getUserStateFromRequest( 'com_menus.'.$menutype.'.filter_order_Dir', 'filter_order_Dir', 'ASC', 'word' );
$filter_state = $mainframe->getUserStateFromRequest( 'com_menus.'.$menutype.'.filter_state', 'filter_state', '', 'word' );
$limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg( 'list_limit' ), 'int' );
$limitstart = $mainframe->getUserStateFromRequest( 'com_menus.'.$menutype.'.limitstart', 'limitstart', 0, 'int' );
$levellimit = $mainframe->getUserStateFromRequest( 'com_menus.'.$menutype.'.levellimit', 'levellimit', 10, 'int' );
$search = $mainframe->getUserStateFromRequest( 'com_menus.'.$menutype.'.search', 'search', '', 'string' );
$search = JString::strtolower( $search );
$and = '';
if ( $filter_state )
{
if ( $filter_state == 'P' ) {
$and = ' AND m.published = 1';
} else if ($filter_state == 'U' ) {
$and = ' AND m.published = 0';
}
}
// just in case filter_order get's messed up
if ($filter_order) {
$orderby = ' ORDER BY '.$filter_order .' '. $filter_order_Dir .', m.parent, m.ordering';
} else {
$orderby = ' ORDER BY m.parent, m.ordering';
}
// select the records
// note, since this is a tree we have to do the limits code-side
if ($search) {
$query = 'SELECT m.id' .
' FROM #__menu AS m' .
' WHERE menutype = '.$db->Quote($menutype) .
' AND LOWER( m.name ) LIKE '.$db->Quote('%'.$search.'%') .
$and;
$db->setQuery( $query );
$search_rows = $db->loadResultArray();
}
$query = 'SELECT m.*, u.name AS editor, g.name AS groupname, c.publish_up, c.publish_down, com.name AS com_name' .
' FROM #__menu AS m' .
' LEFT JOIN #__users AS u ON u.id = m.checked_out' .
' LEFT JOIN #__groups AS g ON g.id = m.access' .
' LEFT JOIN #__content AS c ON c.id = m.componentid AND m.type = "content_typed"' .
' LEFT JOIN #__components AS com ON com.id = m.componentid AND m.type = "component"' .
' WHERE m.menutype = '.$db->Quote($menutype) .
' AND m.published != -2' .
$and .
$orderby;
$db->setQuery( $query );
$rows = $db->loadObjectList();
// establish the hierarchy of the menu
$children = array();
// first pass - collect children
foreach ($rows as $v )
{
$pt = $v->parent;
$list = @$children[$pt] ? $children[$pt] : array();
array_push( $list, $v );
$children[$pt] = $list;
}
// second pass - get an indent list of the items
$list = JHTML::_('menu.treerecurse', 0, '', array(), $children, max( 0, $levellimit-1 ) );
// eventually only pick out the searched items.
if ($search) {
$list1 = array();
foreach ($search_rows as $sid )
{
foreach ($list as $item)
{
if ($item->id == $sid) {
$list1[] = $item;
}
}
}
// replace full list with found items
$list = $list1;
}
$total = count( $list );
jimport('joomla.html.pagination');
$this->_pagination = new JPagination( $total, $limitstart, $limit );
// slice out elements based on limits
$list = array_slice( $list, $this->_pagination->limitstart, $this->_pagination->limit );
$i = 0;
foreach ( $list as $mitem )
{
$edit = '';
switch ( $mitem->type )
{
case 'separator':
$list[$i]->descrip = JText::_('Separator');
break;
case 'url':
$list[$i]->descrip = JText::_('URL');
break;
case 'menulink':
$list[$i]->descrip = JText::_('Menu Link');
break;
case 'component':
$list[$i]->descrip = JText::_('Component');
break;
default:
$list[$i]->descrip = JText::_('Unknown');
break;
}
$i++;
}
$items = $list;
return $items;
}
function &getPagination()
{
if ($this->_pagination == null) {
$this->getItems();
}
return $this->_pagination;
}
/**
* Form for copying item(s) to a specific menu
*/
function getItemsFromRequest()
{
static $items;
if (isset($items)) {
return $items;
}
$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
JArrayHelper::toInteger($cid);
if (count($cid) < 1) {
$this->setError(JText::_( 'Select an item to move'));
return false;
}
// Query to list the selected menu items
$db =& $this->getDBO();
$cids = implode( ',', $cid );
$query = 'SELECT `id`, `name`' .
' FROM `#__menu`' .
' WHERE `id` IN ( '.$cids.' )';
$db->setQuery( $query );
$items = $db->loadObjectList();
return $items;
}
/**
* Gets the componet table object related to this menu item
*/
function &getComponent()
{
$id = $this->_table->componentid;
$component = & JTable::getInstance( 'component');
$component->load( $id );
return $component;
}
/**
* Save the item(s) to the menu selected
*/
function copy( $items, $menu )
{
$curr =& JTable::getInstance('menu');
$itemref = array();
foreach ($items as $id)
{
$curr->load( $id );
$curr->id = NULL;
$curr->home = 0;
if ( !$curr->store() ) {
$this->setError($row->getError());
return false;
}
$itemref[] = array($id, $curr->id);
}
foreach ($itemref as $ref)
{
$curr->load( $ref[1] );
if ($curr->parent!=0) {
$found = false;
foreach ( $itemref as $ref2 )
{
if ($curr->parent == $ref2[0]) {
$curr->parent = $ref2[1];
$found = true;
break;
} // if
}
if (!$found && $curr->menutype!=$menu) {
$curr->parent = 0;
}
} // if
$curr->menutype = $menu;
$curr->ordering = '9999';
$curr->home = 0;
if ( !$curr->store() ) {
$this->setError($row->getError());
return false;
}
$curr->reorder( 'menutype = '.$this->_db->Quote($curr->menutype).' AND parent = '.(int) $curr->parent );
} // foreach
return true;
}
function move($items, $menu)
{
// Add all children to the list
foreach ($items as $id)
{
$this->_addChildren($id, $items);
}
$row =& $this->getTable();
$ordering = 1000000;
$firstroot = 0;
foreach ($items as $id) {
$row->load( $id );
// is it moved together with his parent?
$found = false;
if ($row->parent != 0) {
foreach ($items as $idx)
{
if ($idx == $row->parent) {
$found = true;
break;
} // if
}
}
if (!$found) {
$row->parent = 0;
$row->ordering = $ordering++;
if (!$firstroot) $firstroot = $row->id;
} // if
$row->menutype = $menu;
if ( !$row->store() ) {
$this->setError($row->getError());
return false;
} // if
} // foreach
if ($firstroot) {
$row->load( $firstroot );
$row->reorder( 'menutype = '.$this->_db->Quote($row->menutype).' AND parent = '.(int) $row->parent );
} // if
return true;
}
function toTrash($items)
{
$db =& $this->getDBO();
$nd = $db->getNullDate();
$state = -2;
// Add all children to the list
foreach ($items as $id)
{
$this->_addChildren($id, $items);
}
// Sent menu items to the trash
JArrayHelper::toInteger($items, array(0));
$where = ' WHERE (id = ' . implode( ' OR id = ', $items ) . ') AND home = 0';
$query = 'UPDATE #__menu' .
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -