Icon cleanup
[civicrm-core.git] / CRM / Core / BAO / Navigation.php
index 3add358f1cabc7c1ab3b58fa1d0efbc735f8754a..ec1b4ddefada470dfc9b3053a745cd8fc913c064 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        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -38,34 +38,35 @@ class CRM_Core_BAO_Navigation extends CRM_Core_DAO_Navigation {
   const CACHE_KEY_STRLEN = 8;
 
   /**
-   * Class constructor
+   * Class constructor.
    */
-  function __construct() {
+  public function __construct() {
     parent::__construct();
   }
 
   /**
-   * Update the is_active flag in the db
+   * Update the is_active flag in the db.
    *
-   * @param int      $id        id of the database record
-   * @param boolean  $is_active value we want to set the is_active field
+   * @param int $id
+   *   Id of the database record.
+   * @param bool $is_active
+   *   Value we want to set the is_active field.
    *
-   * @return Object             DAO object on sucess, null otherwise
+   * @return Object
+   *   DAO object on sucess, NULL otherwise
    *
-   * @access public
-   * @static
    */
-  static function setIsActive($id, $is_active) {
+  public static function setIsActive($id, $is_active) {
     return CRM_Core_DAO::setFieldValue('CRM_Core_DAO_Navigation', $id, 'is_active', $is_active);
   }
 
   /**
    * Get existing / build navigation for CiviCRM Admin Menu
    *
-   * @static
-   * @return array associated array
+   * @return array
+   *   associated array
    */
-  static function getMenus() {
+  public static function getMenus() {
     $menus = array();
 
     $menu = new CRM_Core_DAO_Menu();
@@ -83,19 +84,19 @@ class CRM_Core_BAO_Navigation extends CRM_Core_DAO_Navigation {
   /**
    * Add/update navigation record
    *
-   * @param array associated array of submitted values
+   * @param $params associated array of submitted values
    *
-   * @return object navigation object
-   * @static
+   * @return object
+   *   navigation object
    */
-  static function add(&$params) {
+  public static function add(&$params) {
     $navigation = new CRM_Core_DAO_Navigation();
 
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
     $params['has_separator'] = CRM_Utils_Array::value('has_separator', $params, FALSE);
 
     if (!isset($params['id']) ||
-      (CRM_Utils_Array::value( 'parent_id', $params ) != CRM_Utils_Array::value('current_parent_id', $params))
+      (CRM_Utils_Array::value('parent_id', $params) != CRM_Utils_Array::value('current_parent_id', $params))
     ) {
       /* re/calculate the weight, if the Parent ID changed OR create new menu */
 
@@ -122,16 +123,17 @@ class CRM_Core_BAO_Navigation extends CRM_Core_DAO_Navigation {
   }
 
   /**
-   * Fetch object based on array of properties
+   * Fetch object based on array of properties.
    *
-   * @param array $params   (reference ) an assoc array of name/value pairs
-   * @param array $defaults (reference ) an assoc array to hold the flattened values
+   * @param array $params
+   *   (reference ) an assoc array of name/value pairs.
+   * @param array $defaults
+   *   (reference ) an assoc array to hold the flattened values.
    *
-   * @return CRM_Core_BAO_Navigation object on success, null otherwise
-   * @access public
-   * @static
+   * @return CRM_Core_BAO_Navigation|null
+   *   object on success, NULL otherwise
    */
-  static function retrieve(&$params, &$defaults) {
+  public static function retrieve(&$params, &$defaults) {
     $navigation = new CRM_Core_DAO_Navigation();
     $navigation->copyValues($params);
 
@@ -145,14 +147,17 @@ class CRM_Core_BAO_Navigation extends CRM_Core_DAO_Navigation {
   }
 
   /**
-   * Calculate navigation weight
+   * Calculate navigation weight.
    *
-   * @param $parentID parent_id of a menu
-   * @param $menuID  menu id
+   * @param int $parentID
+   *   Parent_id of a menu.
+   * @param int $menuID
+   *   Menu id.
    *
-   * @return int $weight string@static
+   * @return int
+   *   $weight string
    */
-  static function calculateWeight($parentID = NULL, $menuID = NULL) {
+  public static function calculateWeight($parentID = NULL, $menuID = NULL) {
     $domainID = CRM_Core_Config::domainID();
 
     $weight = 1;
@@ -172,12 +177,12 @@ class CRM_Core_BAO_Navigation extends CRM_Core_DAO_Navigation {
   }
 
   /**
-   * Get formatted menu list
+   * Get formatted menu list.
    *
-   * @return array $navigations returns associated array
-   * @static
+   * @return array
+   *   returns associated array
    */
-  static function getNavigationList() {
+  public static function getNavigationList() {
     $cacheKeyString = "navigationList";
     $whereClause = '';
 
@@ -213,11 +218,14 @@ FROM civicrm_navigation WHERE domain_id = $domainID {$whereClause} ORDER BY pare
   /**
    * Helper function for getNavigationList( )
    *
-   * @param array $list menu info
-   * @param array $navigations navigation menus
-   * @param string $separator  menu separator
+   * @param array $list
+   *   Menu info.
+   * @param array $navigations
+   *   Navigation menus.
+   * @param string $separator
+   *   Menu separator.
    */
-  static function _getNavigationLabel($list, &$navigations, $separator = '') {
+  public static function _getNavigationLabel($list, &$navigations, $separator = '') {
     $i18n = CRM_Core_I18n::singleton();
     foreach ($list as $label => $val) {
       if ($label == 'navigation_id') {
@@ -234,11 +242,13 @@ FROM civicrm_navigation WHERE domain_id = $domainID {$whereClause} ORDER BY pare
   /**
    * Helper function for getNavigationList( )
    *
-   * @param string $val menu name
-   * @param array $pidGroups parent menus
+   * @param string $val
+   *   Menu name.
+   * @param array $pidGroups
+   *   Parent menus.
    * @return array
    */
-  static function _getNavigationValue($val, &$pidGroups) {
+  public static function _getNavigationValue($val, &$pidGroups) {
     if (array_key_exists($val, $pidGroups)) {
       $list = array('navigation_id' => $val);
       foreach ($pidGroups[$val] as $label => $id) {
@@ -253,16 +263,19 @@ FROM civicrm_navigation WHERE domain_id = $domainID {$whereClause} ORDER BY pare
   }
 
   /**
-   * Build navigation tree
+   * Build navigation tree.
    *
-   * @param array   $navigationTree nested array of menus
-   * @param int     $parentID       parent id
-   * @param boolean $navigationMenu true when called for building top navigation menu
+   * @param array $navigationTree
+   *   Nested array of menus.
+   * @param int $parentID
+   *   Parent id.
+   * @param bool $navigationMenu
+   *   True when called for building top navigation menu.
    *
-   * @return array $navigationTree nested array of menus
-   * @static
+   * @return array
+   *   nested array of menus
    */
-  static function buildNavigationTree(&$navigationTree, $parentID, $navigationMenu = TRUE) {
+  public static function buildNavigationTree(&$navigationTree, $parentID, $navigationMenu = TRUE) {
     $whereClause = " parent_id IS NULL";
 
     if ($parentID) {
@@ -289,7 +302,8 @@ ORDER BY parent_id, weight";
 
       // for each menu get their children
       $navigationTree[$navigation->id] = array(
-        'attributes' => array('label' => $label,
+        'attributes' => array(
+          'label' => $label,
           'name' => $navigation->name,
           'url' => $navigation->url,
           'permission' => $navigation->permission,
@@ -298,7 +312,8 @@ ORDER BY parent_id, weight";
           'parentID' => $navigation->parent_id,
           'navID' => $navigation->id,
           'active' => $navigation->is_active,
-        ));
+        ),
+      );
       self::buildNavigationTree($navigationTree[$navigation->id]['child'], $navigation->id, $navigationMenu);
     }
 
@@ -306,15 +321,17 @@ ORDER BY parent_id, weight";
   }
 
   /**
-   * Build menu
+   * Build menu.
    *
-   * @param boolean $json by default output is html
-   * @param boolean $navigationMenu true when called for building top navigation menu
+   * @param bool $json
+   *   By default output is html.
+   * @param bool $navigationMenu
+   *   True when called for building top navigation menu.
    *
-   * @return returns html or json object
-   * @static
+   * @return string
+   *   html or json string
    */
-  static function buildNavigation($json = FALSE, $navigationMenu = TRUE) {
+  public static function buildNavigation($json = FALSE, $navigationMenu = TRUE) {
     $navigations = array();
     self::buildNavigationTree($navigations, $parent = NULL, $navigationMenu);
     $navigationString = NULL;
@@ -370,15 +387,15 @@ ORDER BY parent_id, weight";
   }
 
   /**
-   * Recursively check child menus
+   * Recursively check child menus.
    *
    * @param array $value
    * @param string $navigationString
-   * @param boolean $json
-   * @param boolean $skipMenuItems
+   * @param bool $json
+   * @param bool $skipMenuItems
    * @return string
    */
-  static function recurseNavigation(&$value, &$navigationString, $json, $skipMenuItems) {
+  public static function recurseNavigation(&$value, &$navigationString, $json, $skipMenuItems) {
     if ($json) {
       if (!empty($value['child'])) {
         $navigationString .= ', "children": [ ';
@@ -447,26 +464,26 @@ ORDER BY parent_id, weight";
   }
 
   /**
-   * Get Menu name
+   * Get Menu name.
    *
    * @param $value
    * @param array $skipMenuItems
    * @return bool|string
    */
-  static function getMenuName(&$value, &$skipMenuItems) {
+  public static function getMenuName(&$value, &$skipMenuItems) {
     // we need to localise the menu labels (CRM-5456) and don’t
     // want to use ts() as it would throw the ts-extractor off
     $i18n = CRM_Core_I18n::singleton();
 
-    $name       = $i18n->crm_translate($value['attributes']['label'], array('context' => 'menu'));
-    $url        = $value['attributes']['url'];
+    $name = $i18n->crm_translate($value['attributes']['label'], array('context' => 'menu'));
+    $url = $value['attributes']['url'];
     $permission = $value['attributes']['permission'];
-    $operator   = $value['attributes']['operator'];
-    $parentID   = $value['attributes']['parentID'];
-    $navID      = $value['attributes']['navID'];
-    $active     = $value['attributes']['active'];
-    $menuName   = $value['attributes']['name'];
-    $target     = CRM_Utils_Array::value('target', $value['attributes']);
+    $operator = $value['attributes']['operator'];
+    $parentID = $value['attributes']['parentID'];
+    $navID = $value['attributes']['navID'];
+    $active = $value['attributes']['active'];
+    $menuName = $value['attributes']['name'];
+    $target = CRM_Utils_Array::value('target', $value['attributes']);
 
     if (in_array($parentID, $skipMenuItems) || !$active) {
       $skipMenuItems[] = $navID;
@@ -475,7 +492,9 @@ ORDER BY parent_id, weight";
 
     //we need to check core view/edit or supported acls.
     if (in_array($menuName, array(
-      'Search...', 'Contacts'))) {
+      'Search...',
+      'Contacts',
+    ))) {
       if (!CRM_Core_Permission::giveMeAllACLs()) {
         $skipMenuItems[] = $navID;
         return FALSE;
@@ -559,14 +578,15 @@ ORDER BY parent_id, weight";
   }
 
   /**
-   * Create navigation for CiviCRM Admin Menu
+   * Create navigation for CiviCRM Admin Menu.
    *
-   * @param int $contactID contact id
+   * @param int $contactID
+   *   Contact id.
    *
-   * @return string $navigation returns navigation html
-   * @static
+   * @return string
+   *   returns navigation html
    */
-  static function createNavigation($contactID) {
+  public static function createNavigation($contactID) {
     $config = CRM_Core_Config::singleton();
 
     $navigation = self::buildNavigation();
@@ -579,7 +599,7 @@ ORDER BY parent_id, weight";
       // get home menu from db
       $homeParams = array('name' => 'Home');
       $homeNav = array();
-      $homeIcon = '<img src="' . $config->userFrameworkResourceURL . 'i/logo16px.png" style="vertical-align:middle;" />';
+      $homeIcon = '<span class="crm-logo-sm" ></span>';
       self::retrieve($homeParams, $homeNav);
       if ($homeNav) {
         list($path, $q) = explode('?', $homeNav['url']);
@@ -615,7 +635,7 @@ ORDER BY parent_id, weight";
           <ul id='civicrm-home'>
             <li><a href='$homeURL'>$homeLabel</a></li>
             <li><a href='#' class='crm-hidemenu'>$hideLabel</a></li>
-            <li><a href='$logoutURL' class='crm-logout-link'>". ts('Log out') ."</a></li>
+            <li><a href='$logoutURL' class='crm-logout-link'>" . ts('Log out') . "</a></li>
           </ul>";
       // <li> tag doesn't need to be closed
     }
@@ -623,12 +643,13 @@ ORDER BY parent_id, weight";
   }
 
   /**
-   * Reset navigation for all contacts or a specified contact
+   * Reset navigation for all contacts or a specified contact.
    *
-   * @param integer $contactID - reset only entries belonging to that contact ID
+   * @param int $contactID
+   *   Reset only entries belonging to that contact ID.
    * @return string
    */
-  static function resetNavigation($contactID = NULL) {
+  public static function resetNavigation($contactID = NULL) {
     $newKey = CRM_Utils_String::createRandom(self::CACHE_KEY_STRLEN, CRM_Utils_String::ALPHANUMERIC);
     if (!$contactID) {
       $query = "UPDATE civicrm_setting SET value = '$newKey' WHERE name='navigation' AND contact_id IS NOT NULL";
@@ -659,19 +680,19 @@ ORDER BY parent_id, weight";
   }
 
   /**
-   * Process navigation
+   * Process navigation.
    *
-   * @param array $params associated array, $_GET
+   * @param array $params
+   *   Associated array, $_GET.
    *
    * @return void
-   * @static
    */
-  static function processNavigation(&$params) {
-    $nodeID      = (int)str_replace("node_", "", $params['id']);
-    $referenceID = (int)str_replace("node_", "", $params['ref_id']);
-    $position    = $params['ps'];
-    $type        = $params['type'];
-    $label       = CRM_Utils_Array::value('data', $params);
+  public static function processNavigation(&$params) {
+    $nodeID = (int) str_replace("node_", "", $params['id']);
+    $referenceID = (int) str_replace("node_", "", $params['ref_id']);
+    $position = $params['ps'];
+    $type = $params['type'];
+    $label = CRM_Utils_Array::value('data', $params);
 
     switch ($type) {
       case "move":
@@ -693,16 +714,18 @@ ORDER BY parent_id, weight";
   }
 
   /**
-   * Process move action
+   * Process move action.
    *
-   * @param $nodeID node that is being moved
-   * @param $referenceID parent id where node is moved. 0 mean no parent
-   * @param $position new position of the nod, it starts with 0 - n
+   * @param $nodeID
+   *   Node that is being moved.
+   * @param $referenceID
+   *   Parent id where node is moved. 0 mean no parent.
+   * @param $position
+   *   New position of the nod, it starts with 0 - n.
    *
    * @return void
-   * @static
    */
-  static function processMove($nodeID, $referenceID, $position) {
+  public static function processMove($nodeID, $referenceID, $position) {
     // based on the new position we need to get the weight of the node after moved node
     // 1. update the weight of $position + 1 nodes to weight + 1
     // 2. weight of the ( $position -1 ) node - 1 is the new weight of the node being moved
@@ -719,15 +742,15 @@ ORDER BY parent_id, weight";
       $parentClause = 'parent_id IS NULL';
     }
 
-    $incrementOtherNodes = true;
-    $sql    = "SELECT weight from civicrm_navigation WHERE {$parentClause} ORDER BY weight LIMIT %1, 1";
-    $params = array(1 => array( $position, 'Positive'));
+    $incrementOtherNodes = TRUE;
+    $sql = "SELECT weight from civicrm_navigation WHERE {$parentClause} ORDER BY weight LIMIT %1, 1";
+    $params = array(1 => array($position, 'Positive'));
     $newWeight = CRM_Core_DAO::singleValueQuery($sql, $params);
 
     // this means node is moved to last position, so you need to get the weight of last element + 1
     if (!$newWeight) {
       $lastPosition = $position - 1;
-      $sql    = "SELECT weight from civicrm_navigation WHERE {$parentClause} ORDER BY weight LIMIT %1, 1";
+      $sql = "SELECT weight from civicrm_navigation WHERE {$parentClause} ORDER BY weight LIMIT %1, 1";
       $params = array(1 => array($lastPosition, 'Positive'));
       $newWeight = CRM_Core_DAO::singleValueQuery($sql, $params);
 
@@ -735,13 +758,13 @@ ORDER BY parent_id, weight";
       $newWeight = $newWeight + 1;
 
       // since this is a last node we don't need to increment other nodes
-      $incrementOtherNodes = false;
+      $incrementOtherNodes = FALSE;
     }
 
     $transaction = new CRM_Core_Transaction();
 
     // now update the existing nodes to weight + 1, if required.
-    if ( $incrementOtherNodes ) {
+    if ($incrementOtherNodes) {
       $query = "UPDATE civicrm_navigation SET weight = weight + 1
                   WHERE {$parentClause} AND weight >= {$newWeight}";
 
@@ -756,37 +779,38 @@ ORDER BY parent_id, weight";
   }
 
   /**
-   *  Function to process rename action for tree
+   *  Function to process rename action for tree.
    *
    * @param int $nodeID
    * @param $label
    */
-  static function processRename($nodeID, $label) {
+  public static function processRename($nodeID, $label) {
     CRM_Core_DAO::setFieldValue('CRM_Core_DAO_Navigation', $nodeID, 'label', $label);
   }
 
   /**
-   * Process delete action for tree
+   * Process delete action for tree.
    *
    * @param int $nodeID
    */
-  static function processDelete($nodeID) {
+  public static function processDelete($nodeID) {
     $query = "DELETE FROM civicrm_navigation WHERE id = {$nodeID}";
     CRM_Core_DAO::executeQuery($query);
   }
 
   /**
-   * Get the info on navigation item
+   * Get the info on navigation item.
    *
-   * @param int $navigationID  navigation id
+   * @param int $navigationID
+   *   Navigation id.
    *
-   * @return array associated array
-   * @static
+   * @return array
+   *   associated array
    */
-  static function getNavigationInfo($navigationID) {
-    $query  = "SELECT parent_id, weight FROM civicrm_navigation WHERE id = %1";
+  public static function getNavigationInfo($navigationID) {
+    $query = "SELECT parent_id, weight FROM civicrm_navigation WHERE id = %1";
     $params = array($navigationID, 'Integer');
-    $dao    = CRM_Core_DAO::executeQuery($query, array(1 => $params));
+    $dao = CRM_Core_DAO::executeQuery($query, array(1 => $params));
     $dao->fetch();
     return array(
       'parent_id' => $dao->parent_id,
@@ -795,13 +819,13 @@ ORDER BY parent_id, weight";
   }
 
   /**
-   * Update menu
+   * Update menu.
    *
-   * @param array  $params
-   * @param array  $newParams new value of params
-   * @static
+   * @param array $params
+   * @param array $newParams
+   *   New value of params.
    */
-  static function processUpdate($params, $newParams) {
+  public static function processUpdate($params, $newParams) {
     $dao = new CRM_Core_DAO_Navigation();
     $dao->copyValues($params);
     if ($dao->find(TRUE)) {
@@ -815,7 +839,7 @@ ORDER BY parent_id, weight";
    *
    * @return object|string
    */
-  static function getCacheKey($cid) {
+  public static function getCacheKey($cid) {
     $key = CRM_Core_BAO_Setting::getItem(
       CRM_Core_BAO_Setting::PERSONAL_PREFERENCES_NAME,
       'navigation',
@@ -828,5 +852,5 @@ ORDER BY parent_id, weight";
     }
     return $key;
   }
-}
 
+}