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 | * This class contains the functions that are called using AJAX (jQuery) | |
20 | */ | |
21 | class CRM_Group_Page_AJAX { | |
7e8c8317 | 22 | |
1cd3ffa9 EM |
23 | /** |
24 | * Get list of groups. | |
1cd3ffa9 | 25 | */ |
00be9182 | 26 | public static function getGroupList() { |
3b448eca | 27 | $params = $_GET; |
5c2ad8fb | 28 | if (isset($params['parent_id'])) { |
6a488035 | 29 | // requesting child groups for a given parent |
03e04002 | 30 | $params['page'] = 1; |
353ffa53 | 31 | $params['rp'] = 0; |
6a488035 | 32 | $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); |
7f0ee582 KJ |
33 | } |
34 | else { | |
be2fb01f CW |
35 | $requiredParams = []; |
36 | $optionalParams = [ | |
5b7b228c | 37 | 'title' => 'String', |
38 | 'created_by' => 'String', | |
39 | 'group_type' => 'String', | |
40 | 'visibility' => 'String', | |
fecb40f5 | 41 | 'component_mode' => 'String', |
5b7b228c | 42 | 'status' => 'Integer', |
d4b01b74 | 43 | 'parentsOnly' => 'Integer', |
44 | 'showOrgInfo' => 'Boolean', | |
5b7b228c | 45 | // Ignore 'parent_id' as that case is handled above |
be2fb01f | 46 | ]; |
5b7b228c | 47 | $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(); |
48 | $params += CRM_Core_Page_AJAX::validateParams($requiredParams, $optionalParams); | |
d4b01b74 | 49 | |
6a488035 TO |
50 | // get group list |
51 | $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); | |
52 | ||
8693efdb | 53 | // if no groups found with parent-child hierarchy and logged in user say can view child groups only (an ACL case), |
03e04002 | 54 | // go ahead with flat hierarchy, CRM-12225 |
8693efdb DS |
55 | if (empty($groups)) { |
56 | $groupsAccessible = CRM_Core_PseudoConstant::group(); | |
9c1bc317 | 57 | $parentsOnly = $params['parentsOnly'] ?? NULL; |
8693efdb DS |
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 | } | |
46d33c7a | 64 | } |
8693efdb | 65 | |
46d33c7a | 66 | CRM_Utils_JSON::output($groups); |
6a488035 | 67 | } |
96025800 | 68 | |
6a488035 | 69 | } |