Commit b3e268b4 authored by ErikHommel's avatar ErikHommel
Browse files

fix issue 6357 test result

parent a3d6140d
......@@ -22,51 +22,9 @@ class CRM_Nbrprojectvolunteerlist_Form_Search_VolunteerList extends CRM_Contact_
$formValues = array_merge($this->getEntityDefaults($entity), $formValues);
}
}
else {
$this->clearFilters($formValues);
}
parent::__construct($formValues);
}
/**
* Method to clear filters
*/
private function clearFilters($formValues) {
// only if this is a "fresh" call of the search and filters are empty (apart from study_id which is always used)
$qfDefault = CRM_Utils_Request::retrieveValue('_qf_default', 'String');
$filters = $this->getFilters();
unset($filters['study_id']);
$hasFilters = FALSE;
foreach ($formValues as $formKey => $formValue) {
if (in_array($formKey, $filters)) {
$hasFilters = TRUE;
}
}
if ($qfDefault == "Custom:refresh") {
$hasFilters = TRUE;
}
if ($hasFilters == FALSE) {
Civi::settings()->set(CRM_Nbrprojectvolunteerlist_Utils::getFilterSettingName(), []);
}
}
/**
* Method om filters op te halen
*
* @return array
*/
private function getFilters() {
return [
'study_id',
'first_name',
'last_name',
'gender_id',
'recall_group',
'study_status_id',
'age_from',
'age_to',
];
}
/**
* Prepare a set of search fields
*
......@@ -304,7 +262,6 @@ class CRM_Nbrprojectvolunteerlist_Form_Search_VolunteerList extends CRM_Contact_
$where .= ' AND ' . implode(' AND ', $clauses);
}
$this->addMultipleClauses($index, $where, $params);
$this->setFiltersForUser();
return $this->whereClause($where, $params);
}
......@@ -575,40 +532,8 @@ class CRM_Nbrprojectvolunteerlist_Form_Search_VolunteerList extends CRM_Contact_
if ($this->_studyId) {
$defaults['study_id'] = $this->_studyId;
}
$this->setDefaultsWithFilters($defaults);
}
return $defaults;
}
/**
* Method to save the filters for the user in setting
*/
private function setFiltersForUser() {
$values = [];
$filters = $this->getFilters();
foreach ($filters as $filter) {
if (isset($this->_formValues[$filter])) {
$values[$filter] = $this->_formValues[$filter];
}
}
if (!empty($values)) {
Civi::settings()->set(CRM_Nbrprojectvolunteerlist_Utils::getFilterSettingName(), $values);
}
}
/**
* Methode to set the filters if they were saved for the user
*
* @param $defaults
*/
private function setDefaultsWithFilters(&$defaults) {
$filters = Civi::settings()->get(CRM_Nbrprojectvolunteerlist_Utils::getFilterSettingName());
if (!empty($filters)) {
foreach ($filters as $key => $value) {
$defaults[$key] = $value;
}
}
}
}
......@@ -147,8 +147,8 @@ class CRM_Nbrprojectvolunteerlist_Form_Task_InviteByEmail extends CRM_Contact_Fo
* Overridden parent method
*/
public function postProcess() {
// only if we have a study, contactIds and a template
if (isset($this->_studyId) && !empty($this->_contactIds) && !empty($this->_submitValues['template_id'])) {
// only if we have a study, invited ids and a template
if (isset($this->_studyId) && !empty($this->_invited) && !empty($this->_submitValues['template_id'])) {
// first find all relevant cases
$caseIds = $this->getRelevantCaseIds();
// then send email (include case_id so the activity is recorded) and add an invited activity
......@@ -177,33 +177,30 @@ class CRM_Nbrprojectvolunteerlist_Form_Task_InviteByEmail extends CRM_Contact_Fo
*/
private function getRelevantCaseIds() {
$caseIds = [];
$participationTable = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationDataCustomGroup('table_name');
$studyColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationCustomField('nvpd_study_id', 'column_name');
$query = "SELECT ccc.case_id, ccc.contact_id
if (!empty($this->_invited)) {
$participationTable = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationDataCustomGroup('table_name');
$studyColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationCustomField('nvpd_study_id', 'column_name');
$query = "SELECT ccc.case_id, ccc.contact_id
FROM " . $participationTable. " AS cvnpd
LEFT JOIN civicrm_case_contact AS ccc ON cvnpd.entity_id = ccc.case_id
LEFT JOIN civicrm_case AS cc ON ccc.case_id = cc.id
WHERE cvnpd." . $studyColumn . " = %2 AND cc.is_deleted = %3";
$queryParams = [
1 => [1, "Integer"],
2 => [$this->_studyId, "Integer"],
3 => [0, "Integer"],
WHERE cvnpd." . $studyColumn . " = %2 AND cc.is_deleted = %3 AND ccc.contact_id IN(";
$queryParams = [
1 => [1, "Integer"],
2 => [$this->_studyId, "Integer"],
3 => [0, "Integer"],
];
$i = 3;
$contactIds = [];
if (!empty($this->_invited)) {
$query .= " AND ccc.contact_id IN (";
$i = 3;
$contactIds = [];
foreach ($this->_invited as $invitedId => $invitedData) {
$contactIds[] = $invitedId;
}
}
$elements = CRM_Nbrprojectvolunteerlist_Utils::processContactQueryElements($contactIds, $i, $queryParams);
if (!empty($contactIds)) {
$elements = CRM_Nbrprojectvolunteerlist_Utils::processContactQueryElements($contactIds, $i, $queryParams);
$query .= implode("," , $elements) . ")";
}
$dao = CRM_Core_DAO::executeQuery($query, $queryParams);
while ($dao->fetch()) {
$caseIds[$dao->case_id] = $dao->contact_id;
$dao = CRM_Core_DAO::executeQuery($query, $queryParams);
while ($dao->fetch()) {
$caseIds[$dao->case_id] = $dao->contact_id;
}
}
return $caseIds;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment