From 52ddd94d6f2ffbdcf313a9f1005f7b5fc35469d7 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 5 Jun 2019 15:20:11 +1200 Subject: [PATCH] Convert pledge search form to use metadata functions This doesn't change anything of itself but is a pre-requisite for - removing jcalendar instances - supporting params in the url - supporting appropriate wildcards on text fields (not seemingly relevant on this entity). In addition it is a driver for cleaning up metadata for our eventual leap away from quickform. In this case the change highlighted the need to define the html type on the converted field (pledge_status_id --- CRM/Pledge/BAO/Query.php | 27 +++++++++++++++++++++------ CRM/Pledge/DAO/Pledge.php | 5 ++++- CRM/Pledge/Form/Search.php | 7 +++++++ xml/schema/Pledge/Pledge.xml | 3 +++ 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/CRM/Pledge/BAO/Query.php b/CRM/Pledge/BAO/Query.php index 902872d1c1..ae120d5224 100644 --- a/CRM/Pledge/BAO/Query.php +++ b/CRM/Pledge/BAO/Query.php @@ -524,10 +524,30 @@ class CRM_Pledge_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 = [ + 'pledge_status_id', + ]; + $metadata = civicrm_api3('Pledge', 'getfields', [])['values']; + return array_intersect_key($metadata, array_flip($fields)); + } + + /** + * Build the search for for pledges. + * + * @param CRM_Pledge_Form_Search|\CRM_Contact_Form_Search_Advanced $form + * + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception */ public static function buildSearchForm(&$form) { // pledge related dates + $form->addSearchFieldMetadata(['Pledge' => self::getSearchFieldMetadata()]); + $form->addFormFieldsFromMetadata(); CRM_Core_Form_Date::buildDateRange($form, 'pledge_start_date', 1, '_low', '_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'pledge_end_date', 1, '_low', '_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'pledge_create_date', 1, '_low', '_high', ts('From'), FALSE); @@ -542,11 +562,6 @@ class CRM_Pledge_BAO_Query extends CRM_Core_BAO_Query { $form->add('text', 'pledge_amount_high', ts('To'), ['size' => 8, 'maxlength' => 8]); $form->addRule('pledge_amount_high', ts('Please enter a valid money value (e.g. %1).', [1 => CRM_Utils_Money::format('99.99', ' ')]), 'money'); - $form->add('select', 'pledge_status_id', - ts('Pledge Status'), CRM_Pledge_BAO_Pledge::buildOptions('status_id'), - FALSE, ['class' => 'crm-select2', 'multiple' => 'multiple'] - ); - $form->addYesNo('pledge_acknowledge_date_is_not_null', ts('Acknowledgement sent?'), TRUE); $form->add('text', 'pledge_installments_low', ts('From'), ['size' => 8, 'maxlength' => 8]); diff --git a/CRM/Pledge/DAO/Pledge.php b/CRM/Pledge/DAO/Pledge.php index b18050474a..a0823646c0 100644 --- a/CRM/Pledge/DAO/Pledge.php +++ b/CRM/Pledge/DAO/Pledge.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Pledge/Pledge.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:877e6098c175e69f385b22f61958b70c) + * (GenCodeChecksum:9590ea3142ac2509cd28e4b4d3f2da32) */ /** @@ -561,6 +561,9 @@ class CRM_Pledge_DAO_Pledge extends CRM_Core_DAO { 'entity' => 'Pledge', 'bao' => 'CRM_Pledge_BAO_Pledge', 'localizable' => 0, + 'html' => [ + 'type' => 'Select', + ], 'pseudoconstant' => [ 'optionGroupName' => 'pledge_status', 'optionEditPath' => 'civicrm/admin/options/pledge_status', diff --git a/CRM/Pledge/Form/Search.php b/CRM/Pledge/Form/Search.php index c101d33a6d..ecf8f503e4 100644 --- a/CRM/Pledge/Form/Search.php +++ b/CRM/Pledge/Form/Search.php @@ -43,6 +43,13 @@ class CRM_Pledge_Form_Search extends CRM_Core_Form_Search { */ protected $_queryParams; + /** + * @return string + */ + public function getDefaultEntity() { + return 'Pledge'; + } + /** * Are we restricting ourselves to a single contact. * diff --git a/xml/schema/Pledge/Pledge.xml b/xml/schema/Pledge/Pledge.xml index 6d4e15e519..22f672ea92 100644 --- a/xml/schema/Pledge/Pledge.xml +++ b/xml/schema/Pledge/Pledge.xml @@ -291,6 +291,9 @@ true false int unsigned + + Select + pledge_status -- 2.25.1