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