ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCronDeleteInactiveUserReminderMail.php
Go to the documentation of this file.
1<?php
2
24{
25 public const TABLE_NAME = "usr_cron_mail_reminder";
26
27 public function __construct(
28 private ilDBInterface $db
29 ) {
30 }
31
33 {
34 $query = "SELECT usr_id,ts FROM " . self::TABLE_NAME;
35 $res = $this->db->queryF($query, [
36 'integer',
37 'integer'
38 ], [
39 'usr_id',
40 'ts'
41 ]);
42 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
43 $lastLoginUnixtime = strtotime(ilObjUser::_lookupLastLogin($row->usr_id));
44 $lastReminderSent = (int) $row->ts;
45 if ($lastLoginUnixtime >= $lastReminderSent) {
46 $this->removeSingleUserFromTable($row->usr_id);
47 }
48 }
49 }
50
51 public function sendReminderMailIfNeeded(
52 ilObjUser $user,
53 int $reminderTime,
54 int $time_frame_for_deletion
55 ): bool {
56 $query = "SELECT ts FROM " . self::TABLE_NAME . " WHERE usr_id = %s";
57 $res = $this->db->queryF($query, ['integer'], [$user->getId()]);
58 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
59 if ($row === false || $row->ts === null) {
60 $this->sendReminder($user, $reminderTime, $time_frame_for_deletion);
61 return true;
62 }
63 return false;
64 }
65
66 public function flushDataTable(): void
67 {
68
69 $this->db->manipulate("DELETE FROM " . self::TABLE_NAME);
70 }
71
72 public function removeSingleUserFromTable(int $usr_id): void
73 {
74 $query = "DELETE FROM " . self::TABLE_NAME . " WHERE usr_id = %s";
75 $this->db->manipulateF($query, ['integer'], [$usr_id]);
76 }
77
78 private function persistMailSent(int $usr_id): void
79 {
80 $this->db->manipulateF(
81 "INSERT INTO " . self::TABLE_NAME . " (usr_id, ts) VALUES (%s, %s)",
82 [
83 "integer",
84 "integer"
85 ],
86 [
87 $usr_id,
88 time()
89 ]
90 );
91 }
92
93 private function sendReminder(
94 ilObjUser $user,
95 int $reminderTime,
96 int $time_frame_for_deletion
97 ): void {
99 $mail->setRecipients([$user]);
100 $mail->setAdditionalInformation(
101 [
102 "www" => ilUtil::_getHttpPath(),
103 "days" => $reminderTime,
104 "date" => $time_frame_for_deletion
105 ]
106 );
107 $mail->send();
108 $this->persistMailSent($user->getId());
109 }
110}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
sendReminder(ilObjUser $user, int $reminderTime, int $time_frame_for_deletion)
sendReminderMailIfNeeded(ilObjUser $user, int $reminderTime, int $time_frame_for_deletion)
User class.
static _lookupLastLogin(int $a_user_id)
static _getHttpPath()
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
if(!file_exists('../ilias.ini.php'))