| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.6 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
| 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 |
| 33 | * @copyright CiviCRM LLC (c) 2004-2014 |
| 34 | * @version $Id: Group.php 30171 2010-10-14 09:11:27Z mover $ |
| 35 | */ |
| 36 | |
| 37 | /** |
| 38 | * Create/update group. |
| 39 | * |
| 40 | * @param array $params |
| 41 | * Associative array of property. |
| 42 | * name/value pairs to insert in new 'group' |
| 43 | * |
| 44 | * @return array |
| 45 | * API result array |
| 46 | */ |
| 47 | function civicrm_api3_group_create($params) { |
| 48 | return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Group'); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Adjust Metadata for Create action. |
| 53 | * |
| 54 | * The metadata is used for setting defaults, documentation & validation. |
| 55 | * |
| 56 | * @param array $params |
| 57 | * Array or parameters determined by getfields. |
| 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 | /** |
| 65 | * Returns array of groups matching a set of one or more group properties. |
| 66 | * |
| 67 | * @param array $params |
| 68 | * Array of one or more valid. |
| 69 | * property_name=>value pairs. If $params is set |
| 70 | * as null, all groups will be returned |
| 71 | * |
| 72 | * @return array |
| 73 | * Array of matching groups |
| 74 | */ |
| 75 | function civicrm_api3_group_get($params) { |
| 76 | $options = _civicrm_api3_get_options_from_params($params, TRUE, 'group', 'get'); |
| 77 | if (empty($options['return']) || !in_array('member_count', $options['return'])) { |
| 78 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Group'); |
| 79 | } |
| 80 | |
| 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'); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Delete an existing group. |
| 90 | * |
| 91 | * @param array $params |
| 92 | * Array containing id of the group. |
| 93 | * to be deleted |
| 94 | * |
| 95 | * @return array |
| 96 | * API result array |
| 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 | } |