ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilMailCronOrphanedMailsNotificationCollector.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3 include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsNotificationCollectionObj.php';
4 include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsFolderObject.php';
5 include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsFolderMailObject.php';
6 
12 {
16  protected $collection = array();
17 
21  protected $db;
22 
26  protected $setting;
27 
31  public function __construct()
32  {
33  global $DIC;
34 
35  $this->db = $DIC->database();
36  $this->setting = $DIC->settings();
37 
38  $this->collect();
39  }
40 
44  public function collect()
45  {
46  $mail_notify_orphaned = (int) $this->setting->get('mail_notify_orphaned');
47  $mail_threshold = (int) $this->setting->get('mail_threshold');
48 
49  if ($mail_threshold > $mail_notify_orphaned) {
50  $notify_days_before = $mail_threshold - $mail_notify_orphaned;
51  } else {
52  $notify_days_before = 1;
53  }
54 
55  $ts_notify = strtotime("- " . $notify_days_before . " days");
56  $ts_for_notification = date('Y-m-d', $ts_notify) . ' 23:59:59';
57 
58  $res = $this->db->query('SELECT mail_id FROM mail_cron_orphaned');
59  $already_notified = array();
60  while ($row = $this->db->fetchAssoc($res)) {
61  $already_notified[$row['mail_id']] = $row['mail_id'];
62  }
63 
64  $types = array('timestamp');
65  $data = array($ts_for_notification);
66 
67  $notification_query = "
68  SELECT mail_id, m.user_id, folder_id, send_time, m_subject, mdata.title
69  FROM mail m
70  INNER JOIN mail_obj_data mdata ON obj_id = folder_id
71  WHERE send_time <= %s";
72 
73  if ((int) $this->setting->get('mail_only_inbox_trash') > 0) {
74  $notification_query .= " AND (mdata.m_type = %s OR mdata.m_type = %s)";
75  $types = array('timestamp', 'text', 'text');
76  $data = array($ts_for_notification, 'inbox', 'trash');
77  }
78 
79  $notification_query .= " AND " . $this->db->in('mail_id', array_values($already_notified), true, 'integer')
80  . " ORDER BY m.user_id, folder_id, mail_id";
81 
82  $collection_obj = null;
83  $folder_obj = null;
84 
85  $res = $this->db->queryF($notification_query, $types, $data);
86  while ($row = $this->db->fetchAssoc($res)) {
87  if (!$this->existsCollectionObjForUserId($row['user_id'])) {
88  if (is_object($collection_obj)) {
89  $this->addCollectionObject($collection_obj);
90  }
91  }
92 
93  if (!is_object($collection_obj)) {
94  $collection_obj = new ilMailCronOrphanedMailsNotificationCollectionObj($row['user_id']);
95  }
96 
97  if (is_object($collection_obj)) {
98  if (!$folder_obj = $collection_obj->getFolderObjectById($row['folder_id'])) {
99  $folder_obj = new ilMailCronOrphanedMailsFolderObject($row['folder_id']);
100  $folder_obj->setFolderTitle($row['title']);
101  $collection_obj->addFolderObject($folder_obj);
102  }
103 
104  if (is_object($folder_obj)) {
105  $orphaned_mail_obj = new ilMailCronOrphanedMailsFolderMailObject($row['mail_id'], $row['m_subject']);
106  $folder_obj->addMailObject($orphaned_mail_obj);
107  }
108  }
109  }
110 
111  if (is_object($collection_obj)) {
112  $this->addCollectionObject($collection_obj);
113  unset($collection_obj);
114  }
115  }
116 
121  {
122  $this->collection[$collection_obj->getUserId()] = $collection_obj;
123  }
124 
129  private function existsCollectionObjForUserId($user_id)
130  {
131  if (isset($this->collection[$user_id])) {
132  return true;
133  }
134 
135  return false;
136  }
137 
141  public function getCollection()
142  {
143  return $this->collection;
144  }
145 }
global $DIC
Definition: saml.php:7
addCollectionObject(ilMailCronOrphanedMailsNotificationCollectionObj $collection_obj)
foreach($_POST as $key=> $value) $res
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
Create styles array
The data for the language used.