mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-10-12 15:04:04 +00:00
implemented api endpoint to search coodle survey participants
This commit is contained in:
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2024 fhcomplete.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Coodle extends FHCAPI_Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Object initialization
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct([
|
||||
'searchParticipants' => self::PERM_LOGGED,
|
||||
]);
|
||||
|
||||
$this->load->library('PermissionLib');
|
||||
|
||||
$this->load->model('person/Benutzer_model', 'BenutzerModel');
|
||||
|
||||
// todo: remove unnecessary crap
|
||||
$this->load->model('ressource/mitarbeiter_model', 'MitarbeiterModel');
|
||||
$this->load->model('person/Person_model', 'PersonModel');
|
||||
|
||||
|
||||
//? put the uid and pid inside the controller for reusability
|
||||
$this->uid = getAuthUID();
|
||||
$this->pid = getAuthPersonID();
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Public methods
|
||||
|
||||
public function searchParticipants()
|
||||
{
|
||||
$searchString = $this->input->post("searchString");
|
||||
|
||||
if (!$searchString || !strlen($searchString))
|
||||
$this->terminateWithError("Empty search input!");
|
||||
|
||||
$users = $this->searchUsersAsParticipants($searchString);
|
||||
$groups = $this->searchGroupsAsParticipants($searchString);
|
||||
|
||||
$potentialParticipants = array_merge($users, $groups);
|
||||
|
||||
$this->terminateWithSuccess($potentialParticipants);
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Private methods
|
||||
|
||||
private function searchUsersAsParticipants($searchString)
|
||||
{
|
||||
$searchStrings = explode(" ", strtolower($searchString));
|
||||
|
||||
$firstSearchString = $searchStrings[0];
|
||||
$remainingSearchStrings = array_slice($searchStrings, 1);
|
||||
|
||||
$query = "
|
||||
SELECT
|
||||
'user' AS type,
|
||||
benutzer.uid AS uid,
|
||||
person.vorname || ' ' || person.nachname AS name
|
||||
FROM public.tbl_person person
|
||||
JOIN public.tbl_benutzer benutzer ON(benutzer.person_id = person.person_id)
|
||||
WHERE LOWER(person.vorname || ' ' || person.nachname) LIKE '%" . $firstSearchString . "%'
|
||||
";
|
||||
|
||||
if (count($remainingSearchStrings)) {
|
||||
foreach ($remainingSearchStrings as $remainingSearchString) {
|
||||
$query .= " AND LOWER(person.vorname || ' ' || person.nachname) LIKE '%" . $remainingSearchString . "%'";
|
||||
}
|
||||
}
|
||||
|
||||
$query .= " LIMIT 25";
|
||||
|
||||
$dbModel = new DB_Model();
|
||||
$usersQueryResult = $dbModel->execReadOnlyQuery($query);
|
||||
|
||||
if (hasData($usersQueryResult)) {
|
||||
return getData($usersQueryResult);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function searchGroupsAsParticipants($searchString)
|
||||
{
|
||||
$searchStrings = explode(" ", strtolower($searchString));
|
||||
|
||||
$firstSearchString = $searchStrings[0];
|
||||
$remainingSearchStrings = array_slice($searchStrings, 1);
|
||||
|
||||
$groupsQuery = "
|
||||
SELECT
|
||||
'group' AS type,
|
||||
gruppe_kurzbz AS name
|
||||
FROM public.tbl_gruppe
|
||||
WHERE LOWER(gruppe_kurzbz) LIKE '%" . $firstSearchString . "%'
|
||||
";
|
||||
|
||||
if (count($remainingSearchStrings)) {
|
||||
foreach ($remainingSearchStrings as $remainingSearchString) {
|
||||
$groupsQuery .= " AND LOWER(gruppe_kurzbz) LIKE '%" . $remainingSearchString . "%'";
|
||||
}
|
||||
}
|
||||
|
||||
$groupsQuery .= " LIMIT 25";
|
||||
|
||||
$dbModel = new DB_Model();
|
||||
$groupsQueryResult = $dbModel->execReadOnlyQuery($groupsQuery);
|
||||
// return getData($groupsQueryResult);
|
||||
|
||||
$groups = hasData($groupsQueryResult) ? getData($groupsQueryResult) : [];
|
||||
if (!count($groups))
|
||||
return $groups;
|
||||
|
||||
$groupNames = array_map(function ($group) {
|
||||
return $group->name;
|
||||
}, $groups);
|
||||
|
||||
|
||||
$userGroupsQuery = "
|
||||
SELECT
|
||||
benutzerGruppe.uid as uid,
|
||||
benutzerGruppe.gruppe_kurzbz as group,
|
||||
person.vorname || ' ' || person.nachname AS name
|
||||
FROM public.tbl_benutzergruppe benutzerGruppe
|
||||
JOIN public.tbl_benutzer benutzer ON(benutzer.uid = benutzerGruppe.uid)
|
||||
JOIN public.tbl_person person ON(person.person_id = benutzer.person_id)
|
||||
WHERE gruppe_kurzbz IN ('" . implode("', '", $groupNames) . "')
|
||||
";
|
||||
$userGroupsQueryResult = $dbModel->execReadOnlyQuery($userGroupsQuery);
|
||||
|
||||
$users = hasData($userGroupsQueryResult) ? getData($userGroupsQueryResult) : [];
|
||||
if (!count($users))
|
||||
return [];
|
||||
|
||||
$groupedUsers = [];
|
||||
|
||||
foreach ($users as $user) {
|
||||
$userData = [
|
||||
"uid" => $user->uid,
|
||||
"name" => $user->name,
|
||||
];
|
||||
|
||||
$group = $user->group;
|
||||
|
||||
if (isset($groupedUsers[$group])) {
|
||||
$groupedUsers[$group][] = $userData;
|
||||
} else {
|
||||
$groupedUsers[$group] = [$userData];
|
||||
}
|
||||
}
|
||||
|
||||
$groups = array_map(function ($group) use ($groupedUsers) {
|
||||
$group->users = isset($groupedUsers[$group->name]) ? $groupedUsers[$group->name] : [];
|
||||
return $group;
|
||||
}, $groups);
|
||||
$groups = array_filter($groups, function ($group) {
|
||||
return count($group->users);
|
||||
});
|
||||
return $groups;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Copyright (C) 2025 fhcomplete.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
export default {
|
||||
searchParticipants(searchString) {
|
||||
return {
|
||||
method: "post",
|
||||
url: `/api/frontend/v1/coodle/Coodle/searchParticipants`,
|
||||
params: {
|
||||
searchString,
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -21,6 +21,7 @@ export default {
|
||||
survey: { type: Object | null },
|
||||
uid: { type: String | null },
|
||||
},
|
||||
emits: ["surveyCreationCanceled"],
|
||||
data() {
|
||||
return {
|
||||
surveyFormData: null,
|
||||
@@ -79,7 +80,7 @@ export default {
|
||||
survey: {
|
||||
async handler() {
|
||||
this.setSurveyFormData();
|
||||
if (!this.survey?.id) {
|
||||
if (!this.$props.survey?.id) {
|
||||
this.isEditInProgress = true;
|
||||
}
|
||||
},
|
||||
@@ -119,11 +120,9 @@ export default {
|
||||
};
|
||||
}
|
||||
|
||||
this.surveyFormData.participants.forEach(
|
||||
(participant) => {
|
||||
participant.isCalendarShown = false;
|
||||
},
|
||||
);
|
||||
this.surveyFormData.participants.forEach((participant) => {
|
||||
participant.isCalendarShown = false;
|
||||
});
|
||||
},
|
||||
parseTimeslot(timeslot) {
|
||||
const timeslotStartsAt = new Date(timeslot.startsAt + " UTC");
|
||||
@@ -154,9 +153,18 @@ export default {
|
||||
console.log("submitting...");
|
||||
// todo
|
||||
},
|
||||
cancelEditForm() {
|
||||
this.isEditInProgress = false;
|
||||
if (!this.$props.survey?.id) {
|
||||
this.$emit("surveyCreationCanceled");
|
||||
}
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.setSurveyFormData();
|
||||
if (!this.$props.survey?.id) {
|
||||
this.isEditInProgress = true;
|
||||
}
|
||||
// todo: localize weekdays and months
|
||||
},
|
||||
template: /*html*/ `
|
||||
@@ -171,8 +179,13 @@ export default {
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="d-flex flex-column gap-3">
|
||||
<span
|
||||
v-if="isEditInProgress"
|
||||
class="fst-italic"
|
||||
>
|
||||
{{ "Required inputs are marked with *." }}
|
||||
</span>
|
||||
<coodle-survey-basic-info
|
||||
v-if="$props.survey"
|
||||
v-model:surveyFormDataModelValue="surveyFormData"
|
||||
:survey="$props.survey"
|
||||
:parsedSelectedTimeslot="parsedSelectedTimeslot"
|
||||
@@ -189,13 +202,13 @@ export default {
|
||||
</div>
|
||||
<div v-else class="d-flex flex-column gap-3">
|
||||
<div class="row">
|
||||
<div class="col-12 col-lg-4">
|
||||
<div class="col-12 col-xl-4">
|
||||
<coodle-survey-participants
|
||||
v-if="surveyFormData?.participants"
|
||||
v-model:participantsModelValue="surveyFormData.participants"
|
||||
/>
|
||||
</div>
|
||||
<div class="col-12 col-lg-8">
|
||||
<div class="col-12 col-xl-8">
|
||||
<div class="d-flex flex-column gap-3">
|
||||
<coodle-survey-duration-selector
|
||||
v-if="surveyFormData?.timeslotDuration"
|
||||
@@ -209,7 +222,7 @@ export default {
|
||||
<div class="d-flex flex-row gap-2 justify-content-end align-items-start px-0">
|
||||
<div>
|
||||
<div
|
||||
@click="isEditInProgress = false"
|
||||
@click="cancelEditForm()"
|
||||
:class="isDarkMode ? 'btn-outline-light' : 'btn-outline-dark'"
|
||||
class="btn text-nowrap"
|
||||
>
|
||||
|
||||
@@ -14,6 +14,10 @@ export default {
|
||||
return this.$props.survey?.description?.replaceAll("\n", "<br>");
|
||||
},
|
||||
formattedSurveyTimeslotDuration() {
|
||||
if (this.isNewSurvey) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const minutes = this.$props.survey.timeslotDuration % 60;
|
||||
const hours = (this.$props.survey.timeslotDuration - minutes) / 60;
|
||||
let formattedDuration = hours ? hours + " hr " : "";
|
||||
@@ -56,11 +60,18 @@ export default {
|
||||
}
|
||||
},
|
||||
surveyCreatorProfileHref() {
|
||||
if (this.isNewSurvey) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return this.$router.resolve({
|
||||
name: "ProfilView",
|
||||
params: { uid: this.survey?.creator?.uid },
|
||||
}).href;
|
||||
},
|
||||
isNewSurvey() {
|
||||
return !this.$props.survey?.id;
|
||||
},
|
||||
surveyFormData: {
|
||||
get() {
|
||||
return this.$props.surveyFormDataModelValue;
|
||||
@@ -124,7 +135,7 @@ export default {
|
||||
</div>
|
||||
<span>
|
||||
<span class="fw-bold">{{ "Maximum selectable timeslots: " }}</span>
|
||||
{{ $props.survey.maxSelections}}
|
||||
{{ $props.survey?.maxSelections}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="d-flex flex-row">
|
||||
@@ -133,22 +144,21 @@ export default {
|
||||
</div>
|
||||
<span>
|
||||
<span class="fw-bold">{{ "Are participants anonymized: " }}</span>
|
||||
{{ $props.survey.areParticipantsAnonymized ? "yes" : "no" }}
|
||||
{{ $props.survey?.areParticipantsAnonymized ? "yes" : "no" }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="d-flex flex-row">
|
||||
<div class="d-flex flex-row justify-content-center align-items-center" style="width: 30px;">
|
||||
<i class="fa-solid fa-person-booth fa-lg"></i>
|
||||
<i class="fa-solid fa-eye-slash fa-lg"></i>
|
||||
</div>
|
||||
<span>
|
||||
<span class="fw-bold">{{ "Are votes anonymized: " }}</span>
|
||||
{{ $props.survey.areSelectionsAnonymized ? "yes" : "no" }}
|
||||
{{ $props.survey?.areSelectionsAnonymized ? "yes" : "no" }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="fst-italic">{{ "Required inputs are marked with *." }}</span>
|
||||
<div class="row">
|
||||
<div class="d-flex flex-column gap-2 col-12 col-md-6 pb-2">
|
||||
<div class="d-flex flex-column gap-1">
|
||||
|
||||
+25
-19
@@ -1,3 +1,5 @@
|
||||
import CoodleApi from "../../../../../api/factory/coodle.js";
|
||||
|
||||
export default {
|
||||
name: "CoodleSurveyParticipants",
|
||||
components: {},
|
||||
@@ -12,7 +14,7 @@ export default {
|
||||
searchResults: [],
|
||||
areSearchResultsShown: false,
|
||||
// todo: increase depending on feedback
|
||||
warningGroupSize: 5,
|
||||
warningGroupSize: 10,
|
||||
// todo: remove
|
||||
searchResultsDevExample: [
|
||||
{
|
||||
@@ -36,7 +38,6 @@ export default {
|
||||
type: "user",
|
||||
},
|
||||
{
|
||||
uid: "ABC-DEF",
|
||||
name: "ABC-DEF",
|
||||
type: "group",
|
||||
users: [
|
||||
@@ -51,7 +52,6 @@ export default {
|
||||
],
|
||||
},
|
||||
{
|
||||
uid: "GHI-JKL",
|
||||
name: "GHI-JKL",
|
||||
type: "group",
|
||||
users: [
|
||||
@@ -131,18 +131,22 @@ export default {
|
||||
this.areSearchResultsShown = false;
|
||||
}, 100);
|
||||
},
|
||||
searchParticipants() {
|
||||
async searchParticipants() {
|
||||
if (this.searchInput.length < 2) return;
|
||||
|
||||
this.isSearchingForParticipants = true;
|
||||
|
||||
// todo
|
||||
this.searchResults = this.searchResultsDevExample;
|
||||
// todo: delete comment
|
||||
// this.searchResults = this.searchResultsDevExample;
|
||||
const participantsSearchResponse = await this.$api.call(CoodleApi.searchParticipants(this.searchInput));
|
||||
this.searchResults = participantsSearchResponse.data;
|
||||
|
||||
this.isSearchingForParticipants = false;
|
||||
},
|
||||
selectSearchResult(searchResult) {
|
||||
if (
|
||||
searchResult.type === "group" &&
|
||||
searchResult.users.length > this.warningGroupSize
|
||||
searchResult.users.length >= this.warningGroupSize
|
||||
) {
|
||||
let warningMessage =
|
||||
"Group (((groupName))) contains (((n))) users. Are you sure you want to add all (((n))) users to your survey?";
|
||||
@@ -166,18 +170,20 @@ export default {
|
||||
this.addParticipants(addedParticipants);
|
||||
},
|
||||
addParticipants(newParticipants) {
|
||||
newParticipants = newParticipants.filter((newParticipant) => {
|
||||
return !this.participants.some(
|
||||
(existingParticipant) =>
|
||||
existingParticipant.uid === newParticipant.uid,
|
||||
);
|
||||
}).map((newParticipant) => {
|
||||
return {
|
||||
uid: newParticipant.uid,
|
||||
name: newParticipant.name,
|
||||
isCalendarShown: false,
|
||||
}
|
||||
});
|
||||
newParticipants = newParticipants
|
||||
.filter((newParticipant) => {
|
||||
return !this.participants.some(
|
||||
(existingParticipant) =>
|
||||
existingParticipant.uid === newParticipant.uid,
|
||||
);
|
||||
})
|
||||
.map((newParticipant) => {
|
||||
return {
|
||||
uid: newParticipant.uid,
|
||||
name: newParticipant.name,
|
||||
isCalendarShown: false,
|
||||
};
|
||||
});
|
||||
|
||||
this.participants = this.participants.concat(newParticipants);
|
||||
},
|
||||
|
||||
@@ -11,7 +11,7 @@ export default {
|
||||
uid: null,
|
||||
view: "survey",
|
||||
// survey: null,
|
||||
// todo: delete comment after dev
|
||||
// todo: delete example survey after dev
|
||||
survey: {
|
||||
id: 1,
|
||||
creator: {
|
||||
@@ -72,7 +72,7 @@ export default {
|
||||
{
|
||||
uid: "ma1437",
|
||||
name: "Test Userrrrr 3",
|
||||
selection: [2,3],
|
||||
selection: [2, 3],
|
||||
},
|
||||
],
|
||||
sums: {
|
||||
@@ -81,7 +81,7 @@ export default {
|
||||
3: 1,
|
||||
4: 0,
|
||||
5: 0,
|
||||
"none": 1,
|
||||
none: 1,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -147,7 +147,12 @@ export default {
|
||||
<div class="flex-grow-1 mt-1">
|
||||
<span v-if="view === 'activeSurveysTable'">active surveys table placeholder</span>
|
||||
<span v-else-if="view === 'pastSurveysTable'">past surveys table placeholder</span>
|
||||
<coodle-survey v-else-if="view === 'survey'" :survey="survey" :uid="uid" />
|
||||
<coodle-survey
|
||||
v-else-if="view === 'survey'"
|
||||
@surveyCreationCanceled="switchToTab('activeSurveysTable')"
|
||||
:survey="survey"
|
||||
:uid="uid"
|
||||
/>
|
||||
</div>
|
||||
</div>`,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user