ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilPrgRestartAssignmentsCronJob.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2019 Denis Klöpfer <denis.kloepfer@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4/* Copyright (c) 2019 Stefan Hecken <stefan.hecken@concepts-and-training.de> Extended GPL, see docs/LICENSE */
5
6declare(strict_types=1);
7
13{
14 const ID = 'prg_restart_assignments_temporal_progress';
15 const ACTING_USR_ID = -1;
16
21
25 protected $log;
26
30 protected $lng;
31
32 public function __construct()
33 {
34 global $DIC;
35 $this->log = $DIC['ilLog'];
36 $this->lng = $DIC['lng'];
37 $this->lng->loadLanguageModule('prg');
38
39 $this->dic = ilStudyProgrammeDIC::dic();
40 }
41
42
48 public function getTitle()
49 {
50 return $this->lng->txt('prg_restart_assignments_temporal_progress_title');
51 }
52
58 public function getDescription()
59 {
60 return $this->lng->txt('prg_restart_assignments_temporal_progress_desc');
61 }
67 public function getId()
68 {
69 return self::ID;
70 }
71
77 public function hasAutoActivation()
78 {
79 return true;
80 }
81
87 public function hasFlexibleSchedule()
88 {
89 return true;
90 }
91
97 public function getDefaultScheduleType()
98 {
100 }
101
107 public function getDefaultScheduleValue()
108 {
109 return 1;
110 }
111
115 public function run()
116 {
117 $result = new ilCronJobResult();
119
120 $programmes_to_reassign = $this->getSettingsRepository()
121 ->getProgrammeIdsWithReassignmentForExpiringValidity();
122
123 if (count($programmes_to_reassign) == 0) {
124 return $result;
125 }
126
127 $today = $this->getNow();
128 $programmes_and_due = [];
129
130 foreach ($programmes_to_reassign as $programme_obj_id => $days_offset) {
131 $interval = new DateInterval('P' . $days_offset . 'D');
132 $due = $today->add($interval);
133 $programmes_and_due[$programme_obj_id] = $due;
134 }
135
136 //TODO: expire for assignment, not progress!!!
137 $progresses = $this->getProgressRepository()
138 ->getAboutToExpire($programmes_and_due, false);
139
140 if (count($progresses) == 0) {
141 return $result;
142 }
143
144 $events = $this->getEvents();
145 $assignment_repo = $this->getAssignmentRepository();
146 foreach ($progresses as $progress) {
147 $ass = $assignment_repo->get($progress->getAssignmentId());
148 if ($ass->getRestartedAssignmentId() < 0) {
149 if ($ass->getRootId() != $progress->getNodeId()) {
150 $this->log(
151 sprintf(
152 'PRG, RestartAssignments: progress %s is not root of assignment %s. skipping.',
153 $progress->getId(),
154 $ass->getId()
155 )
156 );
157 continue;
158 }
159
160 $this->log(
161 sprintf(
162 'PRG, RestartAssignments: user %s\'s assignment %s is being restarted (Programme %s)',
163 $progress->getUserId(),
164 $ass->getId(),
165 $progress->getNodeId()
166 )
167 );
168
169 $prg = ilObjStudyProgramme::getInstanceByObjId($ass->getRootId());
170 $restarted = $prg->assignUser($ass->getUserId(), self::ACTING_USR_ID);
171 $ass = $ass->withRestarted($restarted->getId(), $today);
172
173 $assignment_repo->update($ass);
174
175 $events->userReAssigned($restarted);
177 }
178 }
179
180 return $result;
181 }
182
183 protected function getNow() : \DateTimeImmutable
184 {
185 return new DateTimeImmutable();
186 }
187
189 {
190 return $this->dic['model.Settings.ilStudyProgrammeSettingsRepository'];
191 }
192
194 {
195 return $this->dic['ilStudyProgrammeUserProgressDB'];
196 }
197
199 {
200 return $this->dic['ilStudyProgrammeUserAssignmentDB'];
201 }
202
203 protected function getEvents()
204 {
205 return $this->dic['ilStudyProgrammeEvents'];
206 }
207
208 protected function log(string $msg) : void
209 {
210 $this->log->write($msg);
211 }
212}
$result
An exception for terminatinating execution or to throw for unit testing.
Cron job result data container.
Cron job application base class.
const SCHEDULE_TYPE_IN_DAYS
Re-assign users (according to restart-date).
hasAutoActivation()
Is to be activated on "installation".
hasFlexibleSchedule()
Can the schedule be configured?
global $DIC
Definition: goto.php:24