Merge pull request #17880 from colemanw/headerComments
[civicrm-core.git] / CRM / Group / Page / AJAX.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class contains the functions that are called using AJAX (jQuery)
20 */
21 class CRM_Group_Page_AJAX {
22
23 /**
24 * Get list of groups.
25 */
26 public static function getGroupList() {
27 $params = $_GET;
28 if (isset($params['parent_id'])) {
29 // requesting child groups for a given parent
30 $params['page'] = 1;
31 $params['rp'] = 0;
32 $groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
33 }
34 else {
35 $requiredParams = [];
36 $optionalParams = [
37 'title' => 'String',
38 'created_by' => 'String',
39 'group_type' => 'String',
40 'visibility' => 'String',
41 'component_mode' => 'String',
42 'status' => 'Integer',
43 'parentsOnly' => 'Integer',
44 'showOrgInfo' => 'Boolean',
45 // Ignore 'parent_id' as that case is handled above
46 ];
47 $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
48 $params += CRM_Core_Page_AJAX::validateParams($requiredParams, $optionalParams);
49
50 // get group list
51 $groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
52
53 // if no groups found with parent-child hierarchy and logged in user say can view child groups only (an ACL case),
54 // go ahead with flat hierarchy, CRM-12225
55 if (empty($groups)) {
56 $groupsAccessible = CRM_Core_PseudoConstant::group();
57 $parentsOnly = $params['parentsOnly'] ?? NULL;
58 if (!empty($groupsAccessible) && $parentsOnly) {
59 // recompute group list with flat hierarchy
60 $params['parentsOnly'] = 0;
61 $groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
62 }
63 }
64 }
65
66 CRM_Utils_JSON::output($groups);
67 }
68
69 }