5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
31 * File for the CiviCRM APIv2 group nesting functions
33 * @package CiviCRM_APIv2
34 * @subpackage API_Group
36 * @copyright CiviCRM LLC (c) 2004-2013
37 * @version $Id: GroupNesting.php 21624 2009-08-07 22:02:55Z wmorgan $
42 * Include utility functions
44 require_once 'api/v2/utils.php';
47 * Provides group nesting record(s) given parent and/or child id.
49 * @param array $params an array containing at least child_group_id or parent_group_id
51 * @return array list of group nesting records
53 function civicrm_group_nesting_get(&$params) {
54 _civicrm_initialize();
56 if (!is_array($params)) {
57 return civicrm_create_error('Params need to be of type array!');
60 if (!array_key_exists('child_group_id', $params) &&
61 !array_key_exists('parent_group_id', $params)
63 return civicrm_create_error(ts('At least one of child_group_id or parent_group_id is a required field'));
66 require_once 'CRM/Contact/DAO/GroupNesting.php';
67 $dao = new CRM_Contact_DAO_GroupNesting();
68 if (array_key_exists('child_group_id', $params)) {
69 $dao->child_group_id
= $params['child_group_id'];
71 if (array_key_exists('parent_group_id', $params)) {
72 $dao->parent_group_id
= $params['parent_group_id'];
78 while ($dao->fetch()) {
80 _civicrm_object_to_array($dao, $temp);
81 $values[$dao->id
] = $temp;
83 $values['is_error'] = 0;
86 return civicrm_create_error('No records found.');
93 * Creates group nesting record for given parent and child id.
94 * Parent and child groups need to exist.
96 * @param array &$params parameters array - allowed array keys include:
97 * {@schema Contact/GroupNesting.xml}
101 * @todo Work out the return value.
103 function civicrm_group_nesting_create(&$params) {
105 if (!is_array($params)) {
106 return civicrm_create_error('Params need to be of type array!');
109 require_once 'CRM/Contact/BAO/GroupNesting.php';
111 if (!array_key_exists('child_group_id', $params) &&
112 !array_key_exists('parent_group_id', $params)
114 return civicrm_create_error(ts('You need to define parent_group_id and child_group_id in params.'));
117 CRM_Contact_BAO_GroupNesting
::add($params['parent_group_id'], $params['child_group_id']);
119 // FIXME: CRM_Contact_BAO_GroupNesting requires some work
120 $result = array('is_error' => 0);
125 * Removes specific nesting records.
127 * @param array &$params parameters array - allowed array keys include:
128 * {@schema Contact/GroupNesting.xml}
132 * @todo Work out the return value.
134 function civicrm_group_nesting_remove(&$params) {
136 if (!is_array($params)) {
137 return civicrm_create_error('Params need to be of type array!');
140 if (!array_key_exists('child_group_id', $params) ||
141 !array_key_exists('parent_group_id', $params)
143 return civicrm_create_error(ts('You need to define parent_group_id and child_group_id in params.'));
146 require_once 'CRM/Contact/DAO/GroupNesting.php';
147 $dao = new CRM_Contact_DAO_GroupNesting();
148 $dao->copyValues($params);
150 if ($dao->delete()) {
151 $result = array('is_error' => 0);