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

Merge pull request #774 from kurund/CRM-12514

CRM-12514 expose petitions on activity search along with surveys
parents 35fe6d7e 9231464f
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
);
......
......@@ -255,8 +255,6 @@ class CRM_Activity_Form_Search extends CRM_Core_Form {
}
}
$total = $cancel = 0;
$permission = CRM_Core_Permission::getPermission();
$tasks = array('' => ts('- actions -')) + CRM_Activity_Task::permissionedTaskTitles($permission);
......@@ -328,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;
......@@ -399,51 +390,6 @@ class CRM_Activity_Form_Search extends CRM_Core_Form {
$controller->run();
}
/**
* This function is used to add the rules (mainly global rules) for form.
* All local rules are added near the element
*
* @return None
* @access public
* @see valid_date
*/
function addRules() {
$this->addFormRule(array('CRM_Activity_Form_Search', 'formRule'));
}
/**
* global validation rules for the form
*
* @param array $fields posted values of the form
* @param array $errors list of errors to be posted back to the form
*
* @return void
* @static
* @access public
*/
static function formRule($fields) {
$errors = array();
if (!empty($errors)) {
return $errors;
}
return TRUE;
}
/**
* Set the default form values
*
* @access protected
*
* @return array the default array reference
*/
function setDefaultValues() { // TODO test?
$defaults = array();
$defaults = $this->_formValues;
return $defaults;
}
function fixFormValues() {
if (!$this->_force) {
return;
......@@ -454,11 +400,15 @@ class CRM_Activity_Form_Search extends CRM_Core_Form {
$this->_defaults['activity_status'] = $status;
}
$survey = CRM_Utils_Request::retrieve('survey', 'Positive',
CRM_Core_DAO::$_nullObject
);
$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);
......@@ -473,13 +423,17 @@ class CRM_Activity_Form_Search extends CRM_Core_Form {
$this->_formValues['activity_role'] = $activity_role;
}
else {
list($display, $image) = CRM_Contact_BAO_Contact::getDisplayAndImage($cid);
$this->_defaults['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'sort_name');
}
// also assign individual mode to the template
$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