ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
Survey360Manager.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 namespace ILIAS\Survey\Survey360;
6 
9 
16 {
20  protected $run_repo;
21 
25  protected $appr_repo;
26 
30  protected $set_repo;
31 
35  public function __construct(
37  RunDBRepository $run_rep = null,
39  ) {
40  $this->run_repo = (is_null($run_rep))
41  ? new RunDBRepository()
42  : $run_rep;
43 
44  $this->appr_repo = (is_null($appr_repo))
45  ? new AppraiseeDBRepository()
46  : $appr_repo;
47 
48  $this->set_repo = (is_null($set_repo))
49  ? new SettingsDBRepository()
50  : $set_repo;
51  }
52 
59  public function getOpenSurveysForRater(int $rater_user_id)
60  {
61  // get all appraisees of the ratier
62  $appraisees = $this->appr_repo->getAppraiseesForRater($rater_user_id);
63 
64  // filter out finished appraisees
65  $finished_ids = array_map(function ($i) {
66  return $i["survey_id"] . ":" . $i["appr_id"];
67  }, $this->run_repo->getFinishedAppraiseesForRater($rater_user_id));
68  $open_appraisees = array_filter($appraisees, function ($i) use ($finished_ids) {
69  return !in_array($i["survey_id"] . ":" . $i["appr_id"], $finished_ids);
70  });
71 
72  // filter out closed appraisees
73  $open_surveys = array_unique(array_column($open_appraisees, "survey_id"));
74 
75  // remove closed appraisees
76  $closed_appr = $this->appr_repo->getClosedAppraiseesForSurveys($open_surveys);
77  $closed_appr_ids = array_map(function ($i) {
78  return $i["survey_id"] . ":" . $i["appr_id"];
79  }, $closed_appr);
80 
81  $open_appraisees = array_filter($open_appraisees, function ($i) use ($closed_appr_ids) {
82  return !in_array($i["survey_id"] . ":" . $i["appr_id"], $closed_appr_ids);
83  });
84  $open_surveys = array_unique(array_column($open_appraisees, "survey_id"));
85 
86  // filter all surveys that have ended
87  $has_ended = $this->set_repo->hasEnded($open_surveys);
88  $open_surveys = array_filter($open_surveys, function ($i) use ($has_ended) {
89  return !$has_ended[$i];
90  });
91 
92  return $open_surveys;
93  }
94 
101  public function getOpenSurveysForAppraisee(int $appr_user_id)
102  {
103  // open surveys
104  $open_surveys = $this->appr_repo->getUnclosedSurveysForAppraisee($appr_user_id);
105 
106  // filter all surveys that have ended
107  $has_ended = $this->set_repo->hasEnded($open_surveys);
108  $open_surveys = array_filter($open_surveys, function ($i) use ($has_ended) {
109  return !$has_ended[$i];
110  });
111 
112  return $open_surveys;
113  }
114 }
Apraisee / Rater DB repository Tables: svy_360_rater, svy_360_appr.
getOpenSurveysForAppraisee(int $appr_user_id)
Get open surveys for rater.
getOpenSurveysForRater(int $rater_user_id)
Get open surveys for rater.
__construct(AppraiseeDBRepository $appr_repo=null, RunDBRepository $run_rep=null, SettingsDBRepository $set_repo=null)
Constructor.
$i
Definition: metadata.php:24