ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCronDeleteInactiveUserReminderMail.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once 'Services/Mail/classes/class.ilMailNotification.php';
5 
13 {
14  const TABLE_NAME = "usr_cron_mail_reminder";
15 
16  private static function mailSent($usr_id)
17  {
18  global $DIC;
19 
20  $ilDB = $DIC['ilDB'];
21  $ilDB->manipulateF(
22  "INSERT INTO " . self::TABLE_NAME . " (usr_id, ts) VALUES (%s, %s)",
23  array(
24  "integer",
25  "integer"
26  ),
27  array(
28  $usr_id,
29  time()
30  )
31  );
32  }
33 
34  private static function sendReminder(ilObjUser $user, $reminderTime, $time_frame_for_deletion)
35  {
36  include_once 'Services/User/classes/class.ilCronDeleteInactiveUserReminderMailNotification.php';
38  $mail->setRecipients(array($user));
39  $mail->setAdditionalInformation(
40  array(
41  "www" => ilUtil::_getHttpPath(),
42  "days" => $reminderTime,
43  "date" => $time_frame_for_deletion
44  )
45  );
46  $mail->send();
47  self::mailSent($user->getId());
48  }
49 
51  {
52  global $DIC;
53 
54  $ilDB = $DIC['ilDB'];
55  $query = "SELECT usr_id,ts FROM " . self::TABLE_NAME;
56  $res = $ilDB->queryF($query, array(
57  'integer',
58  'integer'
59  ), array(
60  'usr_id',
61  'ts'
62  ));
63  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
64  $lastLoginUnixtime = strtotime(ilObjUser::_lookupLastLogin($row->usr_id));
65  $lastReminderSent = (int) $row->ts;
66  if ($lastLoginUnixtime >= $lastReminderSent) {
67  self::removeSingleUserFromTable($row->usr_id);
68  }
69  }
70  }
71 
72  public static function checkIfReminderMailShouldBeSend(ilObjUser $user, $reminderTime, $time_frame_for_deletion)
73  {
74  global $DIC;
75 
76  $ilDB = $DIC['ilDB'];
77  $query = "SELECT ts FROM " . self::TABLE_NAME . " WHERE usr_id = %s";
78  $res = $ilDB->queryF($query, array('integer'), array($user->getId()));
80  if ($row->ts == null) {
81  self::sendReminder($user, $reminderTime, $time_frame_for_deletion);
82  return true;
83  }
84  return false;
85  }
86 
87  public static function flushDataTable()
88  {
89  global $DIC;
90 
91  $ilDB = $DIC['ilDB'];
92  $ilDB->manipulate("DELETE FROM " . self::TABLE_NAME);
93  }
94 
95  public static function removeSingleUserFromTable($usr_id)
96  {
97  global $DIC;
98 
99  $ilDB = $DIC['ilDB'];
100  $query = "DELETE FROM " . self::TABLE_NAME . " WHERE usr_id = %s";
101  $ilDB->manipulateF($query, array('integer'), array($usr_id));
102  }
103 }
global $DIC
Definition: saml.php:7
static sendReminder(ilObjUser $user, $reminderTime, $time_frame_for_deletion)
static checkIfReminderMailShouldBeSend(ilObjUser $user, $reminderTime, $time_frame_for_deletion)
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
foreach($_POST as $key=> $value) $res
getId()
get object id public
$query
$user
Definition: migrateto20.php:57
$row
static _getHttpPath()
global $ilDB
static _lookupLastLogin($a_user_id)
lookup last login