dev/core#1410 Fix E-notice when doin a force case search with a predefined case subje...
authorSeamus Lee <seamuslee001@gmail.com>
Thu, 21 Nov 2019 20:40:39 +0000 (07:40 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Fri, 22 Nov 2019 00:12:13 +0000 (11:12 +1100)
CRM/Case/BAO/Query.php
CRM/Case/Form/Search.php

index 0e18cf592784b1b6ceb26c090bd15c4251aae940..078679588cc5f69ecc291bf3a8bdf0e280329d73 100644 (file)
@@ -252,6 +252,8 @@ class CRM_Case_BAO_Query extends CRM_Core_BAO_Query {
       return;
     }
     list($name, $op, $value, $grouping, $wildcard) = $values;
+    $fields = CRM_Case_BAO_Case::fields();
+    $fieldSpec = $fields[$values[0]] ?? [];
     $val = $names = [];
     switch ($name) {
 
@@ -315,10 +317,7 @@ class CRM_Case_BAO_Query extends CRM_Core_BAO_Query {
         return;
 
       case 'case_subject':
-        $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case.subject", $op, $value, 'String');
-        $query->_qill[$grouping][] = CRM_Contact_BAO_Query::getQillValue('CRM_Case_DAO_Case', $name, $value, $op, 'Case Subject');
-        $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
-        $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
+        $query->handleWhereFromMetadata($fieldSpec, $name, $value, $op);
         return;
 
       case 'case_source_contact_id':
index e1b31328dc3e69d73365d408d956ef42af230b52..ffad397c9f49405ae0f691da37de3dedfed5ac7c 100644 (file)
@@ -80,12 +80,7 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search {
 
     $this->_done = FALSE;
 
-    $this->loadStandardSearchOptionsFromUrl();
-    $this->loadFormValues();
-
-    if ($this->_force) {
-      $this->handleForcedSearch();
-    }
+    parent::preProcess();
 
     $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
     $selector = new CRM_Case_Selector_Search($this->_queryParams,
@@ -188,6 +183,7 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search {
 
     $this->_done = TRUE;
     $this->setFormValues();
+    // @todo - stop changing formValues - respect submitted form values, change a working array.
     $this->fixFormValues();
     if (isset($this->_ssID) && empty($_POST)) {
       // if we are editing / running a saved search and the form has not been posted
@@ -196,19 +192,22 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search {
 
     //search for civicase
     if (!$this->_force) {
+      // @todo - stop changing formValues - respect submitted form values, change a working array.
       if (array_key_exists('case_owner', $this->_formValues) && !$this->_formValues['case_owner']) {
         $this->_formValues['case_owner'] = 0;
       }
     }
 
+    // @todo - stop changing formValues - respect submitted form values, change a working array.
     if (empty($this->_formValues['case_deleted'])) {
       $this->_formValues['case_deleted'] = 0;
     }
+    // @todo - stop changing formValues - respect submitted form values, change a working array.
     CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);
 
+    // @todo - stop changing formValues - respect submitted form values, change a working array.
     $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
 
-    $this->set('formValues', $this->_formValues);
     $this->set('queryParams', $this->_queryParams);
 
     $buttonName = $this->controller->getButtonName();
@@ -258,37 +257,6 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search {
     $controller->run();
   }
 
-  /**
-   * Add the rules (mainly global rules) for form.
-   *
-   * All local rules are added near the element
-   *
-   * @see valid_date
-   */
-  public function addRules() {
-    $this->addFormRule(['CRM_Case_Form_Search', 'formRule']);
-  }
-
-  /**
-   * Global validation rules for the form.
-   *
-   * @param array $fields
-   *   Posted values of the form.
-   * @param array $files
-   * @param object $form
-   *
-   * @return array|bool
-   */
-  public static function formRule($fields, $files, $form) {
-    $errors = [];
-
-    if (!empty($errors)) {
-      return $errors;
-    }
-
-    return TRUE;
-  }
-
   public function fixFormValues() {
     if (!$this->_force) {
       return;