Commit 9fcfcb20 authored by ErikHommel's avatar ErikHommel
Browse files

fix issue 6767 for all relevant cases

parent 77109695
......@@ -29,9 +29,13 @@ class CRM_Nbrprojectvolunteerlist_NbrParticipation {
$studyId = (int) $searchFormValues['study_id'];
if ($studyId) {
$contactIds = $form->getVar('_contactIds');
$caseIds = [];
foreach ($contactIds as $contactId) {
$caseId = CRM_Nihrbackbone_NbrVolunteerCase::getActiveParticipationCaseId($studyId, $contactId);
$form->setVar('_caseId', $caseId);
$caseIds[] = CRM_Nihrbackbone_NbrVolunteerCase::getActiveParticipationCaseId($studyId, $contactId);
}
if (!empty($caseIds)) {
$session = CRM_Core_Session::singleton();
$session->nbr_email_case_ids = $caseIds;
}
}
}
......@@ -39,5 +43,20 @@ class CRM_Nbrprojectvolunteerlist_NbrParticipation {
}
}
public static function fileEmailOnCases($activityId) {
// only if case ids in session (put there in buildForm of email
// task if iniated from MSP screen
$session = CRM_Core_Session::singleton();
if (isset($session->nbr_email_case_ids)) {
foreach ($session->nbr_email_case_ids as $caseId) {
$insert = "INSERT INTO civicrm_case_activity (case_id, activity_id) VALUES(%1, %2)";
CRM_Core_DAO::executeQuery($insert, [
1 => [(int) $caseId, "Integer"],
2 => [(int) $activityId, "Integer"],
]);
unset($session->nbr_email_case_ids);
}
}
}
}
......@@ -3,6 +3,19 @@
require_once 'nbrprojectvolunteerlist.civix.php';
use CRM_Nbrprojectvolunteerlist_ExtensionUtil as E;
function nbrprojectvolunteerlist_civicrm_post($op, $objectName, $objectId, &$objectRef) {
if ($objectName == "Activity" && $op == "create") {
// only if email activity type id
if ($objectRef->activity_type_id == Civi::service('nbrBackbone')->getEmailActivityTypeId()) {
if (CRM_Core_Transaction::isActive()) {
CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, 'CRM_Nbrprojectvolunteerlist_NbrParticipation::fileEmailOnCases', [$objectId]);
}
else {
CRM_Nbrprojectvolunteerlist_NbrParticipation::fileEmailOnCases($objectId);
}
}
}
}
/**
* Implements hook_civicrm_buildForm
*
......@@ -15,7 +28,6 @@ function nbrprojectvolunteerlist_civicrm_buildForm($formName, &$form) { # jb2
}
}
/**
* Implements hook_civicrm_searchTasks().
*
......
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