Skip to content
Snippets Groups Projects
Commit 9231464f authored by Kurund Jalmi's avatar Kurund Jalmi
Browse files

CRM-12514 expose petitions on activity search along with surveys

parent dabf18d0
No related branches found
No related tags found
No related merge requests found
......@@ -525,8 +525,8 @@ class CRM_Activity_BAO_Query {
$parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity');
CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_activity', NULL, TRUE, FALSE, TRUE);
$surveys = CRM_Campaign_BAO_Survey::getSurveys();
if ($surveys) $form->add('select', 'activity_survey_id', ts('Survey'),
$surveys = CRM_Campaign_BAO_Survey::getSurveys(TRUE, FALSE, FALSE, TRUE);
if ($surveys) $form->add('select', 'activity_survey_id', ts('Survey / Petition'),
array(
'' => ts('- none -')) + $surveys, FALSE
);
......
......@@ -326,13 +326,6 @@ class CRM_Activity_Form_Search extends CRM_Core_Form {
// if we are editing / running a saved search and the form has not been posted
$this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
}
if (CRM_Utils_Array::value('activity_survey_id', $this->_formValues)) {
// if the user has choosen a survey but not any activity type, we force the activity type
$sid = CRM_Utils_Array::value('activity_survey_id', $this->_formValues);
$activity_type_id = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $sid, 'activity_type_id');
$this->_formValues['activity_type_id'][$activity_type_id] = 1;
}
if (!CRM_Utils_Array::value('activity_test', $this->_formValues)) {
$this->_formValues["activity_test"] = 0;
......@@ -410,7 +403,12 @@ class CRM_Activity_Form_Search extends CRM_Core_Form {
$survey = CRM_Utils_Request::retrieve('survey', 'Positive', CRM_Core_DAO::$_nullObject);
if ($survey) {
$this->_formValues['activity_survey_id'] = $survey;
$this->_formValues['activity_survey_id'] = $this->_defaults['activity_survey_id'] = $survey;
$sid = CRM_Utils_Array::value('activity_survey_id', $this->_formValues);
$activity_type_id = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $sid, 'activity_type_id');
$this->_formValues['activity_type_id'][$activity_type_id] = 1;
$this->_defaults['activity_type_id'][$activity_type_id] = 1;
}
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
......@@ -431,6 +429,11 @@ class CRM_Activity_Form_Search extends CRM_Core_Form {
$this->_single = TRUE;
}
}
if (!empty($this->_defaults)) {
$this->setDefaults($this->_defaults);
}
}
function getFormValues() {
......
......@@ -239,15 +239,13 @@ SELECT survey.id as id,
* @param boolean $onlyActive retrieve only active surveys.
* @param boolean $onlyDefault retrieve only default survey.
* @param boolean $forceAll retrieve all surveys.
* @param boolean $includePetition include or exclude petitions
*
* @static
*/
static function getSurveys($onlyActive = TRUE,
$onlyDefault = FALSE,
$forceAll = FALSE
) {
static function getSurveys($onlyActive = TRUE, $onlyDefault = FALSE, $forceAll = FALSE, $includePetition = FALSE ) {
$cacheKey = 0;
$cacheKeyParams = array('onlyActive', 'onlyDefault', 'forceAll');
$cacheKeyParams = array('onlyActive', 'onlyDefault', 'forceAll', 'includePetition');
foreach ($cacheKeyParams as $param) {
$cacheParam = $$param;
if (!$cacheParam) {
......@@ -259,14 +257,15 @@ SELECT survey.id as id,
static $surveys;
if (!isset($surveys[$cacheKey])) {
//we only have activity type as a
//difference between survey and petition.
$petitionTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'petition', 'name');
$where = array();
if ($petitionTypeID) {
$where[] = "( survey.activity_type_id != {$petitionTypeID} )";
if (!$includePetition) {
//we only have activity type as a
//difference between survey and petition.
$petitionTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'petition', 'name');
$where = array();
if ($petitionTypeID) {
$where[] = "( survey.activity_type_id != {$petitionTypeID} )";
}
}
if (!$forceAll && $onlyActive) {
$where[] = '( survey.is_active = 1 )';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment