ILIAS  release_8 Revision v8.24
class.ilPrgRestartAssignmentsCronJob.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21use Pimple\Container;
22
28{
29 private const ID = 'prg_restart_assignments_temporal_progress';
30 private const ACTING_USR_ID = -1;
31
33 protected ilLanguage $lng;
36
37 protected array $prgs = [];
38
39 public function __construct()
40 {
41 global $DIC;
42 $this->log = $DIC['ilLog'];
43 $this->lng = $DIC['lng'];
44 $this->lng->loadLanguageModule('prg');
45
47 $this->assignment_repo = $dic['repo.assignment'];
48 $this->adapter = $dic['cron.restart'];
49 }
50
51 public function getTitle(): string
52 {
53 return $this->lng->txt('prg_restart_assignments_temporal_progress_title');
54 }
55
56 public function getDescription(): string
57 {
58 return $this->lng->txt('prg_restart_assignments_temporal_progress_desc');
59 }
60
61 public function getId(): string
62 {
63 return self::ID;
64 }
65
66 public function hasAutoActivation(): bool
67 {
68 return true;
69 }
70
71 public function hasFlexibleSchedule(): bool
72 {
73 return true;
74 }
75
76 public function getDefaultScheduleType(): int
77 {
79 }
80
81 public function getDefaultScheduleValue(): ?int
82 {
83 return 1;
84 }
85
86 public function run(): ilCronJobResult
87 {
88 $result = new ilCronJobResult();
89 $result->setStatus(ilCronJobResult::STATUS_NO_ACTION);
90
91 $programmes_to_reassign = $this->adapter->getRelevantProgrammeIds();
92 if (count($programmes_to_reassign) === 0) {
93 return $result;
94 }
95
96 $today = $this->getNow();
97 $programmes_and_due = [];
98
99 foreach ($programmes_to_reassign as $programme_obj_id => $days_offset) {
100 $interval = new DateInterval('P' . $days_offset . 'D');
101 $due = $today->add($interval);
102 $programmes_and_due[$programme_obj_id] = $due;
103 }
104
105 $assignments = $this->assignment_repo->getAboutToExpire($programmes_and_due, false);
106
107 if (count($assignments) === 0) {
108 return $result;
109 }
110
111 foreach ($assignments as $ass) {
112 if ($ass->getRestartedAssignmentId() < 0) {
113 $prg = $this->getStudyProgramme($ass->getRootId());
114
115 $restart_settings = $prg->getSettings()->getValidityOfQualificationSettings();
116 if ($restart_settings->getRestartRecheck()
117 && !$ass->isManuallyAssigned()
118 && !$prg->getApplicableMembershipSourceForUser($ass->getUserId(), null)
119 ) {
120 continue;
121 }
122
123 $this->log(
124 sprintf(
125 'PRG, RestartAssignments: user %s\'s assignment %s is being restarted (Programme %s)',
126 $ass->getUserId(),
127 $ass->getId(),
128 $ass->getRootId()
129 )
130 );
131
132 $restarted = $prg->assignUser($ass->getUserId(), self::ACTING_USR_ID, false);
133 $ass = $ass->withRestarted($restarted->getId(), $today);
134 $this->assignment_repo->store($ass);
135
136 $this->adapter->actOnSingleAssignment($restarted);
137
138 $result->setStatus(ilCronJobResult::STATUS_OK);
139 }
140 }
141
142 return $result;
143 }
144
145 protected function getStudyProgramme(int $prg_obj_id): ilObjStudyProgramme
146 {
147 if (!array_key_exists($prg_obj_id, $this->prgs)) {
148 $this->prgs[$prg_obj_id] = ilObjStudyProgramme::getInstanceByObjId($prg_obj_id);
149 }
150 return $this->prgs[$prg_obj_id];
151 }
152
153 protected function getNow(): DateTimeImmutable
154 {
155 return new DateTimeImmutable();
156 }
157
158 protected function log(string $msg): void
159 {
160 $this->log->write($msg);
161 }
162}
Component logger with individual log levels by component id.
const SCHEDULE_TYPE_IN_DAYS
@depracated This will be replaced with an ENUM in ILIAS 9
language handling
static getInstanceByObjId(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Re-assign users (according to restart-date).
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$dic
Definition: result.php:32