Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-03-09-21-44-34
[civicrm-core.git] / CRM / Group / Page / AJAX.php
index 4b2aa2029b29f06135e37088fcf1b122ee9c558a..ce150a1422aa140ef1f41c01ed147134165ba779 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 class contains the functions that are called using AJAX (jQuery)
  */
 class CRM_Group_Page_AJAX {
-  static function getGroupList() {
+  /**
+   * Get list of groups.
+   *
+   * @return array
+   */
+  public static function getGroupList() {
     $params = $_REQUEST;
 
     if (isset($params['parent_id'])) {
       // requesting child groups for a given parent
       $params['page'] = 1;
-      $params['rp']   = 0;
+      $params['rp'] = 0;
       $groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
 
       CRM_Utils_JSON::output($groups);
     }
     else {
       $sortMapper = array(
-        0 => 'groups.title', 1 => 'count', 2 => 'createdBy.sort_name', 3 => '',
-        4 => 'groups.group_type', 5 => 'groups.visibility',
+        0 => 'groups.title',
+        1 => 'count',
+        2 => 'createdBy.sort_name',
+        3 => '',
+        4 => 'groups.group_type',
+        5 => 'groups.visibility',
       );
 
-      $sEcho     = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
-      $offset    = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
-      $rowCount  = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
-      $sort      = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
+      $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
+      $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
+      $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
+      $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
       $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
 
       if ($sort && $sortOrder) {
@@ -73,7 +82,7 @@ class CRM_Group_Page_AJAX {
       // go ahead with flat hierarchy, CRM-12225
       if (empty($groups)) {
         $groupsAccessible = CRM_Core_PseudoConstant::group();
-        $parentsOnly      = CRM_Utils_Array::value('parentsOnly', $params);
+        $parentsOnly = CRM_Utils_Array::value('parentsOnly', $params);
         if (!empty($groupsAccessible) && $parentsOnly) {
           // recompute group list with flat hierarchy
           $params['parentsOnly'] = 0;
@@ -83,17 +92,24 @@ class CRM_Group_Page_AJAX {
 
       $iFilteredTotal = $iTotal = $params['total'];
       $selectorElements = array(
-        'group_name', 'count', 'created_by', 'group_description',
-        'group_type', 'visibility', 'org_info', 'links', 'class',
+        'group_name',
+        'count',
+        'created_by',
+        'group_description',
+        'group_type',
+        'visibility',
+        'org_info',
+        'links',
+        'class',
       );
 
       if (empty($params['showOrgInfo'])) {
         unset($selectorElements[6]);
       }
-     //add setting so this can be tested by unit test
-     //@todo - ideally the portion of this that retrieves the groups should be extracted into a function separate
-     // from the one which deals with web inputs & outputs so we have a properly testable & re-usable function
-      if(!empty($params['is_unit_test'])) {
+      //add setting so this can be tested by unit test
+      //@todo - ideally the portion of this that retrieves the groups should be extracted into a function separate
+      // from the one which deals with web inputs & outputs so we have a properly testable & re-usable function
+      if (!empty($params['is_unit_test'])) {
         return array($groups, $iFilteredTotal);
       }
       header('Content-Type: application/json');
@@ -101,5 +117,5 @@ class CRM_Group_Page_AJAX {
       CRM_Utils_System::civiExit();
     }
   }
-}
 
+}