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