* @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 -'),
$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);
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;
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();
}
*/
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
*/
<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>
$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;
+}
</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}
+--------------------------------------------------------------------+
*}
<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>
{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(''); });