Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2014-12-09-14-48-51
[civicrm-core.git] / api / v3 / Event.php
index 93eb30c93e6f6bce74697ae57f73aab6eaf916c9..3053bdd8a641d91f0030d9c04a27ae5c84770119 100644 (file)
@@ -62,22 +62,10 @@ function civicrm_api3_event_create($params) {
     $copy = CRM_Event_BAO_Event::copy($params['template_id']);
     $params['id'] = $copy->id;
     unset($params['template_id']);
-    if (empty($params['is_template'])) {
-      $params['is_template'] = 0;
-    }
   }
 
   _civicrm_api3_event_create_legacy_support_42($params);
-
-  //format custom fields so they can be added
-  $values = array();
-  _civicrm_api3_custom_format_params($params, $values, 'Event');
-  $params = array_merge($values, $params);
-
-  $eventBAO = CRM_Event_BAO_Event::create($params);
-  $event = array();
-  _civicrm_api3_object_to_array($eventBAO, $event[$eventBAO->id]);
-  return civicrm_api3_create_success($event, $params);
+  return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Event');
 }
 
 /**
@@ -91,6 +79,7 @@ function _civicrm_api3_event_create_spec(&$params) {
   $params['title']['api.required'] = 1;
   $params['is_active']['api.default'] = 1;
   $params['financial_type_id']['api.aliases'] = array('contribution_type_id');
+  $params['is_template']['api.default'] = 0;
 }
 
 /**
@@ -139,13 +128,6 @@ function civicrm_api3_event_get($params) {
   $eventDAO = new CRM_Event_BAO_Event();
   _civicrm_api3_dao_set_filter($eventDAO, $params, TRUE, 'Event');
 
-  if (!empty($params['is_template'])) {
-    $eventDAO->whereAdd( '( is_template = 1 )' );
-  }
-  elseif(empty($eventDAO->id)){
-    $eventDAO->whereAdd('( is_template IS NULL ) OR ( is_template = 0 )');
-  }
-
   if (!empty($params['isCurrent'])) {
     $eventDAO->whereAdd('(start_date >= CURDATE() || end_date >= CURDATE())');
   }
@@ -154,6 +136,8 @@ function civicrm_api3_event_get($params) {
   // the return.is_full to deal with.
   // NB the std dao_to_array function should only return custom if required.
   $event = array();
+  $options = _civicrm_api3_get_options_from_params($params);
+
   $eventDAO->find();
   while ($eventDAO->fetch()) {
     $event[$eventDAO->id] = array();
@@ -163,8 +147,10 @@ function civicrm_api3_event_get($params) {
     }
     _civicrm_api3_event_get_legacy_support_42($event, $eventDAO->id);
     _civicrm_api3_custom_data_get($event[$eventDAO->id], 'Event', $eventDAO->id, NULL, $eventDAO->event_type_id);
+    if(!empty($options['return'])) {
+      $event[$eventDAO->id]['price_set_id'] = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventDAO->id);
+    }
   }
-  //end of the loop
 
   return civicrm_api3_create_success($event, $params, 'event', 'get', $eventDAO);
 }
@@ -213,7 +199,7 @@ function civicrm_api3_event_delete($params) {
 /*
 
 /**
- * Function to add 'is_full' & 'available_seats' to the return array. (this might be better in the BAO)
+ * add 'is_full' & 'available_seats' to the return array. (this might be better in the BAO)
  * Default BAO function returns a string if full rather than a Bool - which is more appropriate to a form
  *
  * @param array $event return array of the event
@@ -222,7 +208,7 @@ function civicrm_api3_event_delete($params) {
  */
 /**
  * @param $event
- * @param $event_id
+ * @param int $event_id
  */
 function _civicrm_api3_event_getisfull(&$event, $event_id) {
   $eventFullResult = CRM_Event_BAO_Participant::eventFull($event_id, 1);