ILIAS  release_8 Revision v8.24
class.EvaluationManager.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
25
32{
34 protected int $requested_appr_id;
36 protected \ilObjSurvey $survey;
37 protected int $user_id;
38 protected \ILIAS\Survey\Access\AccessManager $access;
39 protected \ILIAS\Survey\Mode\FeatureConfig $feature_config;
41 protected string $requested_rater_id;
42
43 public function __construct(
47 int $user_id,
50 ) {
51 $this->domain_service = $domain_service;
52 $this->repo_service = $repo_service;
53 $this->access = $this->domain_service->access($survey->getRefId(), $user_id);
54 $this->feature_config = $this->domain_service->modeFeatureConfig($survey->getMode());
55 $this->survey = $survey;
56 $this->user_id = $user_id;
57 $this->requested_appr_id = $requested_appr_id;
58 $this->requested_rater_id = $requested_rater_id;
59 $this->eval_repo = $this->repo_service->evaluation();
60 }
61
68 public function isMultiParticipantsView(): bool
69 {
72
73 switch ($survey->getMode()) {
74 case \ilObjSurvey::MODE_360:
75 return ($access->canEditSettings() ||
77 // tutors can switch appraisees on detailed evaluation screen
78 case \ilObjSurvey::MODE_IND_FEEDB:
79 return ($access->canEditSettings());
80 case \ilObjSurvey::MODE_SELF_EVAL:
81 return ($access->canEditSettings() ||
83 }
84 return false;
85
86 /*
87 return ($access->canEditSettings() ||
88 $survey->get360Results() === \ilObjSurvey::RESULTS_360_ALL ||
89 $survey->getSelfEvaluationResults() === \ilObjSurvey::RESULTS_SELF_EVAL_ALL);*/
90 }
91
97 public function getSelectableAppraisees(): array
98 {
103
104 $appraisee_ids = [];
105 if ($this->isMultiParticipantsView()) { // the user may see results of "others"
106 if ($feature_config->usesAppraisees()) {
107 foreach ($survey->getAppraiseesData() as $item) {
108 if (!$survey->get360Mode() || $item["closed"]) {
109 $appraisee_ids[] = (int) $item["user_id"];
110 }
111 }
112 } elseif ($survey->getMode() === \ilObjSurvey::MODE_SELF_EVAL) {
113 foreach ($survey->getSurveyParticipants() as $item) {
114 $appraisee_ids[] = (int) \ilObjUser::_lookupId($item['login']);
115 }
116 }
117 } elseif ($feature_config->usesAppraisees() ||
119 $appraisee_ids[] = $user_id;
120 }
121 return $appraisee_ids;
122 }
123
133 public function getCurrentAppraisee(): int
134 {
135 $req_appr_id = $this->requested_appr_id;
136
137 // if no user is requested, request current user
139 if ($req_appr_id === 0) {
140 $req_appr_id = $user_id;
141 }
142
143
144 // requested appraisee is valid -> return appraisee
146 if (in_array($req_appr_id, $valid)) {
147 return $req_appr_id;
148 }
149
150 // we have at least one selectable appraisee -> return appraisee
151 if (count($valid) > 0) {
152 return current($valid);
153 }
154
155 return 0;
156 }
157
162 public function getSelectableRaters(): array
163 {
164 $raters = [];
166
167 $appr_id = $this->getCurrentAppraisee();
168
169 if ($survey->getMode() === \ilObjSurvey::MODE_IND_FEEDB
170 && !$this->isMultiParticipantsView()) {
171 foreach ($survey->getRatersData($appr_id) as $rater) {
172 if ($rater["finished"]) {
173 $raters[] = $rater;
174 }
175 }
176 }
177
178 return $raters;
179 }
180
181 public function getCurrentRater(): string
182 {
183 $req_rater_id = $this->requested_rater_id;
184
185 $valid = array_map(static function ($i): int {
186 return (int) $i["user_id"];
187 }, $this->getSelectableRaters());
188 if (in_array($req_rater_id, $valid, true)) {
189 return $req_rater_id;
190 }
191 return "";
192 }
193
194 public function setAnonEvaluationAccess(int $ref_id): void
195 {
196 $this->eval_repo->setAnonEvaluationAccess($ref_id);
197 }
198
199 public function getAnonEvaluationAccess(): int
200 {
201 return $this->eval_repo->getAnonEvaluationAccess();
202 }
203
204 public function clearAnonEvaluationAccess(): void
205 {
206 $this->eval_repo->clearAnonEvaluationAccess();
207 }
208
213 public function getFilteredFinishedIds(): ?array
214 {
215 $appr_id = $this->getCurrentAppraisee();
216 $finished_ids = null;
217
218 $filter = false;
219 if ($appr_id > 0) {
220 $filter = true;
221 // see #36336
222 if ($this->survey->getMode() === \ilObjSurvey::MODE_SELF_EVAL &&
223 $this->survey->getSelfEvaluationResults() === \ilObjSurvey::RESULTS_SELF_EVAL_ALL) {
224 $filter = false;
225 }
226 // see #36336, #36378
227 if ($this->survey->getMode() !== \ilObjSurvey::MODE_IND_FEEDB &&
228 $this->access->canEditSettings()) {
229 $filter = false;
230 }
231 }
232
233 if ($filter) {
234 $finished_ids = $this->survey->getFinishedIdsForAppraiseeId($appr_id);
235 if (!count($finished_ids)) {
236 $finished_ids = [];
237 }
238 }
239
240 // @todo (from SM 2018)
241 // filter finished ids
242 /*
243 $finished_ids2 = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
244 'read_results',
245 'access_results',
246 $this->survey->getRefId(),
247 (array) $finished_ids
248 );*/
249
250 return $finished_ids;
251 }
252
253 public function getUserSpecificResults(): array
254 {
255 $data = array();
256
257 $finished_ids = $this->getFilteredFinishedIds();
258 $participants = $this->access->canReadResultOfParticipants($finished_ids);
259 foreach ($this->survey->getSurveyQuestions() as $qdata) {
260 $q_eval = \SurveyQuestion::_instanciateQuestionEvaluation((int) $qdata["question_id"], $finished_ids);
261 $q_res = $q_eval->getResults();
262
263 // see #28507 (matrix question without a row)
264 if (is_array($q_res) && !is_object($q_res[0][1])) {
265 continue;
266 }
267
268 $question = is_array($q_res)
269 ? $q_res[0][1]->getQuestion()
270 : $q_res->getQuestion();
271
272 foreach ($participants as $user) {
273 $user_id = (int) $user["active_id"];
274
275 $parsed_results = $q_eval->parseUserSpecificResults($q_res, $user_id);
276
277 if (!array_key_exists($user_id, $data)) {
278 $wt = $this->survey->getWorkingtimeForParticipant($user_id);
279
280 $finished = $user["finished"]
281 ? $user["finished_tstamp"]
282 : false;
283
284 $data[$user_id] = array(
285 "username" => $user["sortname"],
286 "question" => $question->getTitle(),
287 "results" => $parsed_results,
288 "workingtime" => $wt,
289 "finished" => $finished,
290 "subitems" => array()
291 );
292 } else {
293 $data[$user_id]["subitems"][] = array(
294 "username" => " ",
295 "question" => $question->getTitle(),
296 "results" => $parsed_results,
297 "workingtime" => null,
298 "finished" => null
299 );
300 }
301 }
302 }
303
304 return $data;
305 }
306}
getSelectableRaters()
Only the individual feedback mode allows to select raters and only, if the user cannot select apprais...
ILIAS Survey Mode FeatureConfig $feature_config
__construct(InternalDomainService $domain_service, InternalRepoService $repo_service, \ilObjSurvey $survey, int $user_id, int $requested_appr_id, string $requested_rater_id)
getSelectableAppraisees()
Get all participants the current user may see results from, including itself.
getCurrentAppraisee()
1) We have a set of selectable appraisees.
ILIAS Survey Access AccessManager $access
isMultiParticipantsView()
Can the current user switch between participants and see their results?
Stores access codes of anonymous session.
static _instanciateQuestionEvaluation(int $question_id, array $a_finished_ids=null)
const RESULTS_SELF_EVAL_ALL
getSurveyParticipants(?array $finished_ids=null, bool $force_non_anonymous=false, bool $include_invites=false)
getRatersData(int $a_appraisee_id)
static _lookupId($a_user_str)
$valid
$ref_id
Definition: ltiauth.php:67
$i
Definition: metadata.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...