ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  public function __construct()
22  {
23  $this->collect();
24  }
25 
29  public function collect()
30  {
31  global $ilDB, $ilSetting;
32 
33  $mail_notify_orphaned = (int)$ilSetting->get('mail_notify_orphaned');
34  $mail_threshold = (int)$ilSetting->get('mail_threshold');
35 
36  if($mail_threshold > $mail_notify_orphaned )
37  {
38  $notify_days_before = $mail_threshold - $mail_notify_orphaned;
39  }
40  else
41  {
42  $notify_days_before = 1;
43  }
44 
45  $ts_notify = strtotime("- ".$notify_days_before." days");
46  $ts_for_notification = date('Y-m-d', $ts_notify).' 23:59:59';
47 
48  $res = $ilDB->query('SELECT mail_id FROM mail_cron_orphaned');
49  $already_notified = array();
50  while($row = $ilDB->fetchAssoc($res))
51  {
52  $already_notified[] = $row['mail_id'];
53  }
54 
55  //.. überprüfen ob es bereits einen Eintrag in "mail_cron_orphaned" gibt
56  $types = array('timestamp');
57  $data = array($ts_for_notification);
58 
59  $notification_query = "
60  SELECT mail_id, m.user_id, folder_id, send_time, m_subject, mdata.title
61  FROM mail m
62  INNER JOIN mail_obj_data mdata ON obj_id = folder_id
63  WHERE send_time <= %s";
64 
65  if((int)$ilSetting->get('mail_only_inbox_trash') > 0)
66  {
67  $notification_query .= " AND (mdata.m_type = %s OR mdata.m_type = %s)";
68  $types = array('timestamp', 'text', 'text');
69  $data = array($ts_for_notification, 'inbox', 'trash');
70  }
71 
72  $notification_query .= " AND " . $ilDB->in('mail_id', $already_notified, true, 'integer')
73  . " ORDER BY m.user_id, folder_id, mail_id";
74 
75  $res = $ilDB->queryF($notification_query, $types, $data);
76 
77  $collection_obj = NULL;
78  $folder_obj = NULL;
79 
80  while($row = $ilDB->fetchAssoc($res))
81  {
82  if(!$this->existsCollectionObjForUserId($row['user_id']))
83  {
84  if(is_object($collection_obj))
85  {
86  $this->addCollectionObject($collection_obj);
87  }
88  }
89 
90  if(!is_object($collection_obj))
91  {
92  $collection_obj = new ilMailCronOrphanedMailsNotificationCollectionObj($row['user_id']);
93  }
94 
95  if(is_object($collection_obj))
96  {
97  if(!$folder_obj = $collection_obj->getFolderObjectById($row['folder_id']))
98  {
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  {
106  $orphaned_mail_obj = new ilMailCronOrphanedMailsFolderMailObject($row['mail_id'], $row['m_subject']);
107  $folder_obj->addMailObject($orphaned_mail_obj);
108  }
109  }
110  }
111  if(is_object($collection_obj))
112  {
113  $this->addCollectionObject($collection_obj);
114  unset($collection_obj);
115  }
116  }
117 
122  {
123  $this->collection[$collection_obj->getUserId()] = $collection_obj;
124  }
125 
130  private function existsCollectionObjForUserId($user_id)
131  {
132  if(isset($this->collection[$user_id]))
133  {
134  return true;
135  }
136  return false;
137  }
138 
142  public function getCollection()
143  {
144  return $this->collection;
145  }
146 }
addCollectionObject(ilMailCronOrphanedMailsNotificationCollectionObj $collection_obj)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
Create styles array
The data for the language used.
global $ilSetting
Definition: privfeed.php:17
global $ilDB