Skip to content

Commit

Permalink
Merge pull request #15990 from eileenmcnaughton/act_search
Browse files Browse the repository at this point in the history
Fix activity search to work by url params
  • Loading branch information
seamuslee001 authored Nov 30, 2019
2 parents 5b13270 + 1c1e779 commit bb3a3d0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
9 changes: 7 additions & 2 deletions CRM/Activity/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,13 @@ public static function select(&$query) {
/**
* Given a list of conditions in query generate the required where clause.
*
* @param $query
* @param \CRM_Contact_BAO_Query $query
*
* @throws \CRM_Core_Exception
*/
public static function where(&$query) {
foreach (array_keys($query->_params) as $id) {
if (substr($query->_params[$id][0], 0, 9) == 'activity_') {
if (substr($query->_params[$id][0], 0, 9) === 'activity_') {
if ($query->_mode == CRM_Contact_BAO_Query::MODE_CONTACTS) {
$query->_useDistinct = TRUE;
}
Expand Down Expand Up @@ -457,6 +459,9 @@ public static function getSearchFieldMetadata() {
'title' => ts('Activity Text'),
'type' => CRM_Utils_Type::T_STRING,
'is_pseudofield' => TRUE,
'html' => [
'type' => 'Text',
],
];
return $metadata;
}
Expand Down
52 changes: 23 additions & 29 deletions CRM/Activity/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ class CRM_Activity_Form_Search extends CRM_Core_Form_Search {
*
* @var bool
*/
protected $_limit = NULL;
protected $_limit;

/**
* Prefix for the controller.
* @var string
*/
protected $_prefix = "activity_";
protected $_prefix = 'activity_';

/**
* The saved search ID retrieved from the GET vars.
Expand All @@ -63,6 +63,9 @@ public function getDefaultEntity() {

/**
* Processing needed for buildForm and later.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function preProcess() {
$this->set('searchFormName', 'Search');
Expand All @@ -73,37 +76,14 @@ public function preProcess() {

$this->_done = FALSE;

$this->loadStandardSearchOptionsFromUrl();

// get user submitted values
// get it from controller only if form has been submitted, else preProcess has set this
if (!empty($_POST) && !$this->controller->isModal()) {
$this->_formValues = $this->controller->exportValues($this->_name);
}
else {
$this->_formValues = $this->get('formValues');

if ($this->_force) {
// If we force the search then merge form values with url values
// and set submit values to form values.
// @todo this is not good security practice. Instead define the fields in metadata & use
// getEntityDefaults.
$this->_formValues = array_merge((array) $this->_formValues, CRM_Utils_Request::exportValues());
$this->_submitValues = $this->_formValues;
}
}
parent::preProcess();

if (empty($this->_formValues)) {
if (isset($this->_ssID)) {
$this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
}
}

if ($this->_force) {
$this->postProcess();
$this->set('force', 0);
}

$sortID = NULL;
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
Expand Down Expand Up @@ -143,6 +123,9 @@ public function preProcess() {

/**
* Build the form object.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function buildQuickForm() {
parent::buildQuickForm();
Expand Down Expand Up @@ -210,7 +193,6 @@ public function postProcess() {

$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);

$this->set('formValues', $this->_formValues);
$this->set('queryParams', $this->_queryParams);

$buttonName = $this->controller->getButtonName();
Expand Down Expand Up @@ -242,7 +224,7 @@ public function postProcess() {
$selector->setKey($this->controller->_key);

$prefix = NULL;
if ($this->_context == 'basic' || $this->_context == 'user') {
if ($this->_context === 'basic' || $this->_context === 'user') {
$prefix = $this->_prefix;
}

Expand All @@ -257,12 +239,17 @@ public function postProcess() {
$controller->setEmbedded(TRUE);
$query = &$selector->getQuery();

if ($this->_context == 'user') {
if ($this->_context === 'user') {
$query->setSkipPermission(TRUE);
}
$controller->run();
}

/**
* Probably more hackery than anything else.
*
* @throws \CRM_Core_Exception
*/
public function fixFormValues() {
if (!$this->_force) {
return;
Expand Down Expand Up @@ -337,6 +324,13 @@ public function getTitle() {
return ts('Find Activities');
}

/**
* Get metadata for the entity fields.
*
* @return array
*
* @throws \CiviCRM_API3_Exception
*/
protected function getEntityMetadata() {
return CRM_Activity_BAO_Query::getSearchFieldMetadata();
}
Expand Down

0 comments on commit bb3a3d0

Please sign in to comment.