ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilPrgRestartAssignmentsCronJob.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
30 {
31  private const ID = 'prg_restart_assignments_temporal_progress';
33 
35  protected ilLanguage $lng;
38 
39  protected array $prgs = [];
40 
41  public function __construct()
42  {
43  global $DIC;
44  $this->log = $DIC['ilLog'];
45  $this->lng = $DIC['lng'];
46  $this->lng->loadLanguageModule('prg');
47 
49  $this->assignment_repo = $dic['repo.assignment'];
50  $this->adapter = $dic['cron.restart'];
51  }
52 
53  public function getTitle(): string
54  {
55  return $this->lng->txt('prg_restart_assignments_temporal_progress_title');
56  }
57 
58  public function getDescription(): string
59  {
60  return $this->lng->txt('prg_restart_assignments_temporal_progress_desc');
61  }
62 
63  public function getId(): string
64  {
65  return self::ID;
66  }
67 
68  public function hasAutoActivation(): bool
69  {
70  return true;
71  }
72 
73  public function hasFlexibleSchedule(): bool
74  {
75  return true;
76  }
77 
79  {
80  return JobScheduleType::IN_DAYS;
81  }
82 
83  public function getDefaultScheduleValue(): ?int
84  {
85  return 1;
86  }
87 
88  public function run(): JobResult
89  {
90  $result = new JobResult();
91  $result->setStatus(JobResult::STATUS_NO_ACTION);
92 
93  $programmes_to_reassign = $this->adapter->getRelevantProgrammeIds();
94  if (count($programmes_to_reassign) === 0) {
95  return $result;
96  }
97 
98  $today = $this->getNow();
99  $programmes_and_due = [];
100 
101  foreach ($programmes_to_reassign as $programme_obj_id => $days_offset) {
102  $interval = new DateInterval('P' . $days_offset . 'D');
103  $due = $today->add($interval);
104  $programmes_and_due[$programme_obj_id] = $due;
105  }
106 
107  $assignments = $this->assignment_repo->getAboutToExpire($programmes_and_due, false);
108 
109  if (count($assignments) === 0) {
110  return $result;
111  }
112 
113  foreach ($assignments as $ass) {
114  if ($ass->getRestartedAssignmentId() < 0) {
115  $prg = $this->getStudyProgramme($ass->getRootId());
116 
117  $restart_settings = $prg->getSettings()->getValidityOfQualificationSettings();
118  if ($restart_settings->getRestartRecheck()
119  && !$ass->isManuallyAssigned()
120  && !$prg->getApplicableMembershipSourceForUser($ass->getUserId(), null)
121  ) {
122  continue;
123  }
124 
125  $this->log(
126  sprintf(
127  'PRG, RestartAssignments: user %s\'s assignment %s is being restarted (Programme %s)',
128  $ass->getUserId(),
129  $ass->getId(),
130  $ass->getRootId()
131  )
132  );
133 
134  $restarted = $prg->assignUser($ass->getUserId(), self::ACTING_USR_ID, false);
135  $ass = $ass->withRestarted($restarted->getId(), $today);
136  $this->assignment_repo->store($ass);
137 
138  $this->adapter->actOnSingleAssignment($restarted);
139 
140  $result->setStatus(JobResult::STATUS_OK);
141  }
142  }
143 
144  return $result;
145  }
146 
147  protected function getStudyProgramme(int $prg_obj_id): ilObjStudyProgramme
148  {
149  if (!array_key_exists($prg_obj_id, $this->prgs)) {
150  $this->prgs[$prg_obj_id] = ilObjStudyProgramme::getInstanceByObjId($prg_obj_id);
151  }
152  return $this->prgs[$prg_obj_id];
153  }
154 
155  protected function getNow(): DateTimeImmutable
156  {
157  return new DateTimeImmutable();
158  }
159 
160  protected function log(string $msg): void
161  {
162  $this->log->write($msg);
163  }
164 }
Component logger with individual log levels by component id.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22
Re-assign users (according to restart-date).
static getInstanceByObjId(int $obj_id)
Assignments are relations of users to a PRG; They hold progress-information for (sub-)nodes of the PR...
$dic
Definition: result.php:31