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