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