ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.EvaluationManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
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 // if no user is requested, request current user
138 if ($req_appr_id === 0) {
139 $req_appr_id = $user_id;
140 }
141
142
143 // requested appraisee is valid -> return appraisee
145 if (in_array($req_appr_id, $valid)) {
146 return $req_appr_id;
147 }
148
149 // we have at least one selectable appraisee -> return appraisee
150 if (count($valid) > 0) {
151 return current($valid);
152 }
153
154 return 0;
155 }
156
161 public function getSelectableRaters(): array
162 {
163 $raters = [];
165
166 $appr_id = $this->getCurrentAppraisee();
167
168 if ($survey->getMode() === \ilObjSurvey::MODE_IND_FEEDB
169 && !$this->isMultiParticipantsView()) {
170 foreach ($survey->getRatersData($appr_id) as $rater) {
171 if ($rater["finished"]) {
172 $raters[] = $rater;
173 }
174 }
175 }
176
177 return $raters;
178 }
179
180 public function getCurrentRater(bool $fallback_to_first = false): string
181 {
182 $req_rater_id = $this->requested_rater_id;
183
184 $valid = array_map(static function ($i): string {
185 return (string) $i["user_id"];
186 }, $this->getSelectableRaters());
187 if (in_array($req_rater_id, $valid, true)) {
188 return $req_rater_id;
189 }
190 if ($fallback_to_first && count($this->getSelectableRaters()) > 0) {
191 return $this->getSelectableRaters()[0]["user_id"];
192 }
193 return "";
194 }
195
196 public function setAnonEvaluationAccess(int $ref_id): void
197 {
198 $this->eval_repo->setAnonEvaluationAccess($ref_id);
199 }
200
201 public function getAnonEvaluationAccess(): int
202 {
203 return $this->eval_repo->getAnonEvaluationAccess();
204 }
205
206 public function clearAnonEvaluationAccess(): void
207 {
208 $this->eval_repo->clearAnonEvaluationAccess();
209 }
210
215 public function getFilteredFinishedIds(): ?array
216 {
217 $appr_id = $this->getCurrentAppraisee();
218 $finished_ids = null;
219 $filter = false;
220 if ($appr_id > 0) {
221 $filter = true;
222 // see #36336
223 if ($this->survey->getMode() === \ilObjSurvey::MODE_SELF_EVAL &&
224 $this->survey->getSelfEvaluationResults() === \ilObjSurvey::RESULTS_SELF_EVAL_ALL) {
225 $filter = false;
226 }
227 // see #36336, #36378
228 if ($this->survey->getMode() !== \ilObjSurvey::MODE_IND_FEEDB &&
229 $this->access->canEditSettings()) {
230 if ($appr_id === 0) { // #44755
231 $filter = false;
232 }
233 }
234 }
235 if ($filter) {
236 $finished_ids = $this->survey->getFinishedIdsForAppraiseeId($appr_id);
237 if (!count($finished_ids)) {
238 $finished_ids = [];
239 }
240 }
241
242 // @todo (from SM 2018)
243 // filter finished ids
244 /*
245 $finished_ids2 = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
246 'read_results',
247 'access_results',
248 $this->survey->getRefId(),
249 (array) $finished_ids
250 );*/
251
252 return $finished_ids;
253 }
254
255 public function getUserSpecificResults(): array
256 {
257 $data = array();
258
259 $finished_ids = $this->getFilteredFinishedIds();
260 $participants = $this->access->canReadResultOfParticipants($finished_ids);
261 foreach ($this->survey->getSurveyQuestions() as $qdata) {
262 $q_eval = \SurveyQuestion::_instanciateQuestionEvaluation((int) $qdata["question_id"], $finished_ids);
263 $q_res = $q_eval->getResults();
264
265 // see #28507 (matrix question without a row)
266 if (is_array($q_res) && !is_object($q_res[0][1])) {
267 continue;
268 }
269
270 $question = is_array($q_res)
271 ? $q_res[0][1]->getQuestion()
272 : $q_res->getQuestion();
273
274 foreach ($participants as $user) {
275 $user_id = (int) $user["active_id"];
276
277 $parsed_results = $q_eval->parseUserSpecificResults($q_res, $user_id);
278
279 if (!array_key_exists($user_id, $data)) {
280 $wt = $this->survey->getWorkingtimeForParticipant($user_id);
281
282 $finished = $user["finished"]
283 ? $user["finished_tstamp"]
284 : false;
285
286 $data[$user_id] = array(
287 "username" => $user["sortname"],
288 "question" => $question->getTitle(),
289 "results" => $parsed_results,
290 "workingtime" => $wt,
291 "finished" => $finished,
292 "subitems" => array()
293 );
294 } else {
295 $data[$user_id]["subitems"][] = array(
296 "username" => " ",
297 "question" => $question->getTitle(),
298 "results" => $parsed_results,
299 "workingtime" => null,
300 "finished" => null
301 );
302 }
303 }
304 }
305
306 return $data;
307 }
308}
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(string|array $a_user_str)
$valid
$ref_id
Definition: ltiauth.php:66
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...