From 61b4d09160e6c857c4fa5389256d0e22c85cab10 Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 25 May 2019 19:41:54 +1200 Subject: [PATCH] Convert event search to use metadata This only converts one field (participant status) but lays the ground-work for converting more & removing the jcalendar --- CRM/Core/Form/Search.php | 2 +- CRM/Event/BAO/Query.php | 32 +++++++++++++++++++++----------- CRM/Event/Form/Search.php | 22 +++++++++++++++++----- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index b6fb1cb4d4..5071980e4b 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -125,7 +125,7 @@ class CRM_Core_Form_Search extends CRM_Core_Form { /** * Common buildForm tasks required by all searches. */ - public function buildQuickform() { + public function buildQuickForm() { CRM_Core_Resources::singleton() ->addScriptFile('civicrm', 'js/crm.searchForm.js', 1, 'html-header') ->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header'); diff --git a/CRM/Event/BAO/Query.php b/CRM/Event/BAO/Query.php index 5f8e8bf000..4d21ac4ea5 100644 --- a/CRM/Event/BAO/Query.php +++ b/CRM/Event/BAO/Query.php @@ -575,9 +575,29 @@ class CRM_Event_BAO_Query extends CRM_Core_BAO_Query { } /** - * @param CRM_Core_Form $form + * Get the metadata for fields to be included on the grant search form. + * + * @throws \CiviCRM_API3_Exception + */ + public static function getSearchFieldMetadata() { + $fields = [ + 'participant_status_id', + ]; + $metadata = civicrm_api3('Participant', 'getfields', [])['values']; + return array_intersect_key($metadata, array_flip($fields)); + } + + /** + * Build the event search form. + * + * @param \CRM_Event_Form_Search $form + * + * @throws \CiviCRM_API3_Exception + * @throws \CRM_Core_Exception */ public static function buildSearchForm(&$form) { + $form->addSearchFieldMetadata(['Participant' => self::getSearchFieldMetadata()]); + $form->addFormFieldsFromMetadata(); $dataURLEventFee = CRM_Utils_System::url('civicrm/ajax/eventFee', "reset=1", FALSE, NULL, FALSE @@ -616,16 +636,6 @@ class CRM_Event_BAO_Query extends CRM_Core_BAO_Query { $form->addElement('checkbox', "event_include_repeating_events", NULL, ts('Include participants from all events in the %1 series', [1 => '%1'])); - $form->addSelect('participant_status_id', - [ - 'entity' => 'participant', - 'label' => ts('Participant Status'), - 'multiple' => 'multiple', - 'option_url' => NULL, - 'placeholder' => ts('- any -'), - ] - ); - $form->addSelect('participant_role_id', [ 'entity' => 'participant', diff --git a/CRM/Event/Form/Search.php b/CRM/Event/Form/Search.php index 3f7af06118..4282764ef9 100644 --- a/CRM/Event/Form/Search.php +++ b/CRM/Event/Form/Search.php @@ -31,10 +31,6 @@ * @copyright CiviCRM LLC (c) 2004-2019 */ -/** - * Files required - */ - /** * This file is for civievent search */ @@ -74,6 +70,21 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { */ protected $_ssID; + /** + * Metadata of all fields to include on the form. + * + * @var array + */ + protected $searchFieldMetadata = []; + + + /** + * @return string + */ + public function getDefaultEntity() { + return 'Participant'; + } + /** * Processing needed for buildForm and later. * @@ -138,8 +149,9 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { /** * Build the form object. * - * * @return void + * + * @throws \CRM_Core_Exception */ public function buildQuickForm() { parent::buildQuickForm(); -- 2.25.1