Merge pull request #5081 from NileemaJadhav/CRM-15821-work
[civicrm-core.git] / CRM / Core / Menu.php
index ffbdb2a21334804fbc219fb832dfd44b97f60169..eb0c1e85a7415c09f4a74ff17b6199401def38b2 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  * This file contains the various menus of the CiviCRM module
@@ -42,18 +42,16 @@ require_once 'CRM/Core/I18n.php';
 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 $_permissionedItems = NULL;
 
@@ -66,16 +64,17 @@ class CRM_Core_Menu {
   );
 
   static $_menuCache = NULL;
-  CONST MENU_ITEM = 1;
+  const MENU_ITEM = 1;
 
   /**
-   * This function fetches the menu items from xml and xmlMenu hooks
+   * This function fetches the menu items from xml and xmlMenu hooks.
    *
-   * @param boolen $fetchFromXML fetch the menu items from xml and not from cache
+   * @param boolen $fetchFromXML
+   *   Fetch the menu items from xml and not from cache.
    *
    * @return array
    */
-  static function &xmlItems($fetchFromXML = FALSE) {
+  public static function &xmlItems($fetchFromXML = FALSE) {
     if (!self::$_items || $fetchFromXML) {
       $config = CRM_Core_Config::singleton();
 
@@ -108,7 +107,7 @@ class CRM_Core_Menu {
    *
    * @throws Exception
    */
-  static function read($name, &$menu) {
+  public static function read($name, &$menu) {
 
     $config = CRM_Core_Config::singleton();
 
@@ -160,14 +159,14 @@ class CRM_Core_Menu {
   }
 
   /**
-   * This function defines information for various menu items
+   * This function defines information for various menu items.
    *
-   * @param boolen $fetchFromXML fetch the menu items from xml and not from cache
+   * @param boolen $fetchFromXML
+   *   Fetch the menu items from xml and not from cache.
    *
-   * @static
-   * @access public
+   * @return array
    */
-  static function &items($fetchFromXML = FALSE) {
+  public static function &items($fetchFromXML = FALSE) {
     return self::xmlItems($fetchFromXML);
   }
 
@@ -176,7 +175,7 @@ class CRM_Core_Menu {
    *
    * @return bool
    */
-  static function isArrayTrue(&$values) {
+  public static function isArrayTrue(&$values) {
     foreach ($values as $name => $value) {
       if (!$value) {
         return FALSE;
@@ -191,7 +190,7 @@ class CRM_Core_Menu {
    *
    * @throws Exception
    */
-  static function fillMenuValues(&$menu, $path) {
+  public static function fillMenuValues(&$menu, $path) {
     $fieldsToPropagate = array(
       'access_callback',
       'access_arguments',
@@ -236,15 +235,14 @@ class CRM_Core_Menu {
   }
 
   /**
-   * We use this function to
+   * We use this function to.
    *
    * 1. Compute the breadcrumb
    * 2. Compute local tasks value if any
    * 3. Propagate access argument, access callback, page callback to the menu item
    * 4. Build the global navigation block
-   *
    */
-  static function build(&$menu) {
+  public static function build(&$menu) {
     foreach ($menu as $path => $menuItems) {
       self::buildBreadcrumb($menu, $path);
       self::fillMenuValues($menu, $path);
@@ -261,10 +259,10 @@ class CRM_Core_Menu {
   }
 
   /**
-   * This function recomputes menu from xml and populates civicrm_menu
+   * This function recomputes menu from xml and populates civicrm_menu.
    * @param bool $truncate
    */
-  static function store($truncate = TRUE) {
+  public static function store($truncate = TRUE) {
     // first clean up the db
     if ($truncate) {
       $query = 'TRUNCATE civicrm_menu';
@@ -274,12 +272,11 @@ class CRM_Core_Menu {
 
     self::build($menuArray);
 
-
     $config = CRM_Core_Config::singleton();
 
     foreach ($menuArray as $path => $item) {
-      $menu            = new CRM_Core_DAO_Menu();
-      $menu->path      = $path;
+      $menu = new CRM_Core_DAO_Menu();
+      $menu->path = $path;
       $menu->domain_id = CRM_Core_Config::domainID();
 
       $menu->find(TRUE);
@@ -304,7 +301,7 @@ class CRM_Core_Menu {
   /**
    * @param $menu
    */
-  static function buildAdminLinks(&$menu) {
+  public static function buildAdminLinks(&$menu) {
     $values = array();
 
     foreach ($menu as $path => $item) {
@@ -318,16 +315,19 @@ class CRM_Core_Menu {
         'title' => $item['title'],
         'desc' => CRM_Utils_Array::value('desc', $item),
         'id' => strtr($item['title'], array(
-          '(' => '_', ')' => '', ' ' => '',
-            ',' => '_', '/' => '_',
+            '(' => '_',
+            ')' => '',
+            ' ' => '',
+            ',' => '_',
+            '/' => '_',
           )
         ),
         'url' => CRM_Utils_System::url($path, $query,
-            FALSE, // absolute
-            NULL, // fragment
-            TRUE, // htmlize
-            FALSE, // frontend
-            TRUE // forceBackend; CRM-14439 work-around; acceptable for now because we don't display breadcrumbs on frontend
+          FALSE, // absolute
+          NULL, // fragment
+          TRUE, // htmlize
+          FALSE, // frontend
+          TRUE // forceBackend; CRM-14439 work-around; acceptable for now because we don't display breadcrumbs on frontend
         ),
         'icon' => CRM_Utils_Array::value('icon', $item),
         'extra' => CRM_Utils_Array::value('extra', $item),
@@ -355,7 +355,7 @@ class CRM_Core_Menu {
    * @return mixed
    * @throws Exception
    */
-  static function &getNavigation($all = FALSE) {
+  public static function &getNavigation($all = FALSE) {
     CRM_Core_Error::fatal();
 
     if (!self::$_menuCache) {
@@ -390,7 +390,8 @@ class CRM_Core_Menu {
     foreach ($values as $index => $item) {
       if (strpos(CRM_Utils_Array::value($config->userFrameworkURLVar, $_REQUEST),
           $item['path']
-        ) === 0) {
+        ) === 0
+      ) {
         $values[$index]['active'] = 'class="active"';
       }
       else {
@@ -421,7 +422,6 @@ class CRM_Core_Menu {
       }
     }
 
-
     if (!$all) {
       // remove all collapsed menu items from the array
       foreach ($values as $weight => $v) {
@@ -464,7 +464,7 @@ class CRM_Core_Menu {
   /**
    * @return null
    */
-  static function &getAdminLinks() {
+  public static function &getAdminLinks() {
     $links = self::get('admin');
 
     if (!$links ||
@@ -480,15 +480,16 @@ class CRM_Core_Menu {
   /**
    * Get the breadcrumb for a given path.
    *
-   * @param  array   $menu   An array of all the menu items.
-   * @param  string  $path   Path for which breadcrumb is to be build.
+   * @param array $menu
+   *   An array of all the menu items.
+   * @param string $path
+   *   Path for which breadcrumb is to be build.
    *
-   * @return array  The breadcrumb for this path
+   * @return array
+   *   The breadcrumb for this path
    *
-   * @static
-   * @access public
    */
-  static function buildBreadcrumb(&$menu, $path) {
+  public static function buildBreadcrumb(&$menu, $path) {
     $crumbs = array();
 
     $pathElements = explode('/', $path);
@@ -531,7 +532,7 @@ class CRM_Core_Menu {
    * @param $menu
    * @param $path
    */
-  static function buildReturnUrl(&$menu, $path) {
+  public 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);
     }
@@ -543,7 +544,7 @@ class CRM_Core_Menu {
    *
    * @return array
    */
-  static function getReturnUrl(&$menu, $path) {
+  public static function getReturnUrl(&$menu, $path) {
     if (!isset($menu[$path]['return_url'])) {
       $pathElements = explode('/', $path);
       array_pop($pathElements);
@@ -571,7 +572,7 @@ class CRM_Core_Menu {
    * @param $menu
    * @param $path
    */
-  static function fillComponentIds(&$menu, $path) {
+  public static function fillComponentIds(&$menu, $path) {
     static $cache = array();
 
     if (array_key_exists('component_id', $menu[$path])) {
@@ -609,7 +610,7 @@ class CRM_Core_Menu {
    *
    * @return null
    */
-  static function get($path) {
+  public static function get($path) {
     // return null if menu rebuild
     $config = CRM_Core_Config::singleton();
 
@@ -619,14 +620,14 @@ class CRM_Core_Menu {
 
     $elements = array();
     while (!empty($args)) {
-      $string     = implode('/', $args);
-      $string     = CRM_Core_DAO::escapeString($string);
+      $string = implode('/', $args);
+      $string = CRM_Core_DAO::escapeString($string);
       $elements[] = "'{$string}'";
       array_pop($args);
     }
 
-    $queryString       = implode(', ', $elements);
-    $domainID          = CRM_Core_Config::domainID();
+    $queryString = implode(', ', $elements);
+    $domainID = CRM_Core_Config::domainID();
     $domainWhereClause = " AND domain_id = $domainID ";
     if ($config->isUpgradeMode() &&
       !CRM_Core_DAO::checkFieldExists('civicrm_menu', 'domain_id')
@@ -699,7 +700,7 @@ UNION (
     // Once we have another example of a 'cleanup' we should generalize the clause below so it grabs string
     // which follows upgrade/ and checks for existence of a function in Cleanup class.
     if ($path == 'civicrm/upgrade/cleanup425') {
-      $menuPath['page_callback'] = array('CRM_Upgrade_Page_Cleanup','cleanup425');
+      $menuPath['page_callback'] = array('CRM_Upgrade_Page_Cleanup', 'cleanup425');
       $menuPath['access_arguments'][0][] = 'administer CiviCRM';
       $menuPath['access_callback'] = array('CRM_Core_Permission', 'checkMenu');
     }
@@ -716,7 +717,7 @@ UNION (
    *
    * @return mixed
    */
-  static function getArrayForPathArgs($pathArgs) {
+  public static function getArrayForPathArgs($pathArgs) {
     if (!is_string($pathArgs)) {
       return;
     }
@@ -738,12 +739,12 @@ UNION (
           $urlToSession[$count]['sessionVar'],
           $urlToSession[$count]['type'],
           $urlToSession[$count]['default']
-        ) = explode(':', $keyVal);
+          ) = explode(':', $keyVal);
         $count++;
       }
       $arr['urlToSession'] = $urlToSession;
     }
     return $arr;
   }
-}
 
+}