From: eileen Date: Sun, 2 Dec 2018 22:25:58 +0000 (+1300) Subject: dev/core#561 Convert grant date fields to use datepicker X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0bcac7e7d2b4b1aa2662830b5a2becb1ff70fb5f;p=civicrm-core.git dev/core#561 Convert grant date fields to use datepicker --- diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index 694953a4b6..30e5a5de45 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -154,7 +154,14 @@ class CRM_Core_Form_Search extends CRM_Core_Form { $this->_action = CRM_Core_Action::ADVANCED; foreach ($this->getSearchFieldMetadata() as $entity => $fields) { foreach ($fields as $fieldName => $fieldSpec) { - $this->addField($fieldName, ['entity' => $entity]); + if ($fieldSpec['type'] === CRM_Utils_Type::T_DATE) { + // Assuming time is false for now as we are not checking for date-time fields as yet. + $this->add('datepicker', $fieldName . '_low', $fieldSpec['title'], [], FALSE, ['time' => FALSE]); + $this->add('datepicker', $fieldName . '_high', $fieldSpec['title'], [], FALSE, ['time' => FALSE]); + } + else { + $this->addField($fieldName, ['entity' => $entity]); + } } } } diff --git a/CRM/Grant/BAO/Query.php b/CRM/Grant/BAO/Query.php index cb94908f4a..b8f47c67a4 100644 --- a/CRM/Grant/BAO/Query.php +++ b/CRM/Grant/BAO/Query.php @@ -123,9 +123,7 @@ class CRM_Grant_BAO_Query extends CRM_Core_BAO_Query { * @param $query */ public static function whereClauseSingle(&$values, &$query) { - $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; list($name, $op, $value, $grouping, $wildcard) = $values; - $val = $names = array(); switch ($name) { case 'grant_money_transfer_date_low': case 'grant_money_transfer_date_high': @@ -297,17 +295,34 @@ class CRM_Grant_BAO_Query extends CRM_Core_BAO_Query { return $properties; } + /** + * Get the metadata for fields to be included on the activity search form. + */ + public static function getSearchFieldMetadata() { + $fields = [ + 'grant_report_received', + 'grant_application_received_date', + 'grant_decision_date', + 'grant_money_transfer_date', + 'grant_due_date', + ]; + $metadata = civicrm_api3('Grant', 'getfields', [])['values']; + return array_intersect_key($metadata, array_flip($fields)); + } + /** * Add all the elements shared between grant search and advanaced search. * * - * @param CRM_Core_Form $form + * @param \CRM_Grant_Form_Search $form * * @return void */ public static function buildSearchForm(&$form) { $grantType = CRM_Core_OptionGroup::values('grant_type'); + $form->addSearchFieldMetadata(['Grant' => self::getSearchFieldMetadata()]); + $form->addFormFieldsFromMetadata(); $form->add('select', 'grant_type_id', ts('Grant Type'), $grantType, FALSE, array('id' => 'grant_type_id', 'multiple' => 'multiple', 'class' => 'crm-select2') ); @@ -316,29 +331,11 @@ class CRM_Grant_BAO_Query extends CRM_Core_BAO_Query { $form->add('select', 'grant_status_id', ts('Grant Status'), $grantStatus, FALSE, array('id' => 'grant_status_id', 'multiple' => 'multiple', 'class' => 'crm-select2') ); - - $form->addDate('grant_application_received_date_low', ts('App. Received Date - From'), FALSE, array('formatType' => 'searchDate')); - $form->addDate('grant_application_received_date_high', ts('To'), FALSE, array('formatType' => 'searchDate')); - $form->addElement('checkbox', 'grant_application_received_notset', ts('Date is not set'), NULL); - - $form->addDate('grant_money_transfer_date_low', ts('Money Sent Date - From'), FALSE, array('formatType' => 'searchDate')); - $form->addDate('grant_money_transfer_date_high', ts('To'), FALSE, array('formatType' => 'searchDate')); - $form->addElement('checkbox', 'grant_money_transfer_date_notset', ts('Date is not set'), NULL); - - $form->addDate('grant_due_date_low', ts('Report Due Date - From'), FALSE, array('formatType' => 'searchDate')); - $form->addDate('grant_due_date_high', ts('To'), FALSE, array('formatType' => 'searchDate')); - $form->addElement('checkbox', 'grant_due_date_notset', ts('Date is not set'), NULL); - - $form->addDate('grant_decision_date_low', ts('Grant Decision Date - From'), FALSE, array('formatType' => 'searchDate')); - $form->addDate('grant_decision_date_high', ts('To'), FALSE, array('formatType' => 'searchDate')); - $form->addElement('checkbox', 'grant_decision_date_notset', ts('Date is not set'), NULL); - $form->addYesNo('grant_report_received', ts('Grant report received?'), TRUE); - $form->add('text', 'grant_amount_low', ts('Minimum Amount'), array('size' => 8, 'maxlength' => 8)); $form->addRule('grant_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money'); diff --git a/CRM/Grant/DAO/Grant.php b/CRM/Grant/DAO/Grant.php index de63059599..03b5e1814c 100644 --- a/CRM/Grant/DAO/Grant.php +++ b/CRM/Grant/DAO/Grant.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Grant/Grant.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:43c5de526491b3e385bec6d129dba6e3) + * (GenCodeChecksum:ea60d8cd875ca924d3cc34b4282c8a8a) */ /** @@ -200,7 +200,7 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'type' => 'EntityRef', ], ], - 'application_received_date' => [ + 'grant_application_received_date' => [ 'name' => 'application_received_date', 'type' => CRM_Utils_Type::T_DATE, 'title' => ts('Application received date'), @@ -219,7 +219,7 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'formatType' => 'activityDate', ], ], - 'decision_date' => [ + 'grant_decision_date' => [ 'name' => 'decision_date', 'type' => CRM_Utils_Type::T_DATE, 'title' => ts('Decision date'), @@ -260,7 +260,7 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'grant_due_date' => [ 'name' => 'grant_due_date', 'type' => CRM_Utils_Type::T_DATE, - 'title' => ts('Grant Due Date'), + 'title' => ts('Grant Report Due Date'), 'description' => ts('Date on which grant report is due.'), 'import' => TRUE, 'where' => 'civicrm_grant.grant_due_date', diff --git a/CRM/Grant/Form/Search.php b/CRM/Grant/Form/Search.php index bfd64b9de6..2f52f3e3b6 100644 --- a/CRM/Grant/Form/Search.php +++ b/CRM/Grant/Form/Search.php @@ -62,7 +62,19 @@ class CRM_Grant_Form_Search extends CRM_Core_Form_Search { */ protected $_prefix = "grant_"; - protected $entity = 'grant'; + /** + * Metadata of all fields to include on the form. + * + * @var array + */ + protected $searchFieldMetadata = []; + + /** + * @return string + */ + public function getDefaultEntity() { + return 'Grant'; + } /** * Processing needed for buildForm and later. @@ -286,4 +298,13 @@ class CRM_Grant_Form_Search extends CRM_Core_Form_Search { return ts('Find Grants'); } + /** + * Get metadata for fields being assigned by metadata. + * + * @return array + */ + protected function getEntityMetadata() { + return CRM_Grant_BAO_Query::getSearchFieldMetadata(); + } + } diff --git a/templates/CRM/Grant/Form/Search/Common.tpl b/templates/CRM/Grant/Form/Search/Common.tpl index c455821d12..fcf512a802 100644 --- a/templates/CRM/Grant/Form/Search/Common.tpl +++ b/templates/CRM/Grant/Form/Search/Common.tpl @@ -52,45 +52,45 @@ {$form.grant_application_received_date_low.label}
- {include file="CRM/common/jcalendar.tpl" elementName=grant_application_received_date_low} + {$form.grant_application_received_date_low.html} - {$form.grant_application_received_date_high.label}
- {include file="CRM/common/jcalendar.tpl" elementName=grant_application_received_date_high} -  {$form.grant_application_received_notset.html}  {$form.grant_application_received_notset.label} + {$form.grant_application_received_date_high.label}
+ {$form.grant_application_received_date_high.html} +  {$form.grant_application_received_notset.html}  {$form.grant_application_received_notset.label} - {$form.grant_decision_date_low.label}
- {include file="CRM/common/jcalendar.tpl" elementName=grant_decision_date_low} + {$form.grant_decision_date_low.label}
+ {$form.grant_decision_date_low.html} {$form.grant_decision_date_high.label}
- {include file="CRM/common/jcalendar.tpl" elementName=grant_decision_date_high} -  {$form.grant_decision_date_notset.html}  {$form.grant_decision_date_notset.label} + {$form.grant_decision_date_high.html} +  {$form.grant_decision_date_notset.html}  {$form.grant_decision_date_notset.label} - {$form.grant_money_transfer_date_low.label}
- {include file="CRM/common/jcalendar.tpl" elementName=grant_money_transfer_date_low} + {$form.grant_money_transfer_date_low.label}
+ {$form.grant_money_transfer_date_low.html} - {$form.grant_money_transfer_date_high.label}
- {include file="CRM/common/jcalendar.tpl" elementName=grant_money_transfer_date_high} -  {$form.grant_money_transfer_date_notset.html}  {$form.grant_money_transfer_date_notset.label} + {$form.grant_money_transfer_date_high.label}
+ {$form.grant_money_transfer_date_high.html} +  {$form.grant_money_transfer_date_notset.html}  {$form.grant_money_transfer_date_notset.label} - {$form.grant_due_date_low.label}
- {include file="CRM/common/jcalendar.tpl" elementName=grant_due_date_low} + {$form.grant_due_date_low.label}
+ {$form.grant_due_date_low.html} - {$form.grant_due_date_high.label}
- {include file="CRM/common/jcalendar.tpl" elementName=grant_due_date_high} -  {$form.grant_due_date_notset.html}  {$form.grant_due_date_notset.label} + {$form.grant_due_date_high.label}
+ {$form.grant_due_date_high.html} +  {$form.grant_due_date_notset.html}  {$form.grant_due_date_notset.label} {if $grantGroupTree} diff --git a/xml/schema/Grant/Grant.xml b/xml/schema/Grant/Grant.xml index 9d09f0c13c..d19965dde6 100644 --- a/xml/schema/Grant/Grant.xml +++ b/xml/schema/Grant/Grant.xml @@ -43,6 +43,7 @@ application_received_date Application received date + grant_application_received_date date true true @@ -56,6 +57,7 @@ decision_date Decision date + grant_decision_date date Date on which grant decision was made. true @@ -81,7 +83,7 @@ grant_due_date date - Grant Due Date + Grant Report Due Date Date on which grant report is due. 1.8 true