Merge pull request #6132 from colemanw/CRM-16795
[civicrm-core.git] / CRM / Utils / Sort.php
index e5b78d3bbbf0a7943e1ae96a8c0487f094e5a59e..22d7d1b68ff963934dbef1fe22adff67c46c8b24 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -41,7 +41,7 @@
  * if introducing additional functionality
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -55,12 +55,12 @@ class CRM_Utils_Sort {
    */
   const ASCENDING = 1, DESCENDING = 2, DONTCARE = 4,
 
-  /**
-   * The name for the sort GET/POST param
-   *
-   * @var string
-   */
-  SORT_ID = 'crmSID', SORT_DIRECTION = 'crmSortDirection', SORT_ORDER = 'crmSortOrder';
+    /**
+     * The name for the sort GET/POST param
+     *
+     * @var string
+     */
+    SORT_ID = 'crmSID', SORT_DIRECTION = 'crmSortDirection', SORT_ORDER = 'crmSortOrder';
 
   /**
    * Name of the sort function. Used to isolate session variables
@@ -116,11 +116,12 @@ class CRM_Utils_Sort {
    * key names of variable (which should be the same as the column name)
    * value: ascending or descending
    *
-   * @param mixed $vars - assoc array as described above
-   * @param string $defaultSortOrder - order to sort
+   * @param mixed $vars
+   *   Assoc array as described above.
+   * @param string $defaultSortOrder
+   *   Order to sort.
    *
    * @return \CRM_Utils_Sort
-  @access public
    */
   public function __construct(&$vars, $defaultSortOrder = NULL) {
     $this->_vars = array();
@@ -145,10 +146,10 @@ class CRM_Utils_Sort {
   }
 
   /**
-   * Function returns the string for the order by clause
+   * Function returns the string for the order by clause.
    *
-   * @return string the order by clause
-   * @access public
+   * @return string
+   *   the order by clause
    */
   public function orderBy() {
     if (empty($this->_vars[$this->_currentSortID])) {
@@ -168,26 +169,27 @@ class CRM_Utils_Sort {
   }
 
   /**
-   * Create the sortID string to be used in the GET param
+   * Create the sortID string to be used in the GET param.
    *
-   * @param int $index the field index
-   * @param int $dir   the direction of the sort
+   * @param int $index
+   *   The field index.
+   * @param int $dir
+   *   The direction of the sort.
    *
-   * @return string  the string to append to the url
-   * @static
-   * @access public
+   * @return string
+   *   the string to append to the url
    */
   public static function sortIDValue($index, $dir) {
     return ($dir == self::DESCENDING) ? $index . '_d' : $index . '_u';
   }
 
   /**
-   * Init the sort ID values in the object
+   * Init the sort ID values in the object.
    *
-   * @param string $defaultSortOrder the sort order to use by default
+   * @param string $defaultSortOrder
+   *   The sort order to use by default.
    *
-   * @return returns null if $url- (sort url) is not found
-   * @access public
+   * @return void
    */
   public function initSortID($defaultSortOrder) {
     $url = CRM_Utils_Array::value(self::SORT_ID, $_GET, $defaultSortOrder);
@@ -219,12 +221,12 @@ class CRM_Utils_Sort {
   }
 
   /**
-   * Init the object
+   * Init the object.
    *
-   * @param string $defaultSortOrder the sort order to use by default
+   * @param string $defaultSortOrder
+   *   The sort order to use by default.
    *
    * @return void
-   * @access public
    */
   public function initialize($defaultSortOrder) {
     $this->initSortID($defaultSortOrder);
@@ -255,9 +257,10 @@ class CRM_Utils_Sort {
   }
 
   /**
-   * Getter for currentSortID
+   * Getter for currentSortID.
    *
-   * @return int returns of the current sort id
+   * @return int
+   *   returns of the current sort id
    * @acccess public
    */
   public function getCurrentSortID() {
@@ -265,9 +268,10 @@ class CRM_Utils_Sort {
   }
 
   /**
-   * Getter for currentSortDirection
+   * Getter for currentSortDirection.
    *
-   * @return int returns of the current sort direction
+   * @return int
+   *   returns of the current sort direction
    * @acccess public
    */
   public function getCurrentSortDirection() {
@@ -280,8 +284,8 @@ class CRM_Utils_Sort {
    * @param $a
    * @param $b
    *
-   * @return int (-1 or 1)
-   * @access public
+   * @return int
+   *   (-1 or 1)
    */
   public static function cmpFunc($a, $b) {
     $cmp_order = array('weight', 'id', 'title', 'name');
@@ -289,7 +293,8 @@ class CRM_Utils_Sort {
       if (isset($a[$attribute]) && isset($b[$attribute])) {
         if ($a[$attribute] < $b[$attribute]) {
           return -1;
-        } elseif ($a[$attribute] > $b[$attribute]) {
+        }
+        elseif ($a[$attribute] > $b[$attribute]) {
           return 1;
         } // else: $a and $b are equal wrt to this attribute, try next...
       }
@@ -298,4 +303,5 @@ class CRM_Utils_Sort {
     // however, as I understand we don't want equality here:
     return -1;
   }
+
 }