Merge pull request #4896 from totten/master-movedep
[civicrm-core.git] / api / v3 / GroupNesting.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
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 nesting functions
31 *
32 * @package CiviCRM_APIv3
33 * @subpackage API_Group
34 *
35 * @copyright CiviCRM LLC (c) 2004-2014
36 * @version $Id: GroupNesting.php 21624 2009-08-07 22:02:55Z wmorgan $
37 *
38 */
39
40 /**
41 * Provides group nesting record(s) given parent and/or child id.
42 *
43 * @param array $params
44 * An array containing at least child_group_id or parent_group_id.
45 * {@getfields GroupNesting_get}
46 *
47 * @return array
48 * list of group nesting records
49 */
50 function civicrm_api3_group_nesting_get($params) {
51
52 return _civicrm_api3_basic_get('CRM_Contact_DAO_GroupNesting', $params);
53 }
54
55 /**
56 * Creates group nesting record for given parent and child id.
57 * Parent and child groups need to exist.
58 *
59 * @param array $params
60 * Parameters array - allowed array keys include:.
61 *
62 * @return array
63 * TBD
64 * {@getfields GroupNesting_create
65 * @todo Work out the return value.
66 */
67 function civicrm_api3_group_nesting_create($params) {
68
69 CRM_Contact_BAO_GroupNesting::add($params['parent_group_id'], $params['child_group_id']);
70
71 // FIXME: CRM_Contact_BAO_GroupNesting requires some work
72 $result = array('is_error' => 0);
73 return civicrm_api3_create_success($result, $params);
74 }
75
76 /**
77 * Adjust Metadata for Create action
78 *
79 * The metadata is used for setting defaults, documentation & validation
80 * @param array $params
81 * Array or parameters determined by getfields.
82 */
83 function _civicrm_api3_group_nesting_create_spec(&$params) {
84 $params['child_group_id']['api.required'] = 1;
85 $params['parent_group_id']['api.required'] = 1;
86 }
87
88 /**
89 * Removes specific nesting records.
90 *
91 * @param array $params
92 * Parameters array - allowed array keys include:.
93 * {@getfields GroupNesting_delete}
94 *
95 * @return array
96 * API Success or fail array
97 *
98 * @todo Work out the return value.
99 */
100 function civicrm_api3_group_nesting_delete($params) {
101
102 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
103 }