[Date picker][REF] Convert jcalendar date fields to date picker on member search...
authorSeamus Lee <seamuslee001@gmail.com>
Sat, 31 Aug 2019 07:09:05 +0000 (17:09 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Tue, 3 Sep 2019 00:27:01 +0000 (10:27 +1000)
Ensure that relative fields are handled as per newer handling

Update to eileen's metadata date_query functions and fix template

Fix upgrade by including each of the 3 separate field names

CRM/Contact/BAO/Query.php
CRM/Member/BAO/Query.php
CRM/Member/Form/Search.php
CRM/Upgrade/Incremental/php/FiveEighteen.php
templates/CRM/Member/Form/Search/Common.tpl
templates/CRM/Member/Form/Selector.tpl

index b34d882dcd4a6f8bffee3c2841fc68dcec1ea4e7..d62f6279d24cf5909516e9068f1d99e8121edaa6 100644 (file)
@@ -1591,6 +1591,9 @@ class CRM_Contact_BAO_Query {
       'pledge_create_date_relative',
       'pledge_start_date_relative',
       'pledge_payment_scheduled_date_relative',
+      'membership_join_date_relative',
+      'membership_start_date_relative',
+      'membership_end_date_relative',
     ];
     // Handle relative dates first
     foreach (array_keys($formValues) as $id) {
index 0b05a70f0e6cc51fc4bd914c85ed45fad22e6ed5..d8e0d9b9ea4211ed61f45c617cd84af0a0e5dfd3 100644 (file)
@@ -161,12 +161,22 @@ class CRM_Member_BAO_Query extends CRM_Core_BAO_Query {
    * @param CRM_Contact_BAO_Query $query
    */
   public static function whereClauseSingle(&$values, &$query) {
+    if ($query->buildDateRangeQuery($values)) {
+      // @todo - move this to Contact_Query in or near the call to
+      // $this->buildRelativeDateQuery($values);
+      return;
+    }
     list($name, $op, $value, $grouping) = $values;
     switch ($name) {
       case 'member_join_date_low':
       case 'member_join_date_high':
+        Civi::log()->warning(
+          'member_join_date field is deprecated please use membership_join_date field instead',
+          ['civi.tag' => 'deprecated']
+        );
+        $fldName = str_replace(['_low', '_high'], '', $name);
         $query->dateQueryBuilder($values,
-          'civicrm_membership', 'member_join_date', 'join_date',
+          'civicrm_membership', $fldName, 'join_date',
           'Member Since'
         );
         return;
@@ -174,6 +184,10 @@ class CRM_Member_BAO_Query extends CRM_Core_BAO_Query {
       case 'membership_start_date':
       case 'member_start_date_low':
       case 'member_start_date_high':
+        Civi::log()->warning(
+          'member_start_date field is deprecated please use membership_start_date field instead',
+          ['civi.tag' => 'deprecated']
+        );
         $fldName = str_replace(['_low', '_high'], '', $name);
         $query->dateQueryBuilder($values,
           'civicrm_membership', $fldName, 'start_date',
@@ -184,6 +198,10 @@ class CRM_Member_BAO_Query extends CRM_Core_BAO_Query {
       case 'membership_end_date':
       case 'member_end_date_low':
       case 'member_end_date_high':
+        Civi::log()->warning(
+          'member_end_date field is deprecated please use membership_end_date field instead',
+          ['civi.tag' => 'deprecated']
+        );
         $fldName = str_replace(['_low', '_high'], '', $name);
         $query->dateQueryBuilder($values,
           'civicrm_membership', $fldName, 'end_date',
@@ -376,6 +394,7 @@ class CRM_Member_BAO_Query extends CRM_Core_BAO_Query {
         $query->_qill[$grouping][] = $value ? ts("Membership Status Is Overriden") : ts("Membership Status Is NOT Overriden");
         $query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
         return;
+
     }
   }
 
@@ -470,12 +489,29 @@ class CRM_Member_BAO_Query extends CRM_Core_BAO_Query {
     return $properties;
   }
 
+  /**
+   * Get the metadata for fields to be included on the grant search form.
+   *
+   * @throws \CiviCRM_API3_Exception
+   */
+  public static function getSearchFieldMetadata() {
+    $fields = [
+      'membership_join_date',
+      'membership_start_date',
+      'membership_end_date',
+    ];
+    $metadata = civicrm_api3('Membership', 'getfields', [])['values'];
+    return array_intersect_key($metadata, array_flip($fields));
+  }
+
   /**
    * Build the search form.
    *
    * @param CRM_Core_Form $form
    */
   public static function buildSearchForm(&$form) {
+    $form->addSearchFieldMetadata(['Membership' => self::getSearchFieldMetadata()]);
+    $form->addFormFieldsFromMetadata();
     $membershipStatus = CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label', FALSE, FALSE);
     $form->add('select', 'membership_status_id', ts('Membership Status'), $membershipStatus, FALSE, [
       'id' => 'membership_status_id',
@@ -493,17 +529,6 @@ class CRM_Member_BAO_Query extends CRM_Core_BAO_Query {
     $form->addElement('text', 'member_source', ts('Source'));
     $form->add('number', 'membership_id', ts('Membership ID'), ['class' => 'four', 'min' => 1]);
 
-    CRM_Core_Form_Date::buildDateRange($form, 'member_join_date', 1, '_low', '_high', ts('From'), FALSE);
-    $form->addElement('hidden', 'member_join_date_range_error');
-
-    CRM_Core_Form_Date::buildDateRange($form, 'member_start_date', 1, '_low', '_high', ts('From'), FALSE);
-    $form->addElement('hidden', 'member_start_date_range_error');
-
-    CRM_Core_Form_Date::buildDateRange($form, 'member_end_date', 1, '_low', '_high', ts('From'), FALSE);
-    $form->addElement('hidden', 'member_end_date_range_error');
-
-    $form->addFormRule(['CRM_Member_BAO_Query', 'formRule'], $form);
-
     $form->addYesNo('membership_is_current_member', ts('Current Member?'), TRUE);
     $form->addYesNo('member_is_primary', ts('Primary Member?'), TRUE);
     $form->addYesNo('member_pay_later', ts('Pay Later?'), TRUE);
@@ -543,27 +568,4 @@ class CRM_Member_BAO_Query extends CRM_Core_BAO_Query {
     }
   }
 
-  /**
-   * Custom form rules.
-   *
-   * @param array $fields
-   * @param array $files
-   * @param CRM_Core_Form $form
-   *
-   * @return bool|array
-   */
-  public static function formRule($fields, $files, $form) {
-    $errors = [];
-
-    if ((empty($fields['member_join_date_low']) || empty($fields['member_join_date_high'])) && (empty($fields['member_start_date_low']) || empty($fields['member_start_date_high'])) && (empty($fields['member_end_date_low']) || empty($fields['member_end_date_high']))) {
-      return TRUE;
-    }
-
-    CRM_Utils_Rule::validDateRange($fields, 'member_join_date', $errors, ts('Member Since'));
-    CRM_Utils_Rule::validDateRange($fields, 'member_start_date', $errors, ts('Start Date'));
-    CRM_Utils_Rule::validDateRange($fields, 'member_end_date', $errors, ts('End Date'));
-
-    return empty($errors) ? TRUE : $errors;
-  }
-
 }
index 8eba67bfa9c7d76d365568febfe240dd125a6696..3d7afe8ffcd6d50cd2a82621249ff62d51be8d7c 100644 (file)
@@ -95,6 +95,8 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search {
     }
 
     if ($this->_force) {
+      $this->addSearchFieldMetadata(['Membership' => CRM_Member_BAO_Query::getSearchFieldMetadata()]);
+      $this->addFormFieldsFromMetadata();
       $this->postProcess();
       $this->set('force', 0);
     }
@@ -227,8 +229,7 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search {
     }
 
     $this->_done = TRUE;
-
-    $this->_formValues = $this->controller->exportValues($this->_name);
+    $this->setFormValues();
 
     $this->fixFormValues();
 
@@ -292,17 +293,6 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search {
     $controller->run();
   }
 
-  /**
-   * Set default values.
-   *
-   * @todo - can this function override be removed?
-   *
-   * @return array
-   */
-  public function setDefaultValues() {
-    return $this->_defaults;
-  }
-
   /**
    * If this search has been forced then see if there are any get values, and if so over-ride the post values.
    *
index ab974478caae29ccae8e9b5a46cacdaee08709c5..879b4aa240bbe6d94ba4d51849bab75446255710 100644 (file)
@@ -84,7 +84,18 @@ class CRM_Upgrade_Incremental_php_FiveEighteen extends CRM_Upgrade_Incremental_B
     $this->addTask('Re-Create Foreign key between civicrm_dashboard and civicrm_domain correctly', 'recreateDashboardFK');
     $this->addTask('Update smart groups to rename filters on pledge_payment_date to pledge_payment_scheduled_date', 'updateSmartGroups', [
       'renameField' => [
-        ['old' => 'pledge_payment_date', 'new' => 'pledge_payment_scheduled_date'],
+        ['old' => 'pledge_payment_date_relative', 'new' => 'pledge_payment_scheduled_date_relative'],
+        ['old' => 'pledge_payment_date_high', 'new' => 'pledge_payment_scheduled_date_high'],
+        ['old' => 'pledge_payment_date_low', 'new' => 'pledge_payment_scheduled_date_low'],
+        ['old' => 'member_join_date_relative', 'new' => 'membership_join_date_relative'],
+        ['old' => 'member_join_date_high', 'new' => 'membership_join_date_high'],
+        ['old' => 'member_join_date_low', 'new' => 'membership_join_date_low'],
+        ['old' => 'member_start_date_relative', 'new' => 'membership_start_date_relative'],
+        ['old' => 'member_start_date_high', 'new' => 'membership_start_date_high'],
+        ['old' => 'member_start_date_low', 'new' => 'membership_start_date_low'],
+        ['old' => 'member_end_date_relative', 'new' => 'membership_end_date_relative'],
+        ['old' => 'member_end_date_high', 'new' => 'membership_end_date_high'],
+        ['old' => 'member_end_date_low', 'new' => 'membership_end_date_low'],
       ],
     ]);
     $this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', [
@@ -93,6 +104,9 @@ class CRM_Upgrade_Incremental_php_FiveEighteen extends CRM_Upgrade_Incremental_B
         'pledge_create_date',
         'pledge_end_date',
         'pledge_start_date',
+        'membership_join_date',
+        'membership_end_date',
+        'membership_start_date',
       ],
     ]);
     $this->addTask('Update civicrm_mapping_field and civicrm_uf_field for change in join_date name', 'updateJoinDateMappingUF');
index 38d8b78b37773faf1f0b1b183e4df12862420b0b..79592f98597fa5344d305cd5975b364c38082f96 100644 (file)
 </tr>
 
 <tr>
-  <td>
-  {$form.member_source.label}
-    <br />{$form.member_source.html}
-    <p>
-    {$form.member_test.label} {help id="is-test" file="CRM/Contact/Form/Search/Advanced"} &nbsp;{$form.member_test.html}
-    </p>
+  <td>{$form.member_source.label}<br />
+    {$form.member_source.html}
   </td>
   <td>
-    <p>
-    {$form.membership_is_current_member.label}
+    {$form.membership_is_current_member.label}<br />
     {$form.membership_is_current_member.html}
-    </p>
-    <p>
-    {$form.member_is_primary.label}
-    {help id="id-member_is_primary" file="CRM/Member/Form/Search.hlp"}
-    {$form.member_is_primary.html}
-    </p>
-    <p>
-    {$form.member_pay_later.label}&nbsp;{$form.member_pay_later.html}
-    </p>
-    <p>
-      {if $form.member_auto_renew}
-          <label>{$form.member_auto_renew.label}</label>
-          {help id="id-member_auto_renew" file="CRM/Member/Form/Search.hlp"}
-          <br/>
-          {$form.member_auto_renew.html}
-        {/if}
-    </p>
-    <p>
-    {$form.member_is_override.label}
-    {help id="id-member_is_override" file="CRM/Member/Form/Search.hlp"}
-    {$form.member_is_override.html}
-    </p>
   </td>
 </tr>
-
+<tr>
+  <td>{$form.member_test.label} {help id="is-test" file="CRM/Contact/Form/Search/Advanced"} &nbsp;{$form.member_test.html}
+  </td>
+  <td>
+    {$form.member_is_primary.label} {help id="id-member_is_primary" file="CRM/Member/Form/Search.hlp"} {$form.member_is_primary.html}
+  </td>
+</tr>
 <tr><td><label>{$form.membership_id.label}</label> {$form.membership_id.html}</td>
+  <td>{$form.member_pay_later.label}&nbsp;{$form.member_pay_later.html}</td>
 </tr>
-
-<tr><td><label>{ts}Member Since{/ts}</label></td></tr>
 <tr>
-{include file="CRM/Core/DateRange.tpl" fieldName="member_join_date" from='_low' to='_high'}
+  <td>
+    {if $form.member_auto_renew}
+      <label>{$form.member_auto_renew.label}</label>
+      {help id="id-member_auto_renew" file="CRM/Member/Form/Search.hlp"}
+      <br/>
+      {$form.member_auto_renew.html}
+    {/if}
+  </td>
+  <td>{$form.member_is_override.label}{help id="id-member_is_override" file="CRM/Member/Form/Search.hlp"}{$form.member_is_override.html}</td>
 </tr>
-
-<tr><td><label>{ts}Start Date{/ts}</label></td></tr>
 <tr>
-{include file="CRM/Core/DateRange.tpl" fieldName="member_start_date" from='_low' to='_high'}
+  {include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="membership_join_date" colspan='2'}
+</tr>
+<tr>
+  {include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="membership_start_date" colspan='2'}
 </tr>
-
-<tr><td><label>{ts}End Date{/ts}</label></td></tr>
 <tr>
-{include file="CRM/Core/DateRange.tpl" fieldName="member_end_date" from='_low' to='_high'}
+  {include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="membership_end_date" colspan='2'}
 </tr>
 
 {* campaign in membership search *}
index cfd4dc1ff9d4afd9d27c5a2790589d308a69abb5..f33db8e4a6eda8471eccc350fc9fc0fd3b26578c 100644 (file)
@@ -62,7 +62,7 @@
         {$row.membership_type}{if $row.is_test} ({ts}test{/ts}){/if}
         {if $row.owner_membership_id}<br />({ts}by relationship{/ts}){/if}
     </td>
-    <td class="crm-membership-join_date">{$row.join_date|truncate:10:''|crmDate}</td>
+    <td class="crm-membership-join_date">{$row.membership_join_date|truncate:10:''|crmDate}</td>
     <td class="crm-membership-start_date">{$row.membership_start_date|truncate:10:''|crmDate}</td>
     <td class="crm-membership-end_date">{$row.membership_end_date|truncate:10:''|crmDate}</td>
     <td class="crm-membership-source">{$row.membership_source}</td>