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 +--------------------------------------------------------------------+
32 * File for the CiviCRM APIv3 event functions
34 * @package CiviCRM_APIv3
35 * @subpackage API_Event
37 * @copyright CiviCRM LLC (c) 2004-2013
38 * @version $Id: Event.php 30964 2010-11-29 09:41:54Z shot $
43 * Files required for this package
49 * This API is used for creating a Event
51 * @param array $params input parameters
52 * Allowed @params array keys are:
53 * {@getfields event_create}
55 * @return array API result Array.
58 function civicrm_api3_event_create($params) {
59 civicrm_api3_verify_one_mandatory($params, NULL, array('event_type_id', 'template_id'));
61 // Clone event from template
62 if (!empty($params['template_id']) && empty($params['id'])) {
63 $copy = CRM_Event_BAO_Event
::copy($params['template_id']);
64 $params['id'] = $copy->id
;
65 unset($params['template_id']);
66 if (empty($params['is_template'])) {
67 $params['is_template'] = 0;
71 _civicrm_api3_event_create_legacy_support_42($params);
73 //format custom fields so they can be added
75 _civicrm_api3_custom_format_params($params, $values, 'Event');
76 $params = array_merge($values, $params);
78 $eventBAO = CRM_Event_BAO_Event
::create($params);
80 _civicrm_api3_object_to_array($eventBAO, $event[$eventBAO->id
]);
81 return civicrm_api3_create_success($event, $params);
85 * Adjust Metadata for Create action
87 * The metadata is used for setting defaults, documentation & validation
88 * @param array $params array or parameters determined by getfields
90 function _civicrm_api3_event_create_spec(&$params) {
91 $params['start_date']['api.required'] = 1;
92 $params['title']['api.required'] = 1;
93 $params['is_active']['api.default'] = 1;
94 $params['financial_type_id']['api.aliases'] = array('contribution_type_id');
98 * Support for schema changes made in 4.2
99 * The main purpose of the API is to provide integrators a level of stability not provided by
100 * the core code or schema - this means we have to provide support for api calls (where possible)
101 * across schema changes.
103 function _civicrm_api3_event_create_legacy_support_42(&$params){
104 if(!empty($params['payment_processor_id'])){
105 $params['payment_processor'] = CRM_Core_DAO
::VALUE_SEPARATOR
. $params['payment_processor_id'] . CRM_Core_DAO
::VALUE_SEPARATOR
;
113 * @param array $params an associative array of name/value property values of civicrm_event
114 * {@getfields event_get}
116 * @return Array of all found event property values.
120 function civicrm_api3_event_get($params) {
122 //legacy support for $params['return.sort']
123 if (CRM_Utils_Array
::value('return.sort', $params)) {
124 $params['options']['sort'] = $params['return.sort'];
125 unset($params['return.sort']);
128 //legacy support for $params['return.offset']
129 if (CRM_Utils_Array
::value('return.offset', $params)) {
130 $params['options']['offset'] = $params['return.offset'];
131 unset($params['return.offset']);
134 //legacy support for $params['return.max_results']
135 if (CRM_Utils_Array
::value('return.max_results', $params)) {
136 $params['options']['limit'] = $params['return.max_results'];
137 unset($params['return.max_results']);
140 $eventDAO = new CRM_Event_BAO_Event();
141 _civicrm_api3_dao_set_filter($eventDAO, $params, TRUE, 'Event');
143 if (CRM_Utils_Array
::value('is_template', $params)) {
144 $eventDAO->whereAdd( '( is_template = 1 )' );
146 elseif(empty($eventDAO->id
)){
147 $eventDAO->whereAdd('( is_template IS NULL ) OR ( is_template = 0 )');
150 if (CRM_Utils_Array
::value('isCurrent', $params)) {
151 $eventDAO->whereAdd('(start_date >= CURDATE() || end_date >= CURDATE())');
154 // @todo should replace all this with _civicrm_api3_dao_to_array($bao, $params, FALSE, $entity) - but we still have
155 // the return.is_full to deal with.
156 // NB the std dao_to_array function should only return custom if required.
159 while ($eventDAO->fetch()) {
160 $event[$eventDAO->id
] = array();
161 CRM_Core_DAO
::storeValues($eventDAO, $event[$eventDAO->id
]);
162 if (CRM_Utils_Array
::value('return.is_full', $params)) {
163 _civicrm_api3_event_getisfull($event, $eventDAO->id
);
165 _civicrm_api3_event_get_legacy_support_42($event, $eventDAO->id
);
166 _civicrm_api3_custom_data_get($event[$eventDAO->id
], 'Event', $eventDAO->id
, NULL, $eventDAO->event_type_id
);
170 return civicrm_api3_create_success($event, $params, 'event', 'get', $eventDAO);
174 * Adjust Metadata for Get action
176 * The metadata is used for setting defaults, documentation & validation
177 * @param array $params array or parameters determined by getfields
179 function _civicrm_api3_event_get_spec(&$params) {
180 $params['financial_type_id']['api.aliases'] = array('contribution_type_id');
184 * Support for schema changes made in 4.2
185 * The main purpose of the API is to provide integrators a level of stability not provided by
186 * the core code or schema - this means we have to provide support for api calls (where possible)
187 * across schema changes.
189 function _civicrm_api3_event_get_legacy_support_42(&$event, $event_id){
190 if(!empty($event[$event_id]['payment_processor'])){
191 $processors = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,$event[$event_id]['payment_processor']);
192 if(count($processors) == 3 ){
193 $event[$event_id]['payment_processor_id'] = $processors[1];
199 * Deletes an existing event
201 * This API is used for deleting a event
203 * @param Array $params array containing event_id to be deleted
205 * @return boolean true if success, error otherwise
207 * note API has legacy support for 'event_id'
208 * {@getfields event_delete}
210 function civicrm_api3_event_delete($params) {
212 return CRM_Event_BAO_Event
::del($params['id']) ?
civicrm_api3_create_success() : civicrm_api3_create_error(ts('Error while deleting event'));
217 * Function to add 'is_full' & 'available_seats' to the return array. (this might be better in the BAO)
218 * Default BAO function returns a string if full rather than a Bool - which is more appropriate to a form
220 * @param array $event return array of the event
221 * @param int $event_id Id of the event to be updated
224 function _civicrm_api3_event_getisfull(&$event, $event_id) {
225 $eventFullResult = CRM_Event_BAO_Participant
::eventFull($event_id, 1);
226 if (!empty($eventFullResult) && is_int($eventFullResult)) {
227 $event[$event_id]['available_places'] = $eventFullResult;
230 $event[$event_id]['available_places'] = 0;
232 $event[$event_id]['is_full'] = $event[$event_id]['available_places'] == 0 ?
1 : 0;