Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | * |
17 | */ | |
18 | ||
19 | /** | |
20 | * This class contains the functions that are called using AJAX (jQuery) | |
21 | */ | |
22 | class CRM_Group_Page_AJAX { | |
7e8c8317 | 23 | |
1cd3ffa9 EM |
24 | /** |
25 | * Get list of groups. | |
1cd3ffa9 | 26 | */ |
00be9182 | 27 | public static function getGroupList() { |
3b448eca | 28 | $params = $_GET; |
5c2ad8fb | 29 | if (isset($params['parent_id'])) { |
6a488035 | 30 | // requesting child groups for a given parent |
03e04002 | 31 | $params['page'] = 1; |
353ffa53 | 32 | $params['rp'] = 0; |
6a488035 | 33 | $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); |
7f0ee582 KJ |
34 | } |
35 | else { | |
be2fb01f CW |
36 | $requiredParams = []; |
37 | $optionalParams = [ | |
5b7b228c | 38 | 'title' => 'String', |
39 | 'created_by' => 'String', | |
40 | 'group_type' => 'String', | |
41 | 'visibility' => 'String', | |
fecb40f5 | 42 | 'component_mode' => 'String', |
5b7b228c | 43 | 'status' => 'Integer', |
d4b01b74 | 44 | 'parentsOnly' => 'Integer', |
45 | 'showOrgInfo' => 'Boolean', | |
5b7b228c | 46 | // Ignore 'parent_id' as that case is handled above |
be2fb01f | 47 | ]; |
5b7b228c | 48 | $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(); |
49 | $params += CRM_Core_Page_AJAX::validateParams($requiredParams, $optionalParams); | |
d4b01b74 | 50 | |
6a488035 TO |
51 | // get group list |
52 | $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); | |
53 | ||
8693efdb | 54 | // if no groups found with parent-child hierarchy and logged in user say can view child groups only (an ACL case), |
03e04002 | 55 | // go ahead with flat hierarchy, CRM-12225 |
8693efdb DS |
56 | if (empty($groups)) { |
57 | $groupsAccessible = CRM_Core_PseudoConstant::group(); | |
9c1bc317 | 58 | $parentsOnly = $params['parentsOnly'] ?? NULL; |
8693efdb DS |
59 | if (!empty($groupsAccessible) && $parentsOnly) { |
60 | // recompute group list with flat hierarchy | |
61 | $params['parentsOnly'] = 0; | |
62 | $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); | |
63 | } | |
64 | } | |
46d33c7a | 65 | } |
8693efdb | 66 | |
46d33c7a | 67 | if (!empty($_GET['is_unit_test'])) { |
68 | return $groups; | |
6a488035 | 69 | } |
46d33c7a | 70 | |
71 | CRM_Utils_JSON::output($groups); | |
6a488035 | 72 | } |
96025800 | 73 | |
6a488035 | 74 | } |