ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.InvitationsManager.php
Go to the documentation of this file.
1<?php
2
4
5/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
6
9
16{
20 protected $repo;
21
25 protected $run_repo;
26
30 protected $set_repo;
31
35 public function __construct(
37 Execution\RunDBRepository $run_repo = null,
38 Settings\SettingsDBRepository $set_repo = null
39 ) {
40 $this->repo = (is_null($repo))
42 : $repo;
43
44 $this->run_repo = (is_null($run_repo))
45 ? new Execution\RunDBRepository()
46 : $run_repo;
47
48 $this->set_repo = (is_null($set_repo))
49 ? new Settings\SettingsDBRepository()
50 : $set_repo;
51 }
52
53
60 public function remove(int $survey_id, int $user_id)
61 {
62 $this->repo->remove($survey_id, $user_id);
63 }
64
65
72 public function add(int $survey_id, int $user_id)
73 {
74 $this->repo->add($survey_id, $user_id);
75 }
76
83 public function getAllForSurvey(int $survey_id) : array
84 {
85 return $this->repo->getAllForSurvey($survey_id);
86 }
87
94 public function getOpenInvitationsOfUser(int $user_id)
95 {
96 // get all invitations
97 $survey_ids = $this->repo->getAllForUser($user_id);
98
99 // check if user started already
100 $finished_surveys = $this->run_repo->getFinishedSurveysOfUser($user_id);
101
102 $open_surveys = array_filter($survey_ids, function ($i) use ($finished_surveys) {
103 return !in_array($i, $finished_surveys);
104 });
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}
An exception for terminatinating execution or to throw for unit testing.
add(int $survey_id, int $user_id)
Add invitation.
getAllForSurvey(int $survey_id)
Get invitations for survey.
getOpenInvitationsOfUser(int $user_id)
Get all open invitations of a user.
__construct(InvitationsDBRepository $repo=null, Execution\RunDBRepository $run_repo=null, Settings\SettingsDBRepository $set_repo=null)
Constructor.
$i
Definition: metadata.php:24