Skip to content

Commit

Permalink
Convert event search to use metadata
Browse files Browse the repository at this point in the history
This only converts one field (participant status) but lays the ground-work for converting more &
removing the jcalendar
  • Loading branch information
eileenmcnaughton committed May 28, 2019
1 parent abf04d2 commit 61b4d09
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CRM/Core/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function addSearchFieldMetadata($searchFieldMetadata) {
/**
* 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');
Expand Down
32 changes: 21 additions & 11 deletions CRM/Event/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,29 @@ public static function defaultReturnProperties(
}

/**
* @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
Expand Down Expand Up @@ -616,16 +636,6 @@ public static function buildSearchForm(&$form) {

$form->addElement('checkbox', "event_include_repeating_events", NULL, ts('Include participants from all events in the %1 series', [1 => '<em>%1</em>']));

$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',
Expand Down
22 changes: 17 additions & 5 deletions CRM/Event/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
* @copyright CiviCRM LLC (c) 2004-2019
*/

/**
* Files required
*/

/**
* This file is for civievent search
*/
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -138,8 +149,9 @@ public function preProcess() {
/**
* Build the form object.
*
*
* @return void
*
* @throws \CRM_Core_Exception
*/
public function buildQuickForm() {
parent::buildQuickForm();
Expand Down

0 comments on commit 61b4d09

Please sign in to comment.