Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | // $Id: UFJoin.php 45502 2013-02-08 13:32:55Z kurund $ | |
3 | ||
4 | ||
5 | /* | |
6 | +--------------------------------------------------------------------+ | |
7 | | CiviCRM version 4.3 | | |
8 | +--------------------------------------------------------------------+ | |
9 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
10 | +--------------------------------------------------------------------+ | |
11 | | This file is a part of CiviCRM. | | |
12 | | | | |
13 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
14 | | under the terms of the GNU Affero General Public License | | |
15 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
16 | | | | |
17 | | CiviCRM is distributed in the hope that it will be useful, but | | |
18 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
19 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
20 | | See the GNU Affero General Public License for more details. | | |
21 | | | | |
22 | | You should have received a copy of the GNU Affero General Public | | |
23 | | License and the CiviCRM Licensing Exception along | | |
24 | | with this program; if not, contact CiviCRM LLC | | |
25 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
26 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
27 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
28 | +--------------------------------------------------------------------+ | |
29 | */ | |
30 | ||
31 | /** | |
32 | * File for the CiviCRM APIv2 user framework join functions | |
33 | * | |
34 | * @package CiviCRM_APIv2 | |
35 | * @subpackage API_UF | |
36 | * | |
37 | * @copyright CiviCRM LLC (c) 2004-2013 | |
38 | * @version $Id: UFJoin.php 45502 2013-02-08 13:32:55Z kurund $ | |
39 | * | |
40 | */ | |
41 | ||
42 | /** | |
43 | * Files required for this package | |
44 | */ | |
45 | require_once 'api/v2/utils.php'; | |
46 | ||
47 | require_once 'CRM/Core/BAO/UFJoin.php'; | |
48 | ||
49 | /** | |
50 | * takes an associative array and creates a uf join array | |
51 | * | |
52 | * @param array $params assoc array of name/value pairs | |
53 | * | |
54 | * @return array CRM_Core_DAO_UFJoin Array | |
55 | * @access public | |
56 | * | |
57 | */ | |
58 | function civicrm_uf_join_add($params) { | |
59 | if (!is_array($params)) { | |
60 | return civicrm_create_error("params is not an array"); | |
61 | } | |
62 | ||
63 | if (empty($params)) { | |
64 | return civicrm_create_error("params is an empty array"); | |
65 | } | |
66 | ||
67 | if (!isset($params['uf_group_id'])) { | |
68 | return civicrm_create_error("uf_group_id is required field"); | |
69 | } | |
70 | ||
71 | $ufJoin = CRM_Core_BAO_UFJoin::create($params); | |
72 | _civicrm_object_to_array($ufJoin, $ufJoinArray); | |
73 | return $ufJoinArray; | |
74 | } | |
75 | ||
76 | /** | |
77 | * takes an associative array and updates a uf join array | |
78 | * | |
79 | * @param array $params assoc array of name/value pairs | |
80 | * | |
81 | * @return array updated CRM_Core_DAO_UFJoin Array | |
82 | * @access public | |
83 | * | |
84 | */ | |
85 | function civicrm_uf_join_edit($params) { | |
86 | if (!is_array($params)) { | |
87 | return civicrm_create_error("params is not an array"); | |
88 | } | |
89 | ||
90 | if (empty($params)) { | |
91 | return civicrm_create_error("params is an empty array"); | |
92 | } | |
93 | ||
94 | if (!isset($params['uf_group_id'])) { | |
95 | return civicrm_create_error("uf_group_id is required field"); | |
96 | } | |
97 | ||
98 | $ufJoin = CRM_Core_BAO_UFJoin::create($params); | |
99 | _civicrm_object_to_array($ufJoin, $ufJoinArray); | |
100 | return $ufJoinArray; | |
101 | } | |
102 | ||
103 | /** | |
104 | * Given an assoc list of params, finds if there is a record | |
105 | * for this set of params | |
106 | * | |
107 | * @param array $params (reference) an assoc array of name/value pairs | |
108 | * | |
109 | * @return int or null | |
110 | * @access public | |
111 | * | |
112 | */ | |
113 | function civicrm_uf_join_id_find(&$params) { | |
114 | if (!is_array($params) || empty($params)) { | |
115 | return civicrm_create_error("$params is not valid array"); | |
116 | } | |
117 | ||
118 | if (!isset($params['id']) && | |
119 | (!isset($params['entity_table']) && | |
120 | !isset($params['entity_id']) && | |
121 | !isset($params['weight']) | |
122 | ) | |
123 | ) { | |
124 | return civicrm_create_error("$param should have atleast entity_table or entiy_id or weight"); | |
125 | } | |
126 | ||
127 | return CRM_Core_BAO_UFJoin::findJoinEntryId($params); | |
128 | } | |
129 | ||
130 | /** | |
131 | * Given an assoc list of params, find if there is a record | |
132 | * for this set of params and return the group id | |
133 | * | |
134 | * @param array $params (reference) an assoc array of name/value pairs | |
135 | * | |
136 | * @return int or null | |
137 | * @access public | |
138 | * | |
139 | */ | |
140 | function civicrm_uf_join_UFGroupId_find(&$params) { | |
141 | if (!is_array($params) || empty($params)) { | |
142 | return civicrm_create_error("$params is not valid array"); | |
143 | } | |
144 | ||
145 | if (!isset($params['entity_table']) && | |
146 | !isset($params['entity_id']) && | |
147 | !isset($params['weight']) | |
148 | ) { | |
149 | return civicrm_create_error("$param should have atleast entity_table or entiy_id or weight"); | |
150 | } | |
151 | ||
152 | return CRM_Core_BAO_UFJoin::findUFGroupId($params); | |
153 | } | |
154 |