Commit 0aef4c43 authored by ErikHommel's avatar ErikHommel
Browse files

fix issue 5097 - invite by email

parent 9ab55a3d
......@@ -106,6 +106,8 @@ class CRM_Nbrprojectvolunteerlist_Form_Search_VolunteerList extends CRM_Contact_
// return by reference
$columns = [
E::ts('Name') => 'sort_name',
E::ts('Bioresource ID') => 'nva_bioresource_id',
E::ts('Participant ID') => 'nva_participant_id',
E::ts('Study/Part ID') => 'nvpd_study_participant_id',
E::ts('Gender') => 'gender',
E::ts('Age') => 'birth_date',
......@@ -145,10 +147,13 @@ class CRM_Nbrprojectvolunteerlist_Form_Search_VolunteerList extends CRM_Contact_
$studyParticipantIDColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationCustomField('nvpd_study_participant_id', 'column_name');
$dateInvitedColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationCustomField('nvpd_date_invited', 'column_name');
$distanceColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationCustomField('nvpd_distance_volunteer_to_study_centre', 'column_name');
$bioresourceIdColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getVolunteerIdsCustomField('nva_bioresource_id', 'column_name');
$participantIdColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getVolunteerIdsCustomField('nva_participant_id', 'column_name');
return "
DISTINCT(contact_a.id) AS contact_id, contact_a.sort_name, contact_a.birth_date, genderov.label AS gender,
ethnicov.label AS ethnicity, adr.city AS volunteer_address, nvpd." . $eligibleColumn . ", nvpd.". $studyParticipantIDColumn . ", prostatus.label AS project_status,
stustatus.label AS study_status, nvpd." . $dateInvitedColumn . ", nvpd." . $distanceColumn;
ethnicov.label AS ethnicity, adr.city AS volunteer_address, nvpd." . $eligibleColumn . ", nvpd.". $studyParticipantIDColumn . ",
prostatus.label AS project_status, stustatus.label AS study_status, nvpd." . $dateInvitedColumn . ", nvpd." . $distanceColumn .
", nvi." . $bioresourceIdColumn . ", nvi." . $participantIdColumn;
}
/**
......@@ -159,6 +164,7 @@ class CRM_Nbrprojectvolunteerlist_Form_Search_VolunteerList extends CRM_Contact_
function from() {
$nvgoTable = CRM_Nihrbackbone_BackboneConfig::singleton()->getVolunteerGeneralObservationsCustomGroup('table_name');
$nvpdTable = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationDataCustomGroup('table_name');
$nviTable = CRM_Nihrbackbone_BackboneConfig::singleton()->getVolunteerIdsCustomGroup('table_name');
$genderOptionGroupId = CRM_Nihrbackbone_BackboneConfig::singleton()->getGenderOptionGroupId();
$ethnicityOptionGroupId = CRM_Nihrbackbone_BackboneConfig::singleton()->getEthnicityOptionGroupId();
$projectStatusOptionGroupId = CRM_Nihrbackbone_BackboneConfig::singleton()->getProjectParticipationStatusOptionGroupId();
......@@ -173,6 +179,7 @@ class CRM_Nbrprojectvolunteerlist_Form_Search_VolunteerList extends CRM_Contact_
LEFT JOIN " . $nvgoTable . " AS nvgo ON ccc.contact_id = nvgo.entity_id
LEFT JOIN civicrm_address AS adr ON contact_a.id = adr.contact_id AND adr.is_primary = 1
LEFT JOIN " . $nvpdTable . " AS nvpd ON cas.id = nvpd.entity_id
LEFT JOIN " . $nviTable . " AS nvi ON contact_a.id = nvi.entity_id
LEFT JOIN civicrm_option_value AS genderov ON contact_a.gender_id = genderov.value AND genderov.option_group_id = " . $genderOptionGroupId ."
LEFT JOIN civicrm_option_value AS ethnicov ON nvgo." . $ethnicityColumn . " = ethnicov.value AND ethnicov.option_group_id = " . $ethnicityOptionGroupId . "
LEFT JOIN civicrm_option_value AS prostatus ON nvpd." . $projectStatusColumn . " = prostatus.value AND prostatus.option_group_id = " . $projectStatusOptionGroupId . "
......
......@@ -21,19 +21,24 @@ class CRM_Nbrprojectvolunteerlist_Form_Task_ChangeProjectStatus extends CRM_Cont
*/
private function getSelectedData() {
$this->_selected = [];
$nviTable = CRM_Nihrbackbone_BackboneConfig::singleton()->getVolunteerIdsCustomGroup('table_name');
$studyParticipantColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationCustomField('nvpd_study_participant_id', 'column_name');
$eligiblesColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationCustomField('nvpd_eligible_status_id', 'column_name');
$projectColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationCustomField('nvpd_project_id', 'column_name');
$statusColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationCustomField('nvpd_study_participation_status', 'column_name');
$statusColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationCustomField('nvpd_project_participation_status', 'column_name');
$participantTable = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationDataCustomGroup('table_name');
$ovpsOptionGroupId = CRM_Nihrbackbone_BackboneConfig::singleton()->getProjectParticipationStatusOptionGroupId();
$bioresourceIdColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getVolunteerIdsCustomField('nva_bioresource_id', 'column_name');
$participantIdColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getVolunteerIdsCustomField('nva_participant_id', 'column_name');
$query = "
SELECT vol.id AS contact_id, vol.display_name, cvnpd." . $studyParticipantColumn . " AS study_participant_id,
cvnpd." . $eligiblesColumn . " AS eligible_status_id, ovps.label AS project_status
cvnpd." . $eligiblesColumn . " AS eligible_status_id, ovps.label AS project_status, nvi." . $bioresourceIdColumn
. " AS bioresource_id, nvi." . $participantIdColumn. " AS participant_id
FROM " . $participantTable . " AS cvnpd
JOIN civicrm_case_contact AS ccc ON cvnpd.entity_id = ccc.case_id
JOIN civicrm_case AS cas ON ccc.case_id = cas.id
JOIN civicrm_contact AS vol ON ccc.contact_id = vol.id
LEFT JOIN " . $nviTable . " AS nvi ON ccc.contact_id = nvi.entity_id
LEFT JOIN civicrm_option_value AS ovps ON cvnpd." . $statusColumn. " = ovps.value AND ovps.option_group_id = " . $ovpsOptionGroupId . "
WHERE cvnpd." . $projectColumn. " = %1 AND cas.is_deleted = %2 AND vol.id IN (";
$queryParams = [
......@@ -52,10 +57,18 @@ class CRM_Nbrprojectvolunteerlist_Form_Task_ChangeProjectStatus extends CRM_Cont
while ($dao->fetch()) {
$volunteer = [
'display_name' => $dao->display_name,
'bioresource_id' => $dao->bioresource_id,
'participant_id' => $dao->participant_id,
'study_participant_id' => $dao->study_participant_id,
'eligible_status' => implode(', ', CRM_Nihrbackbone_NbrVolunteerCase::getEligibleDescriptions($dao->eligible_status_id)),
'project_status' => $dao->project_status,
];
$eligibleStatus = implode(', ', CRM_Nihrbackbone_NbrVolunteerCase::getEligibleDescriptions($dao->eligible_status_id));
if (!empty($eligibleStatus)) {
$volunteer['eligible_status'] = $eligibleStatus;
}
else {
$volunteer['eligible_status'] = "Eligible";
}
$this->_selected[$dao->contact_id] = $volunteer;
}
}
......
......@@ -27,13 +27,18 @@ class CRM_Nbrprojectvolunteerlist_Form_Task_ChangeStudyStatus extends CRM_Contac
$statusColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationCustomField('nvpd_study_participation_status', 'column_name');
$participantTable = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationDataCustomGroup('table_name');
$ovssOptionGroupId = CRM_Nihrbackbone_BackboneConfig::singleton()->getStudyParticipationStatusOptionGroupId();
$bioresourceIdColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getVolunteerIdsCustomField('nva_bioresource_id', 'column_name');
$participantIdColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getVolunteerIdsCustomField('nva_participant_id', 'column_name');
$nviTable = CRM_Nihrbackbone_BackboneConfig::singleton()->getVolunteerIdsCustomGroup('table_name');
$query = "
SELECT vol.id AS contact_id, vol.display_name, cvnpd." . $studyParticipantColumn . " AS study_participant_id,
cvnpd." . $eligiblesColumn . " AS eligible_status_id, ovss.label AS study_status
cvnpd." . $eligiblesColumn . " AS eligible_status_id, ovss.label AS study_status, nvi." . $bioresourceIdColumn
. " AS bioresource_id, nvi." . $participantIdColumn . " AS participant_id
FROM " . $participantTable . " AS cvnpd
JOIN civicrm_case_contact AS ccc ON cvnpd.entity_id = ccc.case_id
JOIN civicrm_case AS cas ON ccc.case_id = cas.id
JOIN civicrm_contact AS vol ON ccc.contact_id = vol.id
LEFT JOIN " . $nviTable . " AS nvi ON ccc.contact_id = nvi.entity_id
LEFT JOIN civicrm_option_value AS ovss ON cvnpd." . $statusColumn . " = ovss.value AND ovss.option_group_id = " . $ovssOptionGroupId . "
WHERE cvnpd." . $projectColumn. " = %1 AND cas.is_deleted = %2 AND vol.id IN (";
$queryParams = [
......@@ -52,10 +57,18 @@ class CRM_Nbrprojectvolunteerlist_Form_Task_ChangeStudyStatus extends CRM_Contac
while ($dao->fetch()) {
$volunteer = [
'display_name' => $dao->display_name,
'bioresource_id' => $dao->bioresource_id,
'participant_id' => $dao->participant_id,
'study_participant_id' => $dao->study_participant_id,
'eligible_status' => implode(', ', CRM_Nihrbackbone_NbrVolunteerCase::getEligibleDescriptions($dao->eligible_status_id)),
'study_status' => $dao->study_status,
];
$eligibleStatus = implode(', ', CRM_Nihrbackbone_NbrVolunteerCase::getEligibleDescriptions($dao->eligible_status_id));
if (!empty($eligibleStatus)) {
$volunteer['eligible_status'] = $eligibleStatus;
}
else {
$volunteer['eligible_status'] = "Eligible";
}
$this->_selected[$dao->contact_id] = $volunteer;
}
}
......
......@@ -12,7 +12,9 @@ use CRM_Nbrprojectvolunteerlist_ExtensionUtil as E;
class CRM_Nbrprojectvolunteerlist_Form_Task_InviteByEmail extends CRM_Contact_Form_Task {
private $_countInvited = NULL;
private $_countInvalid = NULL;
private $_invited = [];
private $_invalids = [];
private $_projectId = NULL;
/**
......@@ -21,23 +23,27 @@ class CRM_Nbrprojectvolunteerlist_Form_Task_InviteByEmail extends CRM_Contact_Fo
*/
private function getInvitedData() {
$this->_invited = [];
$bioResourceColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getVolunteerAliasCustomField('nva_bioresource_id', 'column_name');
$this->_invalids = [];
$this->_countInvited = 0;
$this->_countInvalid = 0;
$studyParticipantColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationCustomField('nvpd_study_participant_id', 'column_name');
$eligiblesColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationCustomField('nvpd_eligible_status_id', 'column_name');
$projectColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationCustomField('nvpd_project_id', 'column_name');
$participantTable = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationDataCustomGroup('table_name');
$aliasTable = CRM_Nihrbackbone_BackboneConfig::singleton()->getVolunteerAliasCustomGroup('table_name');
$bioresourceIdColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getVolunteerIdsCustomField('nva_bioresource_id', 'column_name');
$participantIdColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getVolunteerIdsCustomField('nva_participant_id', 'column_name');
$nviTable = CRM_Nihrbackbone_BackboneConfig::singleton()->getVolunteerIdsCustomGroup('table_name');
$query = "
SELECT vol.id AS contact_id, vol.display_name, cvnva." . $bioResourceColumn . " AS bioresource_id,
cvnpd." . $studyParticipantColumn . " AS study_participant_id, cvnpd. "
SELECT vol.id AS contact_id, vol.display_name, nvi." . $bioresourceIdColumn . " AS bioresource_id,
nvi." . $participantIdColumn . " AS participant_id, cvnpd." . $studyParticipantColumn . " AS study_participant_id, cvnpd. "
. $eligiblesColumn. " AS eligible_status_id, ce.email
FROM " . $participantTable . " AS cvnpd
JOIN civicrm_case_contact AS ccc ON cvnpd.entity_id = ccc.case_id
JOIN civicrm_case AS cas ON ccc.case_id = cas.id
JOIN civicrm_contact AS vol ON ccc.contact_id = vol.id
LEFT JOIN civicrm_email AS ce ON vol.id = ce.contact_id AND ce.is_primary = %1
LEFT JOIN " . $aliasTable . " AS cvnva ON vol.id = cvnva.entity_id
WHERE cvnpd." . $projectColumn . " = %2 AND cas.is_deleted = %3";
LEFT JOIN " . $nviTable . " AS nvi ON vol.id = nvi.entity_id
WHERE cvnpd." . $projectColumn . " = %2 AND cas.is_deleted = %3 AND vol.id IN (";
$queryParams = [
1 => [1, "Integer"],
2 => [(int)$this->_projectId, "Integer"],
......@@ -56,11 +62,26 @@ class CRM_Nbrprojectvolunteerlist_Form_Task_InviteByEmail extends CRM_Contact_Fo
$volunteer = [
'display_name' => $dao->display_name,
'bioresource_id' => $dao->bioresource_id,
'participant_id' => $dao->participant_id,
'study_participant_id' => $dao->study_participant_id,
'eligible_status' => implode(', ', CRM_Nihrbackbone_NbrVolunteerCase::getEligibleDescriptions($dao->eligible_status_id)),
'email' => $dao->email,
];
$this->_invited[$dao->contact_id] = $volunteer;
$eligibleStatus = implode(', ', CRM_Nihrbackbone_NbrVolunteerCase::getEligibleDescriptions($dao->eligible_status_id));
if (!empty($eligibleStatus)) {
$volunteer['eligible_status'] = $eligibleStatus;
}
else {
$volunteer['eligible_status'] = "Eligible";
}
// add if valid email else list as invalid
if (filter_var($dao->email, FILTER_VALIDATE_EMAIL)) {
$this->_countInvited++;
$this->_invited[$dao->contact_id] = $volunteer;
}
else {
$this->_countInvalid++;
$this->_invalids[$dao->contact_id] = $volunteer;
}
}
}
......@@ -74,10 +95,13 @@ class CRM_Nbrprojectvolunteerlist_Form_Task_InviteByEmail extends CRM_Contact_Fo
$this->add('select', 'template_id', E::ts('Message template for email'), $this->getTemplateList(),
TRUE, ['class' => 'crm-select2']);
$this->assign('template_txt', E::ts('Template used for invitation'));
$this->assign('invited_txt', E::ts('Volunteers that will be invited by email:'));
$this->assign('count_invited_txt', E::ts('Number of volunteers that will be invited: ') . $this->_countInvited);
$this->assign('invited_txt', E::ts('Volunteers that will be invited by email:') . $this->_countInvited);
$this->assign('invalid_txt', E::ts('Volunteers that will NOT be invited because their email is invalid:') . $this->_countInvalid);
$this->getInvitedData();
$this->assign('count_invited_txt', E::ts('Number of volunteers that will be invited: ') . $this->_countInvited);
$this->assign('count_invalid_txt', E::ts('Number of volunteers that will NOT be invited: ') . $this->_countInvalid);
$this->assign('invited', $this->_invited);
$this->assign('invalids', $this->_invalids);
$this->addDefaultButtons(ts('Invite by Email'));
}
......@@ -108,8 +132,52 @@ class CRM_Nbrprojectvolunteerlist_Form_Task_InviteByEmail extends CRM_Contact_Fo
* Overridden parent method
*/
public function postProcess() {
$values = $this->exportValues();
// only if we have a project, contactIds and a template
if (isset($this->_projectId) && !empty($this->_contactIds) && !empty($this->_submitValues['template_id'])) {
// first find all relevant cases
$caseIds = $this->getRelevantCaseIds();
// then send email (include case_id so the activity is recorded)
foreach ($caseIds as $caseId => $contactId) {
try {
civicrm_api3('Email', 'send', [
'template_id' => $this->_submitValues['template_id'],
'contact_id' => $contactId,
'case_id' => $caseId,
]);
}
catch (CiviCRM_API3_Exception $ex) {
Civi::log()->warning(E::ts("Could not send invitation to project with ID ") . $this->_projectId
. E::ts(" in ") . __METHOD__ . E::ts(", error from API Email Send: ") . $ex->getMessage());
}
}
}
}
/**
* Method to find the relevant case ids
*
* @return array
*/
private function getRelevantCaseIds() {
$caseIds = [];
$participationTable = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationDataCustomGroup('table_name');
$projectColumn = CRM_Nihrbackbone_BackboneConfig::singleton()->getParticipationCustomField('nvpd_project_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
WHERE cvnpd." . $projectColumn . " = %2 AND ccc.contact_id IN (";
$queryParams = [
1 => [1, "Integer"],
2 => [$this->_projectId, "Integer"],
];
$i = 2;
$elements = CRM_Nbrprojectvolunteerlist_Utils::processContactQueryElements($this->_contactIds, $i, $queryParams);
$query .= implode("," , $elements) . ")";
$dao = CRM_Core_DAO::executeQuery($query, $queryParams);
while ($dao->fetch()) {
$caseIds[$dao->case_id] = $dao->contact_id;
}
return $caseIds;
}
}
......@@ -14,8 +14,8 @@
<url desc="Support">https://civicoop.org</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2019-11-26</releaseDate>
<version>1.1</version>
<releaseDate>2019-11-27</releaseDate>
<version>1.2</version>
<develStage>alpha</develStage>
<compatibility>
<ver>4.7</ver>
......
......@@ -15,6 +15,7 @@
<tr>
<th>{ts}Name{/ts}</th>
<th>{ts}BioResource ID{/ts}</th>
<th>{ts}Participant ID{/ts}</th>
<th>{ts}Study/Participant ID{/ts}</th>
<th>{ts}Eligibility{/ts}</th>
<th>{ts}Current Project Status{/ts}</th>
......@@ -23,9 +24,10 @@
<tr id='contactid{$contact_id}' class="{cycle values="odd-row,even-row"}">
<td>{$volunteer.display_name}</td>
<td>{$volunteer.bioresource_id}</td>
<td>{$volunteer.participant_id}</td>
<td>{$volunteer.study_participant_id}</td>
<td>{$volunteer.eligible_status}</td>
<td>{$volunter.project_status}</td>
<td>{$volunteer.project_status}</td>
</tr>
{/foreach}
</table>
......
......@@ -15,6 +15,7 @@
<tr>
<th>{ts}Name{/ts}</th>
<th>{ts}BioResource ID{/ts}</th>
<th>{ts}Participant ID{/ts}</th>
<th>{ts}Study/Participant ID{/ts}</th>
<th>{ts}Eligibility{/ts}</th>
<th>{ts}Current Study Status{/ts}</th>
......@@ -23,9 +24,10 @@
<tr id='contactid{$contact_id}' class="{cycle values="odd-row,even-row"}">
<td>{$volunteer.display_name}</td>
<td>{$volunteer.bioresource_id}</td>
<td>{$volunteer.participant_id}</td>
<td>{$volunteer.study_participant_id}</td>
<td>{$volunteer.eligible_status}</td>
<td>{$volunter.study_status}</td>
<td>{$volunteer.study_status}</td>
</tr>
{/foreach}
</table>
......
......@@ -15,6 +15,7 @@
<tr>
<th>{ts}Name{/ts}</th>
<th>{ts}BioResource ID{/ts}</th>
<th>{ts}Participant ID{/ts}</th>
<th>{ts}Study/Participant ID{/ts}</th>
<th>{ts}Eligibility{/ts}</th>
<th>{ts}Email{/ts}</th>
......@@ -23,6 +24,7 @@
<tr id='contactid{$contact_id}' class="{cycle values="odd-row,even-row"}">
<td>{$invite.display_name}</td>
<td>{$invite.bioresource_id}</td>
<td>{$invite.participant_id}</td>
<td>{$invite.study_participant_id}</td>
<td>{$invite.eligible_status}</td>
<td>{$invite.email}</td>
......@@ -31,6 +33,30 @@
</table>
{/if}
<p>{$count_invited_txt}</p>
<h3>{$invalid_txt}</h3>
{if !empty($invalids)}
<table>
<tr>
<th>{ts}Name{/ts}</th>
<th>{ts}BioResource ID{/ts}</th>
<th>{ts}Participant ID{/ts}</th>
<th>{ts}Study/Participant ID{/ts}</th>
<th>{ts}Eligibility{/ts}</th>
<th>{ts}Email{/ts}</th>
</tr>
{foreach from=$invalids key=contact_id item=invalid}
<tr id='contactid{$contact_id}' class="{cycle values="odd-row,even-row"}">
<td>{$invalid.display_name}</td>
<td>{$invalid.bioresource_id}</td>
<td>{$invalid.participant_id}</td>
<td>{$invalid.study_participant_id}</td>
<td>{$invalid.eligible_status}</td>
<td>{$invalid.email}</td>
</tr>
{/foreach}
</table>
{/if}
<p>{$count_invalid_txt}</p>
</div>
<p>
<div class="form-item">
......
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