Skip to content

Commit

Permalink
Support url defaults on event search
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eileenmcnaughton committed Jun 24, 2019
1 parent 6bf455b commit e8082ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
22 changes: 14 additions & 8 deletions CRM/Core/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ public function addSearchFieldMetadata($searchFieldMetadata) {
* @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;
}

/**
Expand Down Expand Up @@ -251,16 +255,16 @@ protected function getValidationTypeForField($entity, $fieldName) {
*/
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;
Expand Down Expand Up @@ -327,12 +331,14 @@ public function addTaskMenu($tasks) {
* 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];
}

/**
Expand Down
13 changes: 0 additions & 13 deletions CRM/Event/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,19 +419,6 @@ public function postProcess() {
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
Expand Down

0 comments on commit e8082ca

Please sign in to comment.