ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilStudyProgrammeUserAssignment.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2015 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4/* Copyright (c) 2015 Stefan Hecken <stefan.hecken@concepts-and-training.de> Extended GPL, see docs/LICENSE */
5
6declare(strict_types=1);
7
14{
18 protected $assignment;
19
24
29
33 protected $sp_events;
34
35 public function __construct(
40 ) {
41 $this->assignment = $assignment;
42 $this->sp_user_progress_db = $sp_user_progress_db;
43 $this->assignment_repository = $assignment_repository;
44 $this->sp_events = $sp_events;
45 }
46
50 public function getId() : int
51 {
52 return $this->assignment->getId();
53 }
54
63 {
64 $refs = ilObject::_getAllReferences((int) $this->assignment->getRootId());
65 if (!count($refs)) {
66 throw new ilException("ilStudyProgrammeUserAssignment::getStudyProgramme: "
67 . "could not find ref_id for program '"
68 . $this->assignment->getRootId() . "'.");
69 }
70 return ilObjStudyProgramme::getInstanceByRefId((int) array_shift($refs));
71 }
72
77 public function getRestartDate()
78 {
79 return $this->assignment->getRestartDate();
80 }
81
85 public function getRestartedAssignmentId() : int
86 {
87 return $this->assignment->getRestartedAssignmentId();
88 }
89
96 {
97 return $this->getStudyProgramme()->getProgressForAssignment($this->getId());
98 }
99
107 {
108 $restarted = $this->getStudyProgramme()->assignUser($this->getUserId(), $this->getUserId());
109 $this->assignment_repository->update(
110 $this->assignment->setRestartedAssignmentId($restarted->getId())
111 );
112
113 $this->sp_events->userReAssigned($this);
114
115 return $restarted;
116 }
117
118 public function informUserByMailToRestart() : void
119 {
120 $this->sp_events->informUserByMailToRestart($this);
121 }
122
123 public function getUserId() : int
124 {
125 return $this->assignment->getUserId();
126 }
127
133 public function deassign() : void
134 {
135 $this->getStudyProgramme()->removeAssignment($this);
136 }
137
141 public function delete() : void
142 {
143 $progresses = $this->sp_user_progress_db->getInstancesForAssignment($this->getId());
144 foreach ($progresses as $progress) {
145 $progress->delete();
146 }
147 $this->assignment_repository->delete(
148 $this->assignment
149 );
150 }
151
156 public function updateFromProgram() : ilStudyProgrammeUserAssignment
157 {
158 $prg = $this->getStudyProgramme();
159 $id = $this->getId();
160
161 $prg->applyToSubTreeNodes(
162 function (ilObjStudyProgramme $node) use ($id) {
164 $progress = $node->getProgressForAssignment($id);
165 return $progress->updateFromProgramNode();
166 },
167 true
168 );
169
170 return $this;
171 }
172
173 public function updateValidityFromProgram() : void
174 {
175 $prg = $this->getStudyProgramme();
176 $progress = $this->getRootProgress();
177 if (!$progress->hasSuccessStatus()) {
178 return;
179 }
180
181 $validity_settings = $prg->getValidityOfQualificationSettings();
182 $period = $validity_settings->getQualificationPeriod();
183 $date = $validity_settings->getQualificationDate();
184
185 if ($period) {
186 $date = $progress->getCompletionDate();
187 $date->add(new DateInterval('P' . $period . 'D'));
188 }
189 $progress->setValidityOfQualification($date);
190 $progress->storeProgress();
191 }
192
193 public function updateDeadlineFromProgram() : void
194 {
195 $prg = $this->getStudyProgramme();
196 $progress = $this->getRootProgress();
197 if ($progress->hasSuccessStatus()) {
198 return;
199 }
200
201 $deadline_settings = $prg->getDeadlineSettings();
202 $period = $deadline_settings->getDeadlinePeriod();
203 $date = $deadline_settings->getDeadlineDate();
204 if ($period) {
205 $date = $progress->getAssignmentDate();
206 $date->add(new DateInterval('P' . $period . 'D'));
207 }
208 $progress->setDeadline($date);
209 $progress->storeProgress();
210 }
211
213 {
214 return $this->assignment;
215 }
216
220 public static function sendInformToReAssignMail(int $assignment_id, int $usr_id) : void
221 {
222 global $DIC;
223 $lng = $DIC['lng'];
224 $log = $DIC['ilLog'];
225 $lng->loadLanguageModule("prg");
226 $lng->loadLanguageModule("mail");
227
229 $assignment_db = ilStudyProgrammeDIC::dic()['ilStudyProgrammeUserAssignmentDB'];
231 $assignment = $assignment_db->getInstanceById($assignment_id);
233 $prg = $assignment->getStudyProgramme();
234
235 if (!$prg->shouldSendInfoToReAssignMail()) {
236 $log->write("Send info to re assign mail is deactivated in study programme settings");
237 return;
238 }
239
240 $subject = $lng->txt("info_to_re_assign_mail_subject");
241 $gender = ilObjUser::_lookupGender($usr_id);
243 $body = sprintf(
244 $lng->txt("info_to_re_assign_mail_body"),
245 $lng->txt("mail_salutation_" . $gender),
246 $name,
247 $prg->getTitle()
248 );
249
250 $send = true;
251 $mail = new ilMail(ANONYMOUS_USER_ID);
252 try {
253 $mail->enqueue(
255 '',
256 '',
257 $subject,
258 $body,
259 null
260 );
261 } catch (Exception $e) {
262 $send = false;
263 }
264
265 if ($send) {
266 $assignment_db->reminderSendFor($assignment->getId());
267 }
268 }
269}
An exception for terminatinating execution or to throw for unit testing.
Base class for ILIAS Exception handling.
static getInstanceByRefId($a_ref_id)
getProgressForAssignment(int $a_assignment_id)
Get the progress for an assignment on this node.
static _lookupLogin($a_user_id)
lookup login
static _lookupGender($a_user_id)
Lookup gender.
static _lookupFullname($a_user_id)
Lookup Full Name.
static _getAllReferences($a_id)
get all reference ids of object
Class ilStudyProgrammeAssignment.
Represents one assignment of a user to a study programme.
getStudyProgramme()
Get the program node where this assignment was made.
getRootProgress()
Get the progress on the root node of the programme.
restartAssignment()
Assign the user belonging to this assignment to the prg belonging to this assignment again.
getRestartedAssignmentId()
Get restarted assignment id.
__construct(ilStudyProgrammeAssignment $assignment, ilStudyProgrammeUserProgressDB $sp_user_progress_db, ilStudyProgrammeAssignmentRepository $assignment_repository, ilStudyProgrammeEvents $sp_events)
getRestartDate()
Get the possible restart date of this assignment.
Storage implementation for ilStudyProgrammeUserProgress.
Represents the progress of a user at one node of a study programme.
if($format !==null) $name
Definition: metadata.php:230
$log
Definition: result.php:15
$lng
$DIC
Definition: xapitoken.php:46