ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 function mailSent($usr_id)
17  {
18  global $ilDB;
19  $ilDB->manipulateF("INSERT INTO " . self::TABLE_NAME . " (usr_id, ts) VALUES (%s, %s)",
20  array(
21  "integer",
22  "integer"
23  ),
24  array(
25  $usr_id,
26  time()
27  )
28  );
29  }
30 
31  private function sendReminder(ilObjUser $user, $reminderTime, $time_frame_for_deletion)
32  {
33  include_once 'Services/User/classes/class.ilCronDeleteInactiveUserReminderMailNotification.php';
35  $mail->setRecipients(array($user));
36  $mail->setAdditionalInformation(
37  array(
38  "www" => ilUtil::_getHttpPath(),
39  "days" => $reminderTime,
40  "date" => $time_frame_for_deletion
41  )
42  );
43  $mail->send();
44  self::mailSent($user->getId());
45  }
46 
48  {
49  global $ilDB;
50  $query = "SELECT usr_id,ts FROM " . self::TABLE_NAME;
51  $res = $ilDB->queryF($query, array(
52  'integer',
53  'integer'
54  ), array(
55  'usr_id',
56  'ts'
57  ));
58  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
59  {
60  $lastLoginUnixtime = strtotime(ilObjUser::_lookupLastLogin($row->usr_id));
61  $lastReminderSent = (int)$row->ts;
62  if($lastLoginUnixtime >= $lastReminderSent)
63  {
65  }
66  }
67  }
68 
69  public static function checkIfReminderMailShouldBeSend(ilObjUser $user, $reminderTime, $time_frame_for_deletion)
70  {
71  global $ilDB;
72  $query = "SELECT ts FROM " . self::TABLE_NAME . " WHERE usr_id = %s";
73  $res = $ilDB->queryF($query, array('integer'), array($user->getId()));
74  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
75  if($row->ts == null)
76  {
77  self::sendReminder($user, $reminderTime, $time_frame_for_deletion);
78  return true;
79  }
80  return false;
81  }
82 
83  public static function flushDataTable()
84  {
85  global $ilDB;
86  $ilDB->manipulate("DELETE FROM " . self::TABLE_NAME);
87  }
88 
89  public static function removeSingleUserFromTable($usr_id)
90  {
91  global $ilDB;
92  $query = "DELETE FROM " . self::TABLE_NAME . " WHERE usr_id = %s";
93  $ilDB->manipulateF($query, array('integer'), array($usr_id));
94  }
95 }