ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilPrgUserRiskyToFailCronJob.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
8
10{
11 const ID = 'prg_user_risky_to_fail';
12
17
22
26 protected $events;
27
31 protected $dic;
32
36 protected $lng;
37
38 public function __construct()
39 {
40 global $DIC;
41 $this->log = $DIC['ilLog'];
42 $this->lng = $DIC['lng'];
43 $this->lng->loadLanguageModule('prg');
44
45 $this->dic = ilStudyProgrammeDIC::dic();
46 }
47
53 public function getTitle()
54 {
55 return $this->lng->txt('prg_user_risky_to_fail_title');
56 }
57
63 public function getDescription()
64 {
65 return $this->lng->txt('prg_user_risky_to_fail_desc');
66 }
67
73 public function getId()
74 {
75 return self::ID;
76 }
77
83 public function hasAutoActivation()
84 {
85 return true;
86 }
87
93 public function hasFlexibleSchedule()
94 {
95 return true;
96 }
97
103 public function getDefaultScheduleType()
104 {
106 }
107
113 public function getDefaultScheduleValue()
114 {
115 return 1;
116 }
117
118 public function run()
119 {
120 $result = new ilCronJobResult();
122
123 $programmes_to_send = $this->getSettingsRepository()
124 ->getProgrammeIdsWithRiskyToFailSettings();
125
126 if (count($programmes_to_send) == 0) {
127 return $result;
128 }
129
130 $today = $this->getNow();
131 $programmes_and_due = [];
132 foreach ($programmes_to_send as $programme_obj_id => $days_offset_mail) {
133 $interval = new DateInterval('P' . $days_offset_mail . 'D');
134 $due = $today->add($interval);
135 $programmes_and_due[$programme_obj_id] = $due;
136 }
137
138 $progresses = $this->getProgressRepository()
139 ->getRiskyToFail($programmes_and_due);
140
141 if (count($progresses) == 0) {
142 return $result;
143 }
144
145 $events = $this->getEvents();
146 foreach ($progresses as $progress) {
147 $this->log(
148 sprintf(
149 'PRG, RiskyToFail: user %s at progress %s (prg obj_id %s)',
150 $progress->getUserId(),
151 $progress->getId(),
152 $progress->getNodeId()
153 )
154 );
155 $events->userRiskyToFail($progress);
156 }
158 return $result;
159 }
160
161 protected function getNow() : \DateTimeImmutable
162 {
163 return new DateTimeImmutable();
164 }
165
167 {
168 return $this->dic['model.Settings.ilStudyProgrammeSettingsRepository'];
169 }
170
172 {
173 return $this->dic['ilStudyProgrammeUserProgressDB'];
174 }
175
176 protected function getEvents()
177 {
178 return $this->dic['ilStudyProgrammeEvents'];
179 }
180
181 protected function log(string $msg) : void
182 {
183 $this->log->write($msg);
184 }
185}
$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
hasFlexibleSchedule()
Can the schedule be configured?
hasAutoActivation()
Is to be activated on "installation".
global $DIC
Definition: goto.php:24