ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilPrgUserRiskyToFailCronJob.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
24 {
25  private const ID = 'prg_user_risky_to_fail';
26 
28  protected ilLanguage $lng;
31 
32  public function __construct()
33  {
34  global $DIC;
35  $this->log = $DIC['ilLog'];
36  $this->lng = $DIC['lng'];
37  $this->lng->loadLanguageModule('prg');
38 
40  $this->assignment_repo = $dic['repo.assignment'];
41  $this->adapter = $dic['cron.riskyToFail'];
42  }
43 
44  public function getTitle(): string
45  {
46  return $this->lng->txt('prg_user_risky_to_fail_title');
47  }
48 
49  public function getDescription(): string
50  {
51  return $this->lng->txt('prg_user_risky_to_fail_desc');
52  }
53 
54  public function getId(): string
55  {
56  return self::ID;
57  }
58 
59  public function hasAutoActivation(): bool
60  {
61  return true;
62  }
63 
64  public function hasFlexibleSchedule(): bool
65  {
66  return true;
67  }
68 
70  {
71  return CronJobScheduleType::SCHEDULE_TYPE_IN_DAYS;
72  }
73 
74  public function getDefaultScheduleValue(): ?int
75  {
76  return 1;
77  }
78 
79  public function run(): ilCronJobResult
80  {
81  $result = new ilCronJobResult();
82  $result->setStatus(ilCronJobResult::STATUS_NO_ACTION);
83 
84  $programmes_to_send = $this->adapter->getRelevantProgrammeIds();
85  if (count($programmes_to_send) == 0) {
86  return $result;
87  }
88 
89  $today = $this->getNow();
90  $programmes_and_due = [];
91  foreach ($programmes_to_send as $programme_obj_id => $days_offset_mail) {
92  $interval = new DateInterval('P' . $days_offset_mail . 'D');
93  $due = $today->add($interval);
94  $programmes_and_due[$programme_obj_id] = $due;
95  }
96 
97 
98  //root-assignments for any node that has deadline = $due and was not sent before;
99  $assignments = $this->assignment_repo->getRiskyToFail($programmes_and_due, true);
100 
101  if (count($assignments) == 0) {
102  return $result;
103  }
104 
105  foreach ($assignments as $ass) {
106  $pgs = $ass->getProgressTree();
107  $this->log(
108  sprintf(
109  'PRG, RiskyToFail: user %s at progress %s (prg obj_id %s)',
110  $ass->getUserId(),
111  $ass->getId(),
112  $pgs->getNodeId()
113  )
114  );
115 
116  $this->adapter->actOnSingleAssignment($ass);
117  $this->assignment_repo->storeRiskyToFailSentFor($ass);
118  }
119  $result->setStatus(ilCronJobResult::STATUS_OK);
120  return $result;
121  }
122 
123  protected function getNow(): \DateTimeImmutable
124  {
125  return new DateTimeImmutable();
126  }
127 
128  protected function log(string $msg): void
129  {
130  $this->log->write($msg);
131  }
132 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilPRGAssignmentDBRepository $assignment_repo
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
final const STATUS_NO_ACTION
global $DIC
Definition: shib_login.php:25
Assignments are relations of users to a PRG; They hold progress-information for (sub-)nodes of the PR...
$dic
Definition: ltiresult.php:33