CRM-13966 - Migrate event id to select2
authorColeman Watts <coleman@civicrm.org>
Sat, 22 Feb 2014 17:13:36 +0000 (12:13 -0500)
committerColeman Watts <coleman@civicrm.org>
Tue, 25 Feb 2014 14:27:42 +0000 (09:27 -0500)
CRM/Event/BAO/Query.php
CRM/Event/Form/ManageEvent/Conference.php
CRM/Event/Page/AJAX.php
CRM/Event/xml/Menu/Event.xml
api/v3/Event.php
templates/CRM/Event/Form/ManageEvent/Conference.tpl
templates/CRM/Event/Form/Search/Common.tpl

index 193776249e629c0033f733e577d0f87c10a3e7d4..520773f1523d05ed92490484f086c73ef12e5734 100644 (file)
@@ -543,24 +543,19 @@ class CRM_Event_BAO_Query {
    * @param CRM_Core_Form $form
    */
   static function buildSearchForm(&$form) {
-    $dataURLEvent = CRM_Utils_System::url('civicrm/ajax/event',
-      "reset=1",
-      FALSE, NULL, FALSE
-    );
-    $dataURLEventType = CRM_Utils_System::url('civicrm/ajax/eventType',
-      "reset=1",
-      FALSE, NULL, FALSE
-    );
     $dataURLEventFee = CRM_Utils_System::url('civicrm/ajax/eventFee',
       "reset=1",
       FALSE, NULL, FALSE
     );
 
-    $form->assign('dataURLEvent', $dataURLEvent);
-    $form->assign('dataURLEventType', $dataURLEventType);
     $form->assign('dataURLEventFee', $dataURLEventFee);
 
-    $eventId        = &$form->add('text', 'event_name', ts('Event Name'));
+    $eventId = $form->addEntityRef('event_id', ts('Event Name'), array(
+        'entity' => 'event',
+        'placeholder' => ts('- any -'),
+        'select' => array('minimumInputLength' => 0),
+      )
+    );
     $eventType = $form->addEntityRef('event_type_id', ts('Event Type'), array(
         'entity' => 'option_value',
         'placeholder' => ts('- any -'),
@@ -573,7 +568,6 @@ class CRM_Event_BAO_Query {
     $participantFee = &$form->add('text', 'participant_fee_level', ts('Fee Level'));
 
     //elements for assigning value operation
-    $eventNameId      = &$form->add('hidden', 'event_id', '', array('id' => 'event_id'));
     $participantFeeId = &$form->add('hidden', 'participant_fee_id', '', array('id' => 'participant_fee_id'));
 
     CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE);
index 55b598a37f714e2c2874dbba2a956a93f7cb2f02..ef6aefc37ecd7aac6a801ad61562011c3ce12ef5 100644 (file)
@@ -64,13 +64,6 @@ class CRM_Event_Form_ManageEvent_Conference extends CRM_Event_Form_ManageEvent {
 
     CRM_Event_BAO_Event::retrieve($params, $defaults);
 
-    if (isset($defaults['parent_event_id'])) {
-      $params = array('id' => $defaults['parent_event_id']);
-      $r_defaults = array();
-      $parent_event = CRM_Event_BAO_Event::retrieve($params, $r_defaults);
-      $defaults['parent_event_name'] = $parent_event->title;
-    }
-
     $defaults = array_merge($defaults, $parentDefaults);
     $defaults['id'] = $eventId;
 
@@ -94,8 +87,12 @@ class CRM_Event_Form_ManageEvent_Conference extends CRM_Event_Form_ManageEvent {
       FALSE
     );
 
-    $this->addElement('text', 'parent_event_name', ts('Parent Event'));
-    $this->addElement('hidden', 'parent_event_id');
+    $this->addEntityRef('parent_event_id', ts('Parent Event'),  array(
+        'entity' => 'event',
+        'placeholder' => ts('- any -'),
+        'select' => array('minimumInputLength' => 0),
+      )
+    );
 
     parent::buildQuickForm();
   }
index 36a558a25b2c66a4421ad95aab85be7bb6b4ce71..5f68dd0fa42dac498308e256b2838770431eca8c 100644 (file)
  */
 class CRM_Event_Page_AJAX {
 
-  /**
-   * Function for building Event combo box
-   */
-  function event() {
-    $name = trim(CRM_Utils_Type::escape($_GET['s'], 'String'));
-    if (!$name) {
-      $name = '%';
-    }
-    $whereClause = " title LIKE '$name%' AND ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0 )";
-    $includeOld = CRM_Utils_Request::retrieve('includeOld', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, TRUE);
-    if (!$includeOld) {
-      $whereClause .= " AND ( end_date IS NULL OR end_date >= NOW() )";
-    }
-    $query = "
-      SELECT civicrm_event.title AS title,
-        civicrm_event.id AS id,
-        civicrm_address.city AS city,
-        civicrm_event.start_date
-      FROM civicrm_event
-        LEFT JOIN civicrm_loc_block ON
-          civicrm_event.loc_block_id = civicrm_loc_block.id
-        LEFT JOIN civicrm_address ON
-          civicrm_loc_block.address_id = civicrm_address.id
-      WHERE
-        {$whereClause}
-      ORDER BY
-        civicrm_event.title
-";
-    $dao = CRM_Core_DAO::executeQuery($query);
-    $results = array();
-    while ($dao->fetch()) {
-      $fields = array();
-      foreach (array('title', 'city') as $field) {
-        if (isset($dao->$field)) {
-          array_push($fields, $dao->$field);
-        }
-      }
-      if (isset($dao->start_date)) {
-        array_push($fields, CRM_Utils_Date::customFormat($dao->start_date));
-      }
-      $results[$dao->id] = implode(' - ', $fields);
-    }
-    CRM_Core_Page_AJAX::autocompleteResults($results);
-  }
-
   /**
    * Function for building EventFee combo box
    */
index a9872879838c1fca23034291f898b6f6db009176..c78095ed44479d83bf97dfc2bd2a1cdefdca5578 100644 (file)
      <page_callback>CRM_Event_Page_Tab</page_callback>
      <weight>4</weight>
   </item>
-  <item>
-     <path>civicrm/ajax/event</path>
-     <page_callback>CRM_Event_Page_AJAX::event</page_callback>
-     <access_arguments>access CiviCRM,access CiviEvent</access_arguments>
-  </item>
   <item>
      <path>civicrm/ajax/eventFee</path>
      <page_callback>CRM_Event_Page_AJAX::eventFee</page_callback>
index 8990d1019ca9a49d03a4714e393bca9816f322d9..359afee5d2cce46ff9b082e196eb2d5e99dac7cf 100644 (file)
@@ -231,3 +231,46 @@ function _civicrm_api3_event_getisfull(&$event, $event_id) {
   $event[$event_id]['is_full'] = $event[$event_id]['available_places'] == 0 ? 1 : 0;
 }
 
+
+/**
+ * Overrides _civicrm_api3_generic_getlist_params.
+ *
+ * @param $request array
+ */
+function _civicrm_api3_event_getlist_params(&$request) {
+  $request['params']['return'] = array('start_date', 'event_type_id', 'title', 'summary');
+  $request['params']['options']['sort'] = 'start_date DESC';
+  $request['params'] += array(
+    'is_template' => 0,
+    'is_active' => 1,
+  );
+}
+
+/**
+ * Overrides _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' => CRM_Core_Pseudoconstant::getLabel('CRM_Event_BAO_Event', 'event_type_id', $row['event_type_id']),
+      );
+      if (!empty($row['start_date'])) {
+        $data['description'] .= ': ' . CRM_Utils_Date::customFormat($row['start_date']);
+      }
+      if (!empty($row['summary'])) {
+        $data['description'] .= '<br />' . $row['summary'];
+      }
+      $output[] = $data;
+    }
+  }
+  return $output;
+}
index 249d965abc5a266e81409a2c9f023e81787dc8cb..05a5ffa5b7132c7eeaa335d95da083f76aa8fa54 100644 (file)
        </tr>
     </table>
 
-    <div id="parent_event_name">
-      <table id="parent_event_name" class="form-layout">
+    <div>
+      <table id="parent_event_name_wrapper" class="form-layout">
           <tr class="crm-event-conference-form-block-parent_event_name">
-             <td class="label">{$form.parent_event_name.label}</td>
+             <td class="label">{$form.parent_event_id.label}</td>
              <td>
-                 {$form.parent_event_name.html|crmAddClass:huge}
+                 {$form.parent_event_id.html|crmAddClass:huge}
              </td>
           </tr>
       </table>
     </div>
 
-    <div id="conference_slot_id">
-      <table id="conference_slot_id" class="form-layout">
+    <div>
+      <table id="conference_slot_id_wrapper" class="form-layout">
           <tr class="crm-event-conference-form-block-slot_label_id">
              <td class="label">{$form.slot_label_id.label}</td>
              <td>{if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_event' field='slot_label_id' id=$id}{/if}{$form.slot_label_id.html|crmAddClass:big}
 </div>
 
 {include file="CRM/common/formNavigate.tpl"}
-
-{literal}
-<script type="text/javascript">
-var eventUrl = "{/literal}{crmURL p='civicrm/ajax/event' h=0}{literal}";
-
-cj('input#parent_event_name').autocomplete(
-    eventUrl,
-    {
-        width : 280,
-        selectFirst : false,
-        matchContains: true,
-    }
-).result( function(event, data, formatted)
-    {
-        cj( "input#parent_event_name" ).val( data[0] );
-        cj( "input[name=parent_event_id]" ).val( data[1] );
-    }
-).bind( 'click', function( ) { cj( "input#parent_event_name" ).val(''); });
-</script>
-{/literal}
index 7ddc0b6d074ce7e29cc9861b450140befe4a59da..f209a72042aafd7fc73b62796ad8f141ca80a44c 100644 (file)
@@ -24,7 +24,7 @@
  +--------------------------------------------------------------------+
 *}
 <tr>
-  <td class="crm-event-form-block-event_name"> {$form.event_name.label}  <br />{$form.event_name.html|crmAddClass:huge} </td>
+  <td class="crm-event-form-block-event_id"> {$form.event_id.label}  <br />{$form.event_id.html|crmAddClass:huge} </td>
   <td class="crm-event-form-block-event_type_id"> {$form.event_type_id.label}<br />{$form.event_type_id.html} </td>
 </tr>
 <tr>
@@ -89,13 +89,8 @@ campaignTrClass='' campaignTdClass='crm-event-form-block-participant_campaign_id
 
 {literal}
 <script type="text/javascript">
-var eventUrl = "{/literal}{$dataURLEvent}{literal}";
 var feeUrl   = "{/literal}{$dataURLEventFee}{literal}";
 
-cj('#event_name').autocomplete( eventUrl, { width : 280, selectFirst : false, matchContains: true
-}).result( function(event, data, formatted) { cj( "input#event_id" ).val( data[1] );
-  }).bind( 'click', function( ) { cj( "input#event_id" ).val(''); });
-
 cj('#participant_fee_level').autocomplete( feeUrl, { width : 180, selectFirst : false, matchContains: true
 }).result(function(event, data, formatted) { cj( "input#participant_fee_id" ).val( data[1] );
   }).bind( 'click', function( ) { cj( "input#participant_fee_id" ).val(''); });