implemented sending coodle voting reminders

This commit is contained in:
adisposkofh
2026-07-10 16:08:01 +02:00
parent c230990f25
commit 74b916d0c5
3 changed files with 83 additions and 4 deletions
@@ -265,7 +265,6 @@ class CoodleSurvey extends FHCAPI_Controller
}
$participants = $this->CoodleSurveyParticipantModel->getParticipants($surveyId);
$this->addMeta("particips", $participants);
$participantUids = array_map(
function ($participant) {
return $participant->uid;
@@ -292,8 +291,6 @@ class CoodleSurvey extends FHCAPI_Controller
);
$selection = array_slice($selection, 0, $survey->max_selections);
$this->addMeta("selection", $selection);
$this->addMeta("timeslotIds", $timeslotIds);
}
$this->CoodleSurveyParticipantModel->updateSelection($surveyId, getAuthUID(), json_encode($selection));
@@ -310,6 +307,8 @@ class CoodleSurvey extends FHCAPI_Controller
$this->terminateWithError("Survey not found!");
} else if ($survey->creator_uid !== getAuthUID()) {
$this->terminateWithError("You are not authorized to modify this survey!");
} else if ($survey->canceled_at) {
$this->terminateWithError("This survey has already been canceled!");
} else if ($survey->completed_at) {
$this->terminateWithError("This survey has already been completed!");
}
@@ -335,6 +334,8 @@ class CoodleSurvey extends FHCAPI_Controller
$this->terminateWithError("You are not authorized to modify this survey!");
} else if ($survey->canceled_at) {
$this->terminateWithError("This survey has already been canceled!");
} else if ($survey->completed_at) {
$this->terminateWithError("This survey has already been completed!");
}
if ($selectedTimeslotId) {
@@ -357,6 +358,35 @@ class CoodleSurvey extends FHCAPI_Controller
}
}
public function sendVotingReminders()
{
$surveyId = $this->input->post("surveyId");
$survey = $this->CoodleSurveyModel->getSurvey($surveyId);
if (!$survey) {
$this->terminateWithError("Survey not found!");
} else if ($survey->creator_uid !== getAuthUID()) {
$this->terminateWithError("You do not own this survey!");
} else if ($survey->canceled_at || $survey->completed_at) {
$this->terminateWithError("This survey is no longer active!");
}
$participants = $this->CoodleSurveyParticipantModel->getParticipants($surveyId);
$participantsWithoutVote = array_filter(
$participants,
function ($participant) {
return $participant->selection === null;
}
);
if (!count($participantsWithoutVote)) {
$this->terminateWithError("All participants have already voted!");
}
// todo: send reminder emails
$this->terminateWithSuccess();
}
// -----------------------------------------------------------------------------------------------------------------
// Private methods
+9
View File
@@ -98,4 +98,13 @@ export default {
},
};
},
sendReminders(surveyId) {
return {
method: "post",
url: "/api/frontend/v1/coodle/CoodleSurvey/sendVotingReminders",
params: {
surveyId,
},
};
}
};
@@ -41,7 +41,7 @@ export default {
this.$props.survey?.title,
);
const cancellationConfirmation = await this.$fhcAlert.confirm({
header: "Cancellation confirmation!",
header: "Cancellation confirmation",
message: cancellationConfirmationMessage,
acceptLabel: "Yes",
rejectLabel: "No",
@@ -66,6 +66,37 @@ export default {
this.$emit("surveyCanceled");
}
},
async sendReminders() {
if (!this.$props.survey?.id) return;
const numberOfParticipantsWithoutVote =
this.$props.survey.participants.filter(
(participant) => participant.selection === null,
).length;
if (!numberOfParticipantsWithoutVote) {
this.$fhcAlert.alertError(
"All participants have already voted!",
);
return;
}
const reminderConfirmation = await this.$fhcAlert.confirm({
header: "Reminder confirmation",
message:
"Are you sure you want to remind participants to vote?",
acceptLabel: "Yes",
rejectLabel: "No",
});
if (!reminderConfirmation) return;
const remindersResponse = this.$api.call(
CoodleApi.sendReminders(this.$props.survey.id),
);
if (remindersResponse.meta.status === "success") {
this.$fhcAlert.alertSuccess("Reminders successfully sent!");
}
},
},
template: /*html*/ `
<div class="d-flex flex-row align-items-center justify-content-between">
@@ -84,6 +115,15 @@ export default {
<i class="fa-solid fa-ellipsis-vertical fa-lg"></i>
</div>
<ul class="dropdown-menu dropdown-menu-end" style="min-width:0;'">
<li>
<div
@click="sendReminders()"
role="button"
class="dropdown-item px-3 py-1"
>
{{ "Send reminders" }}
</div>
</li>
<li>
<div
@click="$emit('editSurvey')"