$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]);
+ }
}
}
}
* @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':
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')
);
$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');
*
* Generated from xml/schema/CRM/Grant/Grant.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:43c5de526491b3e385bec6d129dba6e3)
+ * (GenCodeChecksum:ea60d8cd875ca924d3cc34b4282c8a8a)
*/
/**
'type' => 'EntityRef',
],
],
- 'application_received_date' => [
+ 'grant_application_received_date' => [
'name' => 'application_received_date',
'type' => CRM_Utils_Type::T_DATE,
'title' => ts('Application received date'),
'formatType' => 'activityDate',
],
],
- 'decision_date' => [
+ 'grant_decision_date' => [
'name' => 'decision_date',
'type' => CRM_Utils_Type::T_DATE,
'title' => ts('Decision date'),
'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',
*/
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.
return ts('Find Grants');
}
+ /**
+ * Get metadata for fields being assigned by metadata.
+ *
+ * @return array
+ */
+ protected function getEntityMetadata() {
+ return CRM_Grant_BAO_Query::getSearchFieldMetadata();
+ }
+
}
<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}
- {$form.grant_application_received_notset.html} {$form.grant_application_received_notset.label}
+ {$form.grant_application_received_date_high.label}<br />
+ {$form.grant_application_received_date_high.html}
+ {$form.grant_application_received_notset.html} {$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}
- {$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}
</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}
- {$form.grant_money_transfer_date_notset.html} {$form.grant_money_transfer_date_notset.label}
+ {$form.grant_money_transfer_date_high.label}<br />
+ {$form.grant_money_transfer_date_high.html}
+ {$form.grant_money_transfer_date_notset.html} {$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}
- {$form.grant_due_date_notset.html} {$form.grant_due_date_notset.label}
+ {$form.grant_due_date_high.label}<br />
+ {$form.grant_due_date_high.html}
+ {$form.grant_due_date_notset.html} {$form.grant_due_date_notset.label}
</td>
</tr>
{if $grantGroupTree}
<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>
<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>
<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>