Merge pull request #3129 from ginkgomzd/CRM-14353-fixes
[civicrm-core.git] / api / v3 / Event.php
index 8990d1019ca9a49d03a4714e393bca9816f322d9..478d28460ed320780a6849698c1fda05a651e579 100644 (file)
@@ -2,9 +2,9 @@
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -33,7 +33,7 @@
  * @package CiviCRM_APIv3
  * @subpackage API_Event
  *
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * @version $Id: Event.php 30964 2010-11-29 09:41:54Z shot $
  *
  */
@@ -231,3 +231,50 @@ function _civicrm_api3_event_getisfull(&$event, $event_id) {
   $event[$event_id]['is_full'] = $event[$event_id]['available_places'] == 0 ? 1 : 0;
 }
 
+
+/**
+ * @see _civicrm_api3_generic_getlist_params.
+ *
+ * @param $request array
+ */
+function _civicrm_api3_event_getlist_params(&$request) {
+  $fieldsToReturn = array('start_date', 'event_type_id', 'title', 'summary');
+  $request['params']['return'] = array_unique(array_merge($fieldsToReturn, $request['extra']));
+  $request['params']['options']['sort'] = 'start_date DESC';
+  $request['params'] += array(
+    'is_template' => 0,
+    'is_active' => 1,
+  );
+}
+
+/**
+ * @see _civicrm_api3_generic_getlist_output
+ *
+ * @param $result array
+ * @param $request array
+ *
+ * @return array
+ */
+function _civicrm_api3_event_getlist_output($result, $request) {
+  $output = array();
+  if (!empty($result['values'])) {
+    foreach ($result['values'] as $row) {
+      $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'])),
+      );
+      if (!empty($row['start_date'])) {
+        $data['description'][0] .= ': ' . CRM_Utils_Date::customFormat($row['start_date']);
+      }
+      if (!empty($row['summary'])) {
+        $data['description'][] = $row['summary'];
+      }
+      foreach ($request['extra'] as $field) {
+        $data['extra'][$field] = isset($row[$field]) ? $row[$field] : NULL;
+      }
+      $output[] = $data;
+    }
+  }
+  return $output;
+}