4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * File for the CiviCRM APIv3 event functions
33 * @package CiviCRM_APIv3
34 * @subpackage API_Event
36 * @copyright CiviCRM LLC (c) 2004-2013
37 * @version $Id: Event.php 30964 2010-11-29 09:41:54Z shot $
42 * Files required for this package
48 * This API is used for creating a Event
50 * @param array $params input parameters
51 * Allowed @params array keys are:
52 * {@getfields event_create}
54 * @return array API result Array.
57 function civicrm_api3_event_create($params) {
58 civicrm_api3_verify_one_mandatory($params, NULL, array('event_type_id', 'template_id'));
60 // Clone event from template
61 if (!empty($params['template_id']) && empty($params['id'])) {
62 $copy = CRM_Event_BAO_Event
::copy($params['template_id']);
63 $params['id'] = $copy->id
;
64 unset($params['template_id']);
65 if (empty($params['is_template'])) {
66 $params['is_template'] = 0;
70 _civicrm_api3_event_create_legacy_support_42($params);
72 //format custom fields so they can be added
74 _civicrm_api3_custom_format_params($params, $values, 'Event');
75 $params = array_merge($values, $params);
77 $eventBAO = CRM_Event_BAO_Event
::create($params);
79 _civicrm_api3_object_to_array($eventBAO, $event[$eventBAO->id
]);
80 return civicrm_api3_create_success($event, $params);
84 * Adjust Metadata for Create action
86 * The metadata is used for setting defaults, documentation & validation
87 * @param array $params array or parameters determined by getfields
89 function _civicrm_api3_event_create_spec(&$params) {
90 $params['start_date']['api.required'] = 1;
91 $params['title']['api.required'] = 1;
92 $params['is_active']['api.default'] = 1;
93 $params['financial_type_id']['api.aliases'] = array('contribution_type_id');
97 * Support for schema changes made in 4.2
98 * The main purpose of the API is to provide integrators a level of stability not provided by
99 * the core code or schema - this means we have to provide support for api calls (where possible)
100 * across schema changes.
102 function _civicrm_api3_event_create_legacy_support_42(&$params){
103 if(!empty($params['payment_processor_id'])){
104 $params['payment_processor'] = CRM_Core_DAO
::VALUE_SEPARATOR
. $params['payment_processor_id'] . CRM_Core_DAO
::VALUE_SEPARATOR
;
112 * @param array $params an associative array of name/value property values of civicrm_event
113 * {@getfields event_get}
115 * @return Array of all found event property values.
119 function civicrm_api3_event_get($params) {
121 //legacy support for $params['return.sort']
122 if (CRM_Utils_Array
::value('return.sort', $params)) {
123 $params['options']['sort'] = $params['return.sort'];
124 unset($params['return.sort']);
127 //legacy support for $params['return.offset']
128 if (CRM_Utils_Array
::value('return.offset', $params)) {
129 $params['options']['offset'] = $params['return.offset'];
130 unset($params['return.offset']);
133 //legacy support for $params['return.max_results']
134 if (CRM_Utils_Array
::value('return.max_results', $params)) {
135 $params['options']['limit'] = $params['return.max_results'];
136 unset($params['return.max_results']);
139 $eventDAO = new CRM_Event_BAO_Event();
140 _civicrm_api3_dao_set_filter($eventDAO, $params, TRUE, 'Event');
142 if (CRM_Utils_Array
::value('is_template', $params)) {
143 $eventDAO->whereAdd( '( is_template = 1 )' );
145 elseif(empty($eventDAO->id
)){
146 $eventDAO->whereAdd('( is_template IS NULL ) OR ( is_template = 0 )');
149 if (CRM_Utils_Array
::value('isCurrent', $params)) {
150 $eventDAO->whereAdd('(start_date >= CURDATE() || end_date >= CURDATE())');
153 // @todo should replace all this with _civicrm_api3_dao_to_array($bao, $params, FALSE, $entity) - but we still have
154 // the return.is_full to deal with.
155 // NB the std dao_to_array function should only return custom if required.
158 while ($eventDAO->fetch()) {
159 $event[$eventDAO->id
] = array();
160 CRM_Core_DAO
::storeValues($eventDAO, $event[$eventDAO->id
]);
161 if (CRM_Utils_Array
::value('return.is_full', $params)) {
162 _civicrm_api3_event_getisfull($event, $eventDAO->id
);
164 _civicrm_api3_event_get_legacy_support_42($event, $eventDAO->id
);
165 _civicrm_api3_custom_data_get($event[$eventDAO->id
], 'Event', $eventDAO->id
, NULL, $eventDAO->event_type_id
);
169 return civicrm_api3_create_success($event, $params, 'event', 'get', $eventDAO);
173 * Adjust Metadata for Get action
175 * The metadata is used for setting defaults, documentation & validation
176 * @param array $params array or parameters determined by getfields
178 function _civicrm_api3_event_get_spec(&$params) {
179 $params['financial_type_id']['api.aliases'] = array('contribution_type_id');
183 * Support for schema changes made in 4.2
184 * The main purpose of the API is to provide integrators a level of stability not provided by
185 * the core code or schema - this means we have to provide support for api calls (where possible)
186 * across schema changes.
188 function _civicrm_api3_event_get_legacy_support_42(&$event, $event_id){
189 if(!empty($event[$event_id]['payment_processor'])){
190 $processors = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,$event[$event_id]['payment_processor']);
191 if(count($processors) == 3 ){
192 $event[$event_id]['payment_processor_id'] = $processors[1];
198 * Deletes an existing event
200 * This API is used for deleting a event
202 * @param Array $params array containing event_id to be deleted
204 * @return boolean true if success, error otherwise
206 * note API has legacy support for 'event_id'
207 * {@getfields event_delete}
209 function civicrm_api3_event_delete($params) {
211 return CRM_Event_BAO_Event
::del($params['id']) ?
civicrm_api3_create_success() : civicrm_api3_create_error(ts('Error while deleting event'));
216 * Function to add 'is_full' & 'available_seats' to the return array. (this might be better in the BAO)
217 * Default BAO function returns a string if full rather than a Bool - which is more appropriate to a form
219 * @param array $event return array of the event
220 * @param int $event_id Id of the event to be updated
223 function _civicrm_api3_event_getisfull(&$event, $event_id) {
224 $eventFullResult = CRM_Event_BAO_Participant
::eventFull($event_id, 1);
225 if (!empty($eventFullResult) && is_int($eventFullResult)) {
226 $event[$event_id]['available_places'] = $eventFullResult;
229 $event[$event_id]['available_places'] = 0;
231 $event[$event_id]['is_full'] = $event[$event_id]['available_places'] == 0 ?
1 : 0;