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
45 require_once 'CRM/Event/BAO/Event.php';
50 * This API is used for creating a Event
52 * @param array $params input parameters
53 * Allowed @params array keys are:
54 * {@getfields event_create}
56 * @return array API result Array.
59 function civicrm_api3_event_create($params) {
61 _civicrm_api3_event_create_legacy_support_42($params);
62 //format custom fields so they can be added
64 _civicrm_api3_custom_format_params($params, $values, 'Event');
65 $params = array_merge($values, $params);
66 require_once 'CRM/Event/BAO/Event.php';
68 $eventBAO = CRM_Event_BAO_Event
::create($params);
70 _civicrm_api3_object_to_array($eventBAO, $event[$eventBAO->id
]);
71 return civicrm_api3_create_success($event, $params);
75 * Adjust Metadata for Create action
77 * The metadata is used for setting defaults, documentation & validation
78 * @param array $params array or parameters determined by getfields
80 function _civicrm_api3_event_create_spec(&$params) {
81 $params['event_type_id']['api.required'] = 1;;
82 $params['start_date']['api.required'] = 1;
83 $params['title']['api.required'] = 1;
84 $params['is_active']['api.default'] = 1;
85 $params['financial_type_id']['api.aliases'] = array('contribution_type_id');
89 * Support for schema changes made in 4.2
90 * The main purpose of the API is to provide integrators a level of stability not provided by
91 * the core code or schema - this means we have to provide support for api calls (where possible)
92 * across schema changes.
94 function _civicrm_api3_event_create_legacy_support_42(&$params){
95 if(!empty($params['payment_processor_id'])){
96 $params['payment_processor'] = CRM_Core_DAO
::VALUE_SEPARATOR
. $params['payment_processor_id'] . CRM_Core_DAO
::VALUE_SEPARATOR
;
104 * @param array $params an associative array of name/value property values of civicrm_event
105 * {@getfields event_get}
107 * @return Array of all found event property values.
111 function civicrm_api3_event_get($params) {
113 //legacy support for $params['return.sort']
114 if (CRM_Utils_Array
::value('return.sort', $params)) {
115 $params['options']['sort'] = $params['return.sort'];
116 unset($params['return.sort']);
119 //legacy support for $params['return.sort']
120 if (CRM_Utils_Array
::value('return.offset', $params)) {
121 $params['options']['offset'] = $params['return.offset'];
122 unset($params['return.offset']);
125 //legacy support for $params['return.max_results']
126 if (CRM_Utils_Array
::value('return.max_results', $params)) {
127 $params['options']['limit'] = $params['return.max_results'];
128 unset($params['return.max_results']);
131 $eventDAO = new CRM_Event_BAO_Event();
132 _civicrm_api3_dao_set_filter($eventDAO, $params, TRUE, 'Event');
134 if (CRM_Utils_Array
::value('is_template', $params)) {
135 $eventDAO->whereAdd( '( is_template = 1 )' );
138 $eventDAO->whereAdd('( is_template IS NULL ) OR ( is_template = 0 )');
141 if (CRM_Utils_Array
::value('isCurrent', $params)) {
142 $eventDAO->whereAdd('(start_date >= CURDATE() || end_date >= CURDATE())');
145 // @todo should replace all this with _civicrm_api3_dao_to_array($bao, $params, FALSE, $entity) - but we still have
146 // the return.is_full to deal with.
147 // NB the std dao_to_array function should only return custom if required.
150 while ($eventDAO->fetch()) {
151 $event[$eventDAO->id
] = array();
152 CRM_Core_DAO
::storeValues($eventDAO, $event[$eventDAO->id
]);
153 if (CRM_Utils_Array
::value('return.is_full', $params)) {
154 _civicrm_api3_event_getisfull($event, $eventDAO->id
);
156 _civicrm_api3_event_get_legacy_support_42($event, $eventDAO->id
);
157 _civicrm_api3_custom_data_get($event[$eventDAO->id
], 'Event', $eventDAO->id
, NULL, $eventDAO->event_type_id
);
161 return civicrm_api3_create_success($event, $params, 'event', 'get', $eventDAO);
165 * Adjust Metadata for Get action
167 * The metadata is used for setting defaults, documentation & validation
168 * @param array $params array or parameters determined by getfields
170 function _civicrm_api3_event_get_spec(&$params) {
171 $params['financial_type_id']['api.aliases'] = array('contribution_type_id');
175 * Support for schema changes made in 4.2
176 * The main purpose of the API is to provide integrators a level of stability not provided by
177 * the core code or schema - this means we have to provide support for api calls (where possible)
178 * across schema changes.
180 function _civicrm_api3_event_get_legacy_support_42(&$event, $event_id){
181 if(!empty($event[$event_id]['payment_processor'])){
182 $processors = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,$event[$event_id]['payment_processor']);
183 if(count($processors) == 3 ){
184 $event[$event_id]['payment_processor_id'] = $processors[1];
190 * Deletes an existing event
192 * This API is used for deleting a event
194 * @param Array $params array containing event_id to be deleted
196 * @return boolean true if success, error otherwise
198 * note API has legacy support for 'event_id'
199 * {@getfields event_delete}
201 function civicrm_api3_event_delete($params) {
203 return CRM_Event_BAO_Event
::del($params['id']) ?
civicrm_api3_create_success() : civicrm_api3_create_error(ts('Error while deleting event'));
208 * Function to add 'is_full' & 'available_seats' to the return array. (this might be better in the BAO)
209 * Default BAO function returns a string if full rather than a Bool - which is more appropriate to a form
211 * @param array $event return array of the event
212 * @param int $event_id Id of the event to be updated
215 function _civicrm_api3_event_getisfull(&$event, $event_id) {
216 require_once 'CRM/Event/BAO/Participant.php';
217 $eventFullResult = CRM_Event_BAO_Participant
::eventFull($event_id, 1);
218 if (!empty($eventFullResult) && is_int($eventFullResult)) {
219 $event[$event_id]['available_places'] = $eventFullResult;
222 $event[$event_id]['available_places'] = 0;
224 $event[$event_id]['is_full'] = $event[$event_id]['available_places'] == 0 ?
1 : 0;