Skip to content

Commit

Permalink
dev/core#561 Convert grant date fields to use datepicker
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Dec 4, 2018
1 parent 5270e28 commit dddca45
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 46 deletions.
9 changes: 8 additions & 1 deletion CRM/Core/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,14 @@ public function addFormFieldsFromMetadata() {
$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]);
}
}
}
}
Expand Down
39 changes: 18 additions & 21 deletions CRM/Grant/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ public static function where(&$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':
Expand Down Expand Up @@ -297,17 +295,34 @@ public static function defaultReturnProperties(
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')
);
Expand All @@ -316,29 +331,11 @@ public static function buildSearchForm(&$form) {
$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');

Expand Down
8 changes: 4 additions & 4 deletions CRM/Grant/DAO/Grant.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Grant/Grant.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:43c5de526491b3e385bec6d129dba6e3)
* (GenCodeChecksum:ea60d8cd875ca924d3cc34b4282c8a8a)
*/

/**
Expand Down Expand Up @@ -200,7 +200,7 @@ public static function &fields() {
'type' => 'EntityRef',
],
],
'application_received_date' => [
'grant_application_received_date' => [
'name' => 'application_received_date',
'type' => CRM_Utils_Type::T_DATE,
'title' => ts('Application received date'),
Expand All @@ -219,7 +219,7 @@ public static function &fields() {
'formatType' => 'activityDate',
],
],
'decision_date' => [
'grant_decision_date' => [
'name' => 'decision_date',
'type' => CRM_Utils_Type::T_DATE,
'title' => ts('Decision date'),
Expand Down Expand Up @@ -260,7 +260,7 @@ public static function &fields() {
'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',
Expand Down
23 changes: 22 additions & 1 deletion CRM/Grant/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -286,4 +298,13 @@ public function getTitle() {
return ts('Find Grants');
}

/**
* Get metadata for fields being assigned by metadata.
*
* @return array
*/
protected function getEntityMetadata() {
return CRM_Grant_BAO_Query::getSearchFieldMetadata();
}

}
36 changes: 18 additions & 18 deletions templates/CRM/Grant/Form/Search/Common.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,45 +52,45 @@
<tr>
<td>
{$form.grant_application_received_date_low.label}<br />
{include file="CRM/common/jcalendar.tpl" elementName=grant_application_received_date_low}
{$form.grant_application_received_date_low.html}
</td>
<td colspan="2">
{$form.grant_application_received_date_high.label}<br />
{include file="CRM/common/jcalendar.tpl" elementName=grant_application_received_date_high}
&nbsp;{$form.grant_application_received_notset.html}&nbsp;&nbsp;{$form.grant_application_received_notset.label}
{$form.grant_application_received_date_high.label}<br />
{$form.grant_application_received_date_high.html}
&nbsp;{$form.grant_application_received_notset.html}&nbsp;&nbsp;{$form.grant_application_received_notset.label}
</td>
</tr>
<tr>
<td>
{$form.grant_decision_date_low.label}<br />
{include file="CRM/common/jcalendar.tpl" elementName=grant_decision_date_low}
{$form.grant_decision_date_low.label}<br />
{$form.grant_decision_date_low.html}
</td>
<td colspan="2">
{$form.grant_decision_date_high.label}<br />
{include file="CRM/common/jcalendar.tpl" elementName=grant_decision_date_high}
&nbsp;{$form.grant_decision_date_notset.html}&nbsp;&nbsp;{$form.grant_decision_date_notset.label}
{$form.grant_decision_date_high.html}
&nbsp;{$form.grant_decision_date_notset.html}&nbsp;&nbsp;{$form.grant_decision_date_notset.label}
</td>
</tr>
<tr>
<td>
{$form.grant_money_transfer_date_low.label}<br />
{include file="CRM/common/jcalendar.tpl" elementName=grant_money_transfer_date_low}
{$form.grant_money_transfer_date_low.label}<br />
{$form.grant_money_transfer_date_low.html}
</td>
<td colspan="2">
{$form.grant_money_transfer_date_high.label}<br />
{include file="CRM/common/jcalendar.tpl" elementName=grant_money_transfer_date_high}
&nbsp;{$form.grant_money_transfer_date_notset.html}&nbsp;&nbsp;{$form.grant_money_transfer_date_notset.label}
{$form.grant_money_transfer_date_high.label}<br />
{$form.grant_money_transfer_date_high.html}
&nbsp;{$form.grant_money_transfer_date_notset.html}&nbsp;&nbsp;{$form.grant_money_transfer_date_notset.label}
</td>
</tr>
<tr>
<td>
{$form.grant_due_date_low.label}<br />
{include file="CRM/common/jcalendar.tpl" elementName=grant_due_date_low}
{$form.grant_due_date_low.label}<br />
{$form.grant_due_date_low.html}
</td>
<td colspan="2">
{$form.grant_due_date_high.label}<br />
{include file="CRM/common/jcalendar.tpl" elementName=grant_due_date_high}
&nbsp;{$form.grant_due_date_notset.html}&nbsp;&nbsp;{$form.grant_due_date_notset.label}
{$form.grant_due_date_high.label}<br />
{$form.grant_due_date_high.html}
&nbsp;{$form.grant_due_date_notset.html}&nbsp;&nbsp;{$form.grant_due_date_notset.label}
</td>
</tr>
{if $grantGroupTree}
Expand Down
4 changes: 3 additions & 1 deletion xml/schema/Grant/Grant.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<field>
<name>application_received_date</name>
<title>Application received date</title>
<uniqueName>grant_application_received_date</uniqueName>
<type>date</type>
<export>true</export>
<import>true</import>
Expand All @@ -56,6 +57,7 @@
<field>
<name>decision_date</name>
<title>Decision date</title>
<uniqueName>grant_decision_date</uniqueName>
<type>date</type>
<comment>Date on which grant decision was made.</comment>
<import>true</import>
Expand All @@ -81,7 +83,7 @@
<field>
<name>grant_due_date</name>
<type>date</type>
<title>Grant Due Date</title>
<title>Grant Report Due Date</title>
<comment>Date on which grant report is due.</comment>
<add>1.8</add>
<import>true</import>
Expand Down

0 comments on commit dddca45

Please sign in to comment.