<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.4 |
+ | CiviCRM version 4.5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
* This file contains the various menus of the CiviCRM module
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
* $Id$
*
*/
require_once 'CRM/Core/I18n.php';
+
+/**
+ * Class CRM_Core_Menu
+ */
class CRM_Core_Menu {
/**
- * the list of menu items
+ * The list of menu items
*
* @var array
* @static
static $_items = NULL;
/**
- * the list of permissioned menu items
+ * The list of permissioned menu items
*
* @var array
* @static
static $_menuCache = NULL;
CONST MENU_ITEM = 1;
- static function &xmlItems() {
- if (!self::$_items) {
+ /**
+ * This function fetches the menu items from xml and xmlMenu hooks
+ *
+ * @param boolen $fetchFromXML fetch the menu items from xml and not from cache
+ *
+ * @return array
+ */
+ static function &xmlItems($fetchFromXML = FALSE) {
+ if (!self::$_items || $fetchFromXML) {
$config = CRM_Core_Config::singleton();
// We needs this until Core becomes a component
return self::$_items;
}
+ /**
+ * @param string $name
+ * @param $menu
+ *
+ * @throws Exception
+ */
static function read($name, &$menu) {
$config = CRM_Core_Config::singleton();
/**
* This function defines information for various menu items
*
+ * @param boolen $fetchFromXML fetch the menu items from xml and not from cache
+ *
* @static
* @access public
*/
- static function &items() {
- return self::xmlItems();
+ static function &items($fetchFromXML = FALSE) {
+ return self::xmlItems($fetchFromXML);
}
+ /**
+ * @param $values
+ *
+ * @return bool
+ */
static function isArrayTrue(&$values) {
foreach ($values as $name => $value) {
if (!$value) {
return TRUE;
}
+ /**
+ * @param $menu
+ * @param $path
+ *
+ * @throws Exception
+ */
static function fillMenuValues(&$menu, $path) {
$fieldsToPropagate = array(
'access_callback',
self::buildAdminLinks($menu);
}
+ /**
+ * This function recomputes menu from xml and populates civicrm_menu
+ * @param bool $truncate
+ */
static function store($truncate = TRUE) {
// first clean up the db
if ($truncate) {
$query = 'TRUNCATE civicrm_menu';
CRM_Core_DAO::executeQuery($query);
}
- $menuArray = self::items();
+ $menuArray = self::items($truncate);
self::build($menuArray);
}
}
+ /**
+ * @param $menu
+ */
static function buildAdminLinks(&$menu) {
$values = array();
foreach ($menu as $path => $item) {
- if (!CRM_Utils_Array::value('adminGroup', $item)) {
+ if (empty($item['adminGroup'])) {
continue;
}
- $query = CRM_Utils_Array::value('path_arguments', $item) ? str_replace(',', '&', $item['path_arguments']) . '&reset=1' : 'reset=1';
+ $query = !empty($item['path_arguments']) ? str_replace(',', '&', $item['path_arguments']) . '&reset=1' : 'reset=1';
$value = array(
'title' => $item['title'],
',' => '_', '/' => '_',
)
),
- 'url' => CRM_Utils_System::url($path, $query,
+ 'url' => CRM_Utils_System::url($path, $query,
FALSE, // absolute
NULL, // fragment
TRUE, // htmlize
$menu['admin'] = array('breadcrumb' => $values);
}
+ /**
+ * @param bool $all
+ *
+ * @return mixed
+ * @throws Exception
+ */
static function &getNavigation($all = FALSE) {
CRM_Core_Error::fatal();
return $values;
}
+ /**
+ * @return null
+ */
static function &getAdminLinks() {
$links = self::get('admin');
if (array_key_exists($currentPath, $menu) &&
isset($menu[$currentPath]['title'])
) {
- $urlVar = CRM_Utils_Array::value('path_arguments', $menu[$currentPath]) ? '&' . $menu[$currentPath]['path_arguments'] : '';
+ $urlVar = !empty($menu[$currentPath]['path_arguments']) ? '&' . $menu[$currentPath]['path_arguments'] : '';
$crumbs[] = array(
'title' => $menu[$currentPath]['title'],
'url' => CRM_Utils_System::url($currentPath,
return $crumbs;
}
+ /**
+ * @param $menu
+ * @param $path
+ */
static function buildReturnUrl(&$menu, $path) {
if (!isset($menu[$path]['return_url'])) {
list($menu[$path]['return_url'], $menu[$path]['return_url_args']) = self::getReturnUrl($menu, $path);
}
}
+ /**
+ * @param $menu
+ * @param $path
+ *
+ * @return array
+ */
static function getReturnUrl(&$menu, $path) {
if (!isset($menu[$path]['return_url'])) {
$pathElements = explode('/', $path);
}
}
+ /**
+ * @param $menu
+ * @param $path
+ */
static function fillComponentIds(&$menu, $path) {
static $cache = array();
}
}
+ /**
+ * @param $path
+ *
+ * @return null
+ */
static function get($path) {
// return null if menu rebuild
$config = CRM_Core_Config::singleton();
return $menuPath;
}
+ /**
+ * @param $pathArgs
+ *
+ * @return mixed
+ */
static function getArrayForPathArgs($pathArgs) {
if (!is_string($pathArgs)) {
return;
$args = array();
$elements = explode(',', $pathArgs);
- //CRM_Core_Error::debug( 'e', $elements );
foreach ($elements as $keyVal) {
- list($key, $val) = explode('=', $keyVal);
+ list($key, $val) = explode('=', $keyVal, 2);
$arr[$key] = $val;
}