Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
731a0992 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * File for the CiviCRM APIv3 group functions | |
30 | * | |
31 | * @package CiviCRM_APIv3 | |
32 | * @subpackage API_Group | |
731a0992 | 33 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
34 | * @version $Id: Group.php 30171 2010-10-14 09:11:27Z mover $ |
35 | */ | |
36 | ||
6a488035 | 37 | /** |
22242c87 | 38 | * Create/update group. |
6a488035 | 39 | * |
cf470720 TO |
40 | * @param array $params |
41 | * Associative array of property. | |
6a488035 TO |
42 | * name/value pairs to insert in new 'group' |
43 | * | |
a6c01b45 | 44 | * @return array |
72b3a70c | 45 | * API result array |
6a488035 TO |
46 | */ |
47 | function civicrm_api3_group_create($params) { | |
e34ab426 | 48 | return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Group'); |
6a488035 | 49 | } |
11e09c59 TO |
50 | |
51 | /** | |
0aa0303c EM |
52 | * Adjust Metadata for Create action. |
53 | * | |
54 | * The metadata is used for setting defaults, documentation & validation. | |
6a488035 | 55 | * |
cf470720 TO |
56 | * @param array $params |
57 | * Array or parameters determined by getfields. | |
6a488035 TO |
58 | */ |
59 | function _civicrm_api3_group_create_spec(&$params) { | |
60 | $params['is_active']['api.default'] = 1; | |
61 | $params['title']['api.required'] = 1; | |
62 | } | |
63 | ||
64 | /** | |
22242c87 | 65 | * Returns array of groups matching a set of one or more group properties. |
6a488035 | 66 | * |
cf470720 TO |
67 | * @param array $params |
68 | * Array of one or more valid. | |
6a488035 TO |
69 | * property_name=>value pairs. If $params is set |
70 | * as null, all groups will be returned | |
71 | * | |
a6c01b45 | 72 | * @return array |
72b3a70c | 73 | * Array of matching groups |
6a488035 TO |
74 | */ |
75 | function civicrm_api3_group_get($params) { | |
e34ab426 | 76 | $options = _civicrm_api3_get_options_from_params($params, TRUE, 'group', 'get'); |
22e263ad | 77 | if (empty($options['return']) || !in_array('member_count', $options['return'])) { |
e34ab426 | 78 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Group'); |
6a488035 TO |
79 | } |
80 | ||
e34ab426 EM |
81 | $groups = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE, 'Group'); |
82 | foreach ($groups as $id => $group) { | |
83 | $groups[$id]['member_count'] = CRM_Contact_BAO_Group::memberCount($id); | |
84 | } | |
85 | return civicrm_api3_create_success($groups, $params, 'group', 'get'); | |
6a488035 TO |
86 | } |
87 | ||
88 | /** | |
22242c87 | 89 | * Delete an existing group. |
6a488035 | 90 | * |
cf470720 TO |
91 | * @param array $params |
92 | * Array containing id of the group. | |
6a488035 TO |
93 | * to be deleted |
94 | * | |
a6c01b45 | 95 | * @return array |
72b3a70c | 96 | * API result array |
6a488035 TO |
97 | */ |
98 | function civicrm_api3_group_delete($params) { | |
99 | ||
100 | CRM_Contact_BAO_Group::discard($params['id']); | |
101 | return civicrm_api3_create_success(TRUE); | |
102 | } |