ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilPrgUserNotRestartedCronJob.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
27 {
28  private const ID = 'prg_user_not_restarted';
29 
31  protected ilLanguage $lng;
34 
35  public function __construct()
36  {
37  global $DIC;
38  $this->log = $DIC['ilLog'];
39  $this->lng = $DIC['lng'];
40  $this->lng->loadLanguageModule('prg');
41 
43  $this->assignment_repo = $dic['repo.assignment'];
44  $this->adapter = $dic['cron.notRestarted'];
45  }
46 
47  public function getTitle(): string
48  {
49  return $this->lng->txt('prg_user_not_restarted_title');
50  }
51 
52  public function getDescription(): string
53  {
54  return $this->lng->txt('prg_user_not_restarted_desc');
55  }
56 
57  public function getId(): string
58  {
59  return self::ID;
60  }
61 
62  public function hasAutoActivation(): bool
63  {
64  return true;
65  }
66 
67  public function hasFlexibleSchedule(): bool
68  {
69  return true;
70  }
71 
73  {
74  return CronJobScheduleType::SCHEDULE_TYPE_IN_DAYS;
75  }
76 
77  public function getDefaultScheduleValue(): ?int
78  {
79  return 1;
80  }
81 
82  public function run(): ilCronJobResult
83  {
84  $result = new ilCronJobResult();
85  $result->setStatus(ilCronJobResult::STATUS_NO_ACTION);
86 
87  $programmes_to_send = $this->adapter->getRelevantProgrammeIds();
88  if (count($programmes_to_send) == 0) {
89  return $result;
90  }
91 
92  $today = $this->getNow();
93  $programmes_and_due = [];
94  foreach ($programmes_to_send as $programme_obj_id => $days_offset_mail) {
95  $interval = new DateInterval('P' . $days_offset_mail . 'D');
96  $due = $today->add($interval);
97  $programmes_and_due[$programme_obj_id] = $due;
98  }
99 
100  $assignments = $this->assignment_repo->getAboutToExpire($programmes_and_due, true);
101 
102  if (count($assignments) == 0) {
103  return $result;
104  }
105  foreach ($assignments as $ass) {
106  $pgs = $ass->getProgressTree();
107  $this->log(
108  sprintf(
109  'PRG, UserNotRestarted: user %s\'s qualification is about to expire at assignment %s (prg obj_id %s)',
110  $ass->getUserId(),
111  $ass->getId(),
112  $pgs->getNodeId()
113  )
114  );
115  $this->adapter->actOnSingleAssignment($ass);
116  $this->assignment_repo->storeExpiryInfoSentFor($ass);
117  }
118  $result->setStatus(ilCronJobResult::STATUS_OK);
119  return $result;
120  }
121 
122  protected function getNow(): DateTimeImmutable
123  {
124  return new DateTimeImmutable();
125  }
126 
127  protected function log(string $msg): void
128  {
129  $this->log->write($msg);
130  }
131 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Component logger with individual log levels by component id.
Inform a user, that her qualification is about to expire.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
final const STATUS_NO_ACTION
Assignments are relations of users to a PRG; They hold progress-information for (sub-)nodes of the PR...
$dic
Definition: result.php:32