Support url defaults on event search
authoreileen <emcnaughton@wikimedia.org>
Fri, 7 Jun 2019 05:16:59 +0000 (17:16 +1200)
committereileen <emcnaughton@wikimedia.org>
Mon, 24 Jun 2019 22:15:41 +0000 (10:15 +1200)
This adds url support for sort_name & participant_status_id & participant_register_date to event search

civicrm/event/search?reset=1&sort_name=p&participant_status_id=1&participant_register_date_low=20180101

CRM/Core/Form/Search.php
CRM/Event/Form/Search.php

index 481051512f4544c908165b5215fc0271b65b533a..29576459915cfee6c6a56140e64429962e73d3fe 100644 (file)
@@ -132,7 +132,11 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
    * @throws \Exception
    */
   public function setDefaultValues() {
-    return array_merge($this->getEntityDefaults($this->getDefaultEntity()), (array) $this->_formValues);
+    $defaults = (array) $this->_formValues;
+    foreach (['Contact', $this->getDefaultEntity()] as $entity) {
+      $defaults = array_merge($this->getEntityDefaults($entity), $defaults);
+    }
+    return $defaults;
   }
 
   /**
@@ -251,16 +255,16 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
    */
   protected function getEntityDefaults($entity) {
     $defaults = [];
-    foreach ($this->getSearchFieldMetadata()[$entity] as $fieldName => $fieldSpec) {
-      if (empty($_POST[$fieldSpec['name']])) {
-        $value = CRM_Utils_Request::retrieveValue($fieldName, $this->getValidationTypeForField($entity, $fieldName), FALSE, NULL, 'GET');
+    foreach (CRM_Utils_Array::value($entity, $this->getSearchFieldMetadata(), []) as $fieldName => $fieldSpec) {
+      if (empty($_POST[$fieldName])) {
+        $value = CRM_Utils_Request::retrieveValue($fieldName, $this->getValidationTypeForField($entity, $fieldName), NULL, NULL, 'GET');
         if ($value !== NULL) {
           $defaults[$fieldName] = $value;
         }
         if ($fieldSpec['type'] === CRM_Utils_Type::T_DATE || ($fieldSpec['type'] === CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME)) {
-          $low = CRM_Utils_Request::retrieveValue($fieldName . '_low', 'Timestamp', FALSE, NULL, 'GET');
-          $high = CRM_Utils_Request::retrieveValue($fieldName . '_high', 'Timestamp', FALSE, NULL, 'GET');
-          if ($low !== FALSE || $high !== FALSE) {
+          $low = CRM_Utils_Request::retrieveValue($fieldName . '_low', 'Timestamp', NULL, NULL, 'GET');
+          $high = CRM_Utils_Request::retrieveValue($fieldName . '_high', 'Timestamp', NULL, NULL, 'GET');
+          if ($low !== NULL || $high !== NULL) {
             $defaults[$fieldName . '_relative'] = 0;
             $defaults[$fieldName . '_low'] = $low ? date('Y-m-d H:i:s', strtotime($low)) : NULL;
             $defaults[$fieldName . '_high'] = $high ? date('Y-m-d H:i:s', strtotime($high)) : NULL;
@@ -327,12 +331,14 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
    * to define the string.
    */
   protected function addSortNameField() {
+    $title = civicrm_api3('setting', 'getvalue', ['name' => 'includeEmailInName', 'group' => 'Search Preferences']) ? $this->getSortNameLabelWithEmail() : $this->getSortNameLabelWithOutEmail();
     $this->addElement(
       'text',
       'sort_name',
-      civicrm_api3('setting', 'getvalue', ['name' => 'includeEmailInName', 'group' => 'Search Preferences']) ? $this->getSortNameLabelWithEmail() : $this->getSortNameLabelWithOutEmail(),
+      $title,
       CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')
     );
+    $this->searchFieldMetadata['Contact']['sort_name'] = ['name' => 'sort_name', 'title' => $title, 'type' => CRM_Utils_Type::T_STRING];
   }
 
   /**
index 412590c22a540444d3985f524a2c223d29e56c13..e53572d90d2f8353d1fec5ed244e550a487d9f64 100644 (file)
@@ -419,19 +419,6 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search {
   public function addRules() {
   }
 
-  /**
-   * Set the default form values.
-   *
-   *
-   * @return array
-   *   the default array reference
-   */
-  public function setDefaultValues() {
-    $defaults = [];
-    $defaults = $this->_formValues;
-    return $defaults;
-  }
-
   public function fixFormValues() {
     // if this search has been forced
     // then see if there are any get values, and if so over-ride the post values