ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPrgUserNotRestartedCronJob.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2019 Stefan Hecken <stefan.hecken@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 declare(strict_types=1);
6 
11 {
12  const ID = 'prg_user_not_restarted';
13 
18 
22  protected $user_progress_db;
23 
27  protected $events;
28 
32  protected $dic;
33 
37  protected $lng;
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 
46  $this->dic = ilStudyProgrammeDIC::dic();
47  }
48 
54  public function getTitle()
55  {
56  return $this->lng->txt('prg_user_not_restarted_title');
57  }
58 
64  public function getDescription()
65  {
66  return $this->lng->txt('prg_user_not_restarted_desc');
67  }
68 
74  public function getId()
75  {
76  return self::ID;
77  }
78 
84  public function hasAutoActivation()
85  {
86  return true;
87  }
88 
94  public function hasFlexibleSchedule()
95  {
96  return true;
97  }
98 
104  public function getDefaultScheduleType()
105  {
106  return self::SCHEDULE_TYPE_IN_DAYS;
107  }
108 
114  public function getDefaultScheduleValue()
115  {
116  return 1;
117  }
118 
125  public function run()
126  {
127  $result = new ilCronJobResult();
129 
130  $programmes_to_send = $this->getSettingsRepository()
131  ->getProgrammeIdsWithMailsForExpiringValidity();
132 
133  if (count($programmes_to_send) == 0) {
134  return $result;
135  }
136 
137  $today = $this->getNow();
138  $programmes_and_due = [];
139  foreach ($programmes_to_send as $programme_obj_id => $days_offset_mail) {
140  $interval = new DateInterval('P' . $days_offset_mail . 'D');
141  $due = $today->add($interval);
142  $programmes_and_due[$programme_obj_id] = $due;
143  }
144 
145  $progresses = $this->getProgressRepository()
146  ->getAboutToExpire($programmes_and_due, true);
147 
148  if (count($progresses) == 0) {
149  return $result;
150  }
151 
152  $events = $this->getEvents();
153  foreach ($progresses as $progress) {
154  $this->log(
155  sprintf(
156  'PRG, UserNotRestarted: user %s\'s qualification is about to expire at progress %s (prg obj_id %s)',
157  $progress->getUserId(),
158  $progress->getId(),
159  $progress->getNodeId()
160  )
161  );
162 
163  $events->informUserByMailToRestart($progress);
164  }
166  return $result;
167  }
168 
169  protected function getNow() : \DateTimeImmutable
170  {
171  return new DateTimeImmutable();
172  }
173 
175  {
176  return $this->dic['model.Settings.ilStudyProgrammeSettingsRepository'];
177  }
178 
180  {
181  return $this->dic['ilStudyProgrammeUserProgressDB'];
182  }
183 
185  {
186  return $this->dic['ilStudyProgrammeUserAssignmentDB'];
187  }
188 
189  protected function getEvents()
190  {
191  return $this->dic['ilStudyProgrammeEvents'];
192  }
193 
194  protected function log(string $msg) : void
195  {
196  $this->log->write($msg);
197  }
198 }
$result
Cron job application base class.
Inform a user, that her qualification is about to expire.
global $DIC
Definition: goto.php:24
hasFlexibleSchedule()
Can the schedule be configured?
hasAutoActivation()
Is to be activated on "installation".
Cron job result data container.