ILIAS  release_8 Revision v8.24
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 private static function mailSent(int $usr_id): void
28 {
29 global $DIC;
30
31 $ilDB = $DIC['ilDB'];
32 $ilDB->manipulateF(
33 "INSERT INTO " . self::TABLE_NAME . " (usr_id, ts) VALUES (%s, %s)",
34 array(
35 "integer",
36 "integer"
37 ),
38 array(
39 $usr_id,
40 time()
41 )
42 );
43 }
44
45 private static function sendReminder(
46 ilObjUser $user,
47 int $reminderTime,
48 int $time_frame_for_deletion
49 ): void {
51 $mail->setRecipients(array($user));
52 $mail->setAdditionalInformation(
53 array(
54 "www" => ilUtil::_getHttpPath(),
55 "days" => $reminderTime,
56 "date" => $time_frame_for_deletion
57 )
58 );
59 $mail->send();
60 self::mailSent($user->getId());
61 }
62
63 public static function removeEntriesFromTableIfLastLoginIsNewer(): void
64 {
65 global $DIC;
66
67 $ilDB = $DIC['ilDB'];
68 $query = "SELECT usr_id,ts FROM " . self::TABLE_NAME;
69 $res = $ilDB->queryF($query, array(
70 'integer',
71 'integer'
72 ), array(
73 'usr_id',
74 'ts'
75 ));
76 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
77 $lastLoginUnixtime = strtotime(ilObjUser::_lookupLastLogin($row->usr_id));
78 $lastReminderSent = (int) $row->ts;
79 if ($lastLoginUnixtime >= $lastReminderSent) {
80 self::removeSingleUserFromTable($row->usr_id);
81 }
82 }
83 }
84
85 public static function sendReminderMailIfNeeded(
86 ilObjUser $user,
87 int $reminderTime,
88 int $time_frame_for_deletion
89 ): bool {
90 global $DIC;
91
92 $ilDB = $DIC['ilDB'];
93 $query = "SELECT ts FROM " . self::TABLE_NAME . " WHERE usr_id = %s";
94 $res = $ilDB->queryF($query, array('integer'), array($user->getId()));
95 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
96 if ($row === false || $row->ts === null) {
97 self::sendReminder($user, $reminderTime, $time_frame_for_deletion);
98 return true;
99 }
100 return false;
101 }
102
103 public static function flushDataTable(): void
104 {
105 global $DIC;
106
107 $ilDB = $DIC['ilDB'];
108 $ilDB->manipulate("DELETE FROM " . self::TABLE_NAME);
109 }
110
111 public static function removeSingleUserFromTable(int $usr_id): void
112 {
113 global $DIC;
114
115 $ilDB = $DIC['ilDB'];
116 $query = "DELETE FROM " . self::TABLE_NAME . " WHERE usr_id = %s";
117 $ilDB->manipulateF($query, array('integer'), array($usr_id));
118 }
119}
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...
static sendReminder(ilObjUser $user, int $reminderTime, int $time_frame_for_deletion)
static sendReminderMailIfNeeded(ilObjUser $user, int $reminderTime, int $time_frame_for_deletion)
User class.
static _lookupLastLogin(int $a_user_id)
static _getHttpPath()
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69
$query