From: Coleman Watts Date: Sat, 22 Feb 2014 17:13:36 +0000 (-0500) Subject: CRM-13966 - Migrate event id to select2 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9c7c6a00156aa0b0278446bc45c4e6c8ea710417;p=civicrm-core.git CRM-13966 - Migrate event id to select2 --- diff --git a/CRM/Event/BAO/Query.php b/CRM/Event/BAO/Query.php index 193776249e..520773f152 100644 --- a/CRM/Event/BAO/Query.php +++ b/CRM/Event/BAO/Query.php @@ -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); diff --git a/CRM/Event/Form/ManageEvent/Conference.php b/CRM/Event/Form/ManageEvent/Conference.php index 55b598a37f..ef6aefc37e 100644 --- a/CRM/Event/Form/ManageEvent/Conference.php +++ b/CRM/Event/Form/ManageEvent/Conference.php @@ -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(); } diff --git a/CRM/Event/Page/AJAX.php b/CRM/Event/Page/AJAX.php index 36a558a25b..5f68dd0fa4 100644 --- a/CRM/Event/Page/AJAX.php +++ b/CRM/Event/Page/AJAX.php @@ -38,51 +38,6 @@ */ 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 */ diff --git a/CRM/Event/xml/Menu/Event.xml b/CRM/Event/xml/Menu/Event.xml index a987287983..c78095ed44 100644 --- a/CRM/Event/xml/Menu/Event.xml +++ b/CRM/Event/xml/Menu/Event.xml @@ -260,11 +260,6 @@ CRM_Event_Page_Tab 4 - - civicrm/ajax/event - CRM_Event_Page_AJAX::event - access CiviCRM,access CiviEvent - civicrm/ajax/eventFee CRM_Event_Page_AJAX::eventFee diff --git a/api/v3/Event.php b/api/v3/Event.php index 8990d1019c..359afee5d2 100644 --- a/api/v3/Event.php +++ b/api/v3/Event.php @@ -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'] .= '
' . $row['summary']; + } + $output[] = $data; + } + } + return $output; +} diff --git a/templates/CRM/Event/Form/ManageEvent/Conference.tpl b/templates/CRM/Event/Form/ManageEvent/Conference.tpl index 249d965abc..05a5ffa5b7 100644 --- a/templates/CRM/Event/Form/ManageEvent/Conference.tpl +++ b/templates/CRM/Event/Form/ManageEvent/Conference.tpl @@ -35,19 +35,19 @@ -
- +
+
- +
{$form.parent_event_name.label}{$form.parent_event_id.label} - {$form.parent_event_name.html|crmAddClass:huge} + {$form.parent_event_id.html|crmAddClass:huge}
-
- +
+
- + @@ -89,13 +89,8 @@ campaignTrClass='' campaignTdClass='crm-event-form-block-participant_campaign_id {literal}
{$form.slot_label_id.label} {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} @@ -61,23 +61,3 @@ {include file="CRM/common/formNavigate.tpl"} - -{literal} - -{/literal} diff --git a/templates/CRM/Event/Form/Search/Common.tpl b/templates/CRM/Event/Form/Search/Common.tpl index 7ddc0b6d07..f209a72042 100644 --- a/templates/CRM/Event/Form/Search/Common.tpl +++ b/templates/CRM/Event/Form/Search/Common.tpl @@ -24,7 +24,7 @@ +--------------------------------------------------------------------+ *}
{$form.event_name.label}
{$form.event_name.html|crmAddClass:huge}
{$form.event_id.label}
{$form.event_id.html|crmAddClass:huge}
{$form.event_type_id.label}
{$form.event_type_id.html}