From 4041c9b6822697707d1a559cbcc7a01ee2f0d275 Mon Sep 17 00:00:00 2001 From: Dave Greenberg Date: Mon, 23 Dec 2013 13:39:07 -0800 Subject: [PATCH] CRM-13978 - Replaces PR 2219 which had all the right changs BUT omitted the activity tagset filter. ---------------------------------------- * CRM-13978: search on activity result field http://issues.civicrm.org/jira/browse/CRM-13978 --- CRM/Activity/BAO/Query.php | 48 ++++++++++++++++++- CRM/Contact/BAO/Query.php | 1 + templates/CRM/Activity/Form/Search/Common.tpl | 23 +++++++-- 3 files changed, 66 insertions(+), 6 deletions(-) diff --git a/CRM/Activity/BAO/Query.php b/CRM/Activity/BAO/Query.php index fe33396de0..ed3b9b07fc 100644 --- a/CRM/Activity/BAO/Query.php +++ b/CRM/Activity/BAO/Query.php @@ -143,6 +143,12 @@ class CRM_Activity_BAO_Query { $query->_element['source_contact'] = 1; $query->_tables['source_contact'] = $query->_whereTables['source_contact'] = 1; } + + if (CRM_Utils_Array::value('activity_result', $query->_returnProperties)) { + $query->_select['activity_result'] = 'civicrm_activity.result as activity_result'; + $query->_element['result'] = 1; + $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1; + } } /** @@ -364,7 +370,17 @@ class CRM_Activity_BAO_Query { 'tableName' => 'civicrm_activity', ); CRM_Campaign_BAO_Query::componentSearchClause($campParams, $query); - return; + break; + case 'activity_result': + if(is_array($value)) { + $safe = NULL; + while(list(,$k) = each($value)) { + $safe[] = "'" . CRM_Utils_Type::escape($k, 'String') . "'"; + } + $query->_where[$grouping][] = "civicrm_activity.result IN (" . implode(',', $safe) . ")"; + $query->_qill[$grouping][] = ts("Activity Result - %1", array(1 => implode(' or ', $safe))); + } + break; } } @@ -498,6 +514,7 @@ class CRM_Activity_BAO_Query { //add engagement level CRM-7775 $buildEngagementLevel = FALSE; + $buildSurveyResult = FALSE; if (CRM_Campaign_BAO_Campaign::isCampaignEnable() && CRM_Campaign_BAO_Campaign::accessCampaign() ) { @@ -506,9 +523,35 @@ class CRM_Activity_BAO_Query { ts('Engagement Index'), array('' => ts('- any -')) + CRM_Campaign_PseudoConstant::engagementLevel() ); - } + // Add survey result field. + $optionGroups = CRM_Campaign_BAO_Survey::getResultSets( 'name' ); + $resultOptions = array(); + foreach ( $optionGroups as $gid => $name ) { + if ( $name ) { + $value = array(); + $value = CRM_Core_OptionGroup::values($name); + if (!empty($value)) { + while(list($k,$v) = each($value)) { + $resultOptions[$v] = $v; + } + } + } + } + // If no survey result options have been created, don't build + // the field to avoid clutter. + if(count($resultOptions) > 0) { + $buildSurveyResult = TRUE; + asort($resultOptions); + $form->add('select', 'activity_result', ts("Survey Result"), + $resultOptions, FALSE, + array('id' => 'activity_result', 'multiple' => 'multiple', 'title' => ts('- select -')) + ); + } + } + $form->assign('buildEngagementLevel', $buildEngagementLevel); + $form->assign('buildSurveyResult', $buildSurveyResult); $form->setDefaults(array('activity_test' => 0)); } @@ -537,6 +580,7 @@ class CRM_Activity_BAO_Query { 'source_record_id' => 1, 'activity_is_test' => 1, 'activity_campaign_id' => 1, + 'result' => 1, 'activity_engagement_level' => 1, ); diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 6b981e6f41..ba339290b3 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1626,6 +1626,7 @@ class CRM_Contact_BAO_Query { case 'activity_campaign_id': case 'activity_engagement_level': case 'activity_id': + case 'activity_result': case 'source_contact': CRM_Activity_BAO_Query::whereClauseSingle($values, $this); return; diff --git a/templates/CRM/Activity/Form/Search/Common.tpl b/templates/CRM/Activity/Form/Search/Common.tpl index 16d7e38d09..236d72082c 100644 --- a/templates/CRM/Activity/Form/Search/Common.tpl +++ b/templates/CRM/Activity/Form/Search/Common.tpl @@ -108,10 +108,25 @@ - - - {include file="CRM/common/Tag.tpl" tagsetType='activity'} - +{if $buildSurveyResult } + + +
+ {$form.activity_result.html} + + + {include file="CRM/common/Tag.tpl" tagsetType='activity'} + +{else} + + {include file="CRM/common/Tag.tpl" tagsetType='activity'} + +{/if} {* campaign in activity search *} {include file="CRM/Campaign/Form/addCampaignToComponent.tpl" -- 2.25.1