ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.EvaluationManager.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Survey\Evaluation;
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(
44  InternalDomainService $domain_service,
45  InternalRepoService $repo_service,
46  \ilObjSurvey $survey,
47  int $user_id,
48  int $requested_appr_id,
49  string $requested_rater_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  {
70  $survey = $this->survey;
71  $access = $this->access;
72 
73  switch ($survey->getMode()) {
74  case \ilObjSurvey::MODE_360:
75  return ($access->canEditSettings() ||
76  $survey->get360Results() === \ilObjSurvey::RESULTS_360_ALL);
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() ||
82  $survey->getSelfEvaluationResults() === \ilObjSurvey::RESULTS_SELF_EVAL_ALL);
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  {
99  $survey = $this->survey;
100  $user_id = $this->user_id;
101  $access = $this->access;
102  $feature_config = $this->feature_config;
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() ||
118  $survey->getMode() === \ilObjSurvey::MODE_SELF_EVAL) {
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
138  $user_id = $this->user_id;
139  if ($req_appr_id === 0) {
140  $req_appr_id = $user_id;
141  }
142 
143 
144  // requested appraisee is valid -> return appraisee
145  $valid = $this->getSelectableAppraisees();
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 = [];
165  $survey = $this->survey;
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(bool $fallback_to_first = false): string
182  {
183  $req_rater_id = $this->requested_rater_id;
184 
185  $valid = array_map(static function ($i): string {
186  return (string) $i["user_id"];
187  }, $this->getSelectableRaters());
188  if (in_array($req_rater_id, $valid, true)) {
189  return $req_rater_id;
190  }
191  if ($fallback_to_first && count($this->getSelectableRaters()) > 0) {
192  return $this->getSelectableRaters()[0]["user_id"];
193  }
194  return "";
195  }
196 
197  public function setAnonEvaluationAccess(int $ref_id): void
198  {
199  $this->eval_repo->setAnonEvaluationAccess($ref_id);
200  }
201 
202  public function getAnonEvaluationAccess(): int
203  {
204  return $this->eval_repo->getAnonEvaluationAccess();
205  }
206 
207  public function clearAnonEvaluationAccess(): void
208  {
209  $this->eval_repo->clearAnonEvaluationAccess();
210  }
211 
216  public function getFilteredFinishedIds(): ?array
217  {
218  $appr_id = $this->getCurrentAppraisee();
219  $finished_ids = null;
220 
221  $filter = false;
222  if ($appr_id > 0) {
223  $filter = true;
224  // see #36336
225  if ($this->survey->getMode() === \ilObjSurvey::MODE_SELF_EVAL &&
226  $this->survey->getSelfEvaluationResults() === \ilObjSurvey::RESULTS_SELF_EVAL_ALL) {
227  $filter = false;
228  }
229  // see #36336, #36378
230  if ($this->survey->getMode() !== \ilObjSurvey::MODE_IND_FEEDB &&
231  $this->access->canEditSettings()) {
232  $filter = false;
233  }
234  }
235 
236  if ($filter) {
237  $finished_ids = $this->survey->getFinishedIdsForAppraiseeId($appr_id);
238  if (!count($finished_ids)) {
239  $finished_ids = [];
240  }
241  }
242 
243  // @todo (from SM 2018)
244  // filter finished ids
245  /*
246  $finished_ids2 = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
247  'read_results',
248  'access_results',
249  $this->survey->getRefId(),
250  (array) $finished_ids
251  );*/
252 
253  return $finished_ids;
254  }
255 
256  public function getUserSpecificResults(): array
257  {
258  $data = array();
259 
260  $finished_ids = $this->getFilteredFinishedIds();
261  $participants = $this->access->canReadResultOfParticipants($finished_ids);
262  foreach ($this->survey->getSurveyQuestions() as $qdata) {
263  $q_eval = \SurveyQuestion::_instanciateQuestionEvaluation((int) $qdata["question_id"], $finished_ids);
264  $q_res = $q_eval->getResults();
265 
266  // see #28507 (matrix question without a row)
267  if (is_array($q_res) && !is_object($q_res[0][1])) {
268  continue;
269  }
270 
271  $question = is_array($q_res)
272  ? $q_res[0][1]->getQuestion()
273  : $q_res->getQuestion();
274 
275  foreach ($participants as $user) {
276  $user_id = (int) $user["active_id"];
277 
278  $parsed_results = $q_eval->parseUserSpecificResults($q_res, $user_id);
279 
280  if (!array_key_exists($user_id, $data)) {
281  $wt = $this->survey->getWorkingtimeForParticipant($user_id);
282 
283  $finished = $user["finished"]
284  ? $user["finished_tstamp"]
285  : false;
286 
287  $data[$user_id] = array(
288  "username" => $user["sortname"],
289  "question" => $question->getTitle(),
290  "results" => $parsed_results,
291  "workingtime" => $wt,
292  "finished" => $finished,
293  "subitems" => array()
294  );
295  } else {
296  $data[$user_id]["subitems"][] = array(
297  "username" => " ",
298  "question" => $question->getTitle(),
299  "results" => $parsed_results,
300  "workingtime" => null,
301  "finished" => null
302  );
303  }
304  }
305  }
306 
307  return $data;
308  }
309 }
ILIAS Survey Access AccessManager $access
__construct(InternalDomainService $domain_service, InternalRepoService $repo_service, \ilObjSurvey $survey, int $user_id, int $requested_appr_id, string $requested_rater_id)
Stores access codes of anonymous session.
getCurrentAppraisee()
1) We have a set of selectable appraisees.
$valid
getSelectableAppraisees()
Get all participants the current user may see results from, including itself.
static _lookupId($a_user_str)
getSelectableRaters()
Only the individual feedback mode allows to select raters and only, if the user cannot select apprais...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$ref_id
Definition: ltiauth.php:65
static _instanciateQuestionEvaluation(int $question_id, ?array $a_finished_ids=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS Survey Mode FeatureConfig $feature_config
isMultiParticipantsView()
Can the current user switch between participants and see their results?
const RESULTS_SELF_EVAL_ALL