Location: PHPKode > projects > Modularized Information Environment > mie/includes/menu.inc
<?php
/**
 * @file includes/menu.inc
 * @brief Menu Object
 * @author Kenneth Smith <hide@address.com>
 *
 * Modularized Information Environment (MIE)
 * Copyright (C) 2005-2006 by Kenneth Smith. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307, USA.
 */

defined('VALIE_MIE') || die(_('Direct access not allowed'));
defined('MENU_INC') && exit;
define('MENU_INC', true);

class MENU {

	/// Cached Menu Data
	public $data;

	/// Construct Object
	function __construct() {
		$this->data = array();
	}

	/// Retrieve a Menu
	function by_id($_id) {
		global $db, $user;
		if(!isset($this->data[$_id])) {
			$sql = $db->rewrite("SELECT k{id} k{id}, k{name} k{name}, k{title} k{title} FROM t{menus} WHERE k{id} = %i", $_id);
			$this->data[$_id] = $db->result($sql);
			// Determine sanctions
			$sanctions = '';
			if(isset($user)) {
				if($user->id == 1) { // The root user
					$sanctions = ' OR TRUE';
				}
				elseif($user->sanctions) { // User has sanctions
					$sanctions = $db->rewrite(' OR x.k{action_id} IN (' . implode(',', mie_extract_key($user->sanctions, 'id')) . ')');
				}
			}
			// Read menu data
			$sql = $db->rewrite("SELECT p.k{id} k{id}, p.k{name} k{name}, p.k{title} k{title}, p.k{path} k{path} FROM t{pages} p LEFT JOIN t{page_shields} x ON x.k{page_id} = p.k{id} LEFT JOIN t{links} l ON l.k{page_id} = p.k{id} WHERE (x.k{page_id} IS NULL$sanctions) AND l.k{menu_id} = %i ORDER BY p.k{name}", $_id);
			$this->data[$_id]['links'] = (array)$db->table($sql);
		}
		return $this->data[$_id];
	}
}

?>
Return current item: Modularized Information Environment