Merge pull request #6345 from pradpnayak/CRM-15187
[civicrm-core.git] / api / v3 / Event.php
index 55cd7fe51f4c939ef6ea630b9ab9f53f538102b8..4728270b45361f3c8dcc16dd2cae943839d67647 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
 
 /**
  *
- * File for the CiviCRM APIv3 event functions
+ * This api exposes CiviCRM Event.
  *
  * @package CiviCRM_APIv3
- * @subpackage API_Event
- *
- * @copyright CiviCRM LLC (c) 2004-2014
- * @version $Id: Event.php 30964 2010-11-29 09:41:54Z shot $
- *
  */
 
 /**
- * Create a Event
- *
- * This API is used for creating a Event
+ * Create a Event.
  *
  * @param array $params
  *   Input parameters.
- *   Allowed @params array keys are:
- * {@getfields event_create}
  *
  * @return array
  *   API result Array.
@@ -65,11 +56,12 @@ function civicrm_api3_event_create($params) {
 }
 
 /**
- * Adjust Metadata for Create action
+ * Adjust Metadata for Create action.
+ *
+ * The metadata is used for setting defaults, documentation & validation.
  *
- * The metadata is used for setting defaults, documentation & validation
  * @param array $params
- *   Array or parameters determined by getfields.
+ *   Array of parameters determined by getfields.
  */
 function _civicrm_api3_event_create_spec(&$params) {
   $params['start_date']['api.required'] = 1;
@@ -80,10 +72,12 @@ function _civicrm_api3_event_create_spec(&$params) {
 }
 
 /**
- * Support for schema changes made in 4.2
+ * Support for schema changes made in 4.2.
+ *
  * The main purpose of the API is to provide integrators a level of stability not provided by
  * the core code or schema - this means we have to provide support for api calls (where possible)
  * across schema changes.
+ *
  * @param array $params
  */
 function _civicrm_api3_event_create_legacy_support_42(&$params) {
@@ -121,7 +115,7 @@ function civicrm_api3_event_get($params) {
   }
 
   $eventDAO = new CRM_Event_BAO_Event();
-  _civicrm_api3_dao_set_filter($eventDAO, $params, TRUE, 'Event');
+  _civicrm_api3_dao_set_filter($eventDAO, $params, TRUE);
 
   if (!empty($params['isCurrent'])) {
     $eventDAO->whereAdd('(start_date >= CURDATE() || end_date >= CURDATE())');
@@ -147,27 +141,30 @@ function civicrm_api3_event_get($params) {
     }
   }
 
-  return civicrm_api3_create_success($event, $params, 'event', 'get', $eventDAO);
+  return civicrm_api3_create_success($event, $params, 'Event', 'get', $eventDAO);
 }
 
 /**
- * Adjust Metadata for Get action
+ * Adjust Metadata for Get action.
+ *
+ * The metadata is used for setting defaults, documentation & validation.
  *
- * The metadata is used for setting defaults, documentation & validation
  * @param array $params
- *   Array or parameters determined by getfields.
+ *   Array of parameters determined by getfields.
  */
 function _civicrm_api3_event_get_spec(&$params) {
   $params['financial_type_id']['api.aliases'] = array('contribution_type_id');
 }
 
 /**
- * Support for schema changes made in 4.2
+ * Support for schema changes made in 4.2.
+ *
  * The main purpose of the API is to provide integrators a level of stability not provided by
  * the core code or schema - this means we have to provide support for api calls (where possible)
  * across schema changes.
- * @param $event
- * @param $event_id
+ *
+ * @param array $event
+ * @param int $event_id
  */
 function _civicrm_api3_event_get_legacy_support_42(&$event, $event_id) {
   if (!empty($event[$event_id]['payment_processor'])) {
@@ -179,31 +176,28 @@ function _civicrm_api3_event_get_legacy_support_42(&$event, $event_id) {
 }
 
 /**
- * Deletes an existing event
+ * Delete an existing Event.
  *
- * This API is used for deleting a event
+ * This API is used for deleting a event given its id.
  *
  * @param array $params
+ *
  * @return array
  */
 function civicrm_api3_event_delete($params) {
   return CRM_Event_BAO_Event::del($params['id']) ? civicrm_api3_create_success() : civicrm_api3_create_error(ts('Error while deleting event'));
 }
-/*
 
 /**
- * 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.
  * @param int $event_id
  *   Id of the event to be updated.
- *
- */
-/**
- * @param $event
- * @param int $event_id
  */
 function _civicrm_api3_event_getisfull(&$event, $event_id) {
   $eventFullResult = CRM_Event_BAO_Participant::eventFull($event_id, 1);
@@ -218,6 +212,8 @@ function _civicrm_api3_event_getisfull(&$event, $event_id) {
 
 
 /**
+ * Get event list parameters.
+ *
  * @see _civicrm_api3_generic_getlist_params
  *
  * @param array $request
@@ -233,6 +229,8 @@ function _civicrm_api3_event_getlist_params(&$request) {
 }
 
 /**
+ * Get event list output.
+ *
  * @see _civicrm_api3_generic_getlist_output
  *
  * @param array $result
@@ -247,7 +245,13 @@ function _civicrm_api3_event_getlist_output($result, $request) {
       $data = array(
         'id' => $row[$request['id_field']],
         'label' => $row[$request['label_field']],
-        'description' => array(CRM_Core_Pseudoconstant::getLabel('CRM_Event_BAO_Event', 'event_type_id', $row['event_type_id'])),
+        'description' => array(
+          CRM_Core_Pseudoconstant::getLabel(
+            'CRM_Event_BAO_Event',
+            'event_type_id',
+            $row['event_type_id']
+          ),
+        ),
       );
       if (!empty($row['start_date'])) {
         $data['description'][0] .= ': ' . CRM_Utils_Date::customFormat($row['start_date']);
@@ -255,8 +259,12 @@ function _civicrm_api3_event_getlist_output($result, $request) {
       if (!empty($row['summary'])) {
         $data['description'][] = $row['summary'];
       }
-      foreach ($request['extra'] as $field) {
-        $data['extra'][$field] = isset($row[$field]) ? $row[$field] : NULL;
+      // Add repeating info
+      $repeat = CRM_Core_BAO_RecurringEntity::getPositionAndCount($row['id'], 'civicrm_event');
+      $data['extra']['is_recur'] = FALSE;
+      if ($repeat) {
+        $data['suffix'] = ts('(%1 of %2)', array(1 => $repeat[0], 2 => $repeat[1]));
+        $data['extra']['is_recur'] = TRUE;
       }
       $output[] = $data;
     }