dev/core#561 Convert grant date fields to use datepicker
authoreileen <emcnaughton@wikimedia.org>
Sun, 2 Dec 2018 22:25:58 +0000 (11:25 +1300)
committereileen <emcnaughton@wikimedia.org>
Fri, 4 Jan 2019 02:24:34 +0000 (15:24 +1300)
CRM/Core/Form/Search.php
CRM/Grant/BAO/Query.php
CRM/Grant/DAO/Grant.php
CRM/Grant/Form/Search.php
templates/CRM/Grant/Form/Search/Common.tpl
xml/schema/Grant/Grant.xml

index 694953a4b69f66e93dc4bf9c299af8e02829715c..30e5a5de4589d7a265d3740979e8778784554189 100644 (file)
@@ -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]);
+        }
       }
     }
   }
index cb94908f4a2af1a8b553fb39bbd09c80da4b1e3b..b8f47c67a4c1e913fecfbb7b214966cabe1bd348 100644 (file)
@@ -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');
 
index de6305959997bf2100f164c364d8de853003f8a4..03b5e1814cf231c0c725392b9a4ac41d7e274dfc 100644 (file)
@@ -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',
index bfd64b9de697e0b15e0ab3cd92a50059f92837b7..2f52f3e3b6f9e584c3ea02d3d8bfdf9f49cbe218 100644 (file)
@@ -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();
+  }
+
 }
index c455821d12d2e2bc8cd77f5f05f905e55bcc2aca..fcf512a80247f9f385b43eaf94af838f13e362dc 100644 (file)
 <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}
index 9d09f0c13c13199c7a962841c0c8ce6198a09fa7..d19965dde64e1b145255d351483fe1ae7fb01fd9 100644 (file)
@@ -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>
@@ -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>
@@ -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>