ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCronMailNotification.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 {
12  public function sendNotifications()
13  {
14  global $ilias, $ilDB, $ilLog;
15 
16  include_once 'Services/Mail/classes/class.ilMail.php';
17  include_once 'Services/User/classes/class.ilObjUser.php';
18  include_once 'Services/Language/classes/class.ilLanguage.php';
19  include_once 'Services/Mail/classes/class.ilMimeMail.php';
20 
21  $res = $ilDB->queryF('SELECT mail.* FROM mail_options
22  INNER JOIN mail ON mail.user_id = mail_options.user_id
23  INNER JOIN mail_obj_data ON mail_obj_data.obj_id = mail.folder_id
24  WHERE cronjob_notification = %s
25  AND send_time >= %s
26  AND mail_obj_data.m_type = %s
27  AND m_status = %s',
28  array('integer', 'timestamp', 'text', 'text'),
29  array(1, date('Y-m-d H:i:s', time() - 60 * 60 * 24), 'inbox', 'unread')
30  );
31 
32  $users = array();
33 
34  $user_id = 0;
35  while($row = $ilDB->fetchAssoc($res))
36  {
37  if($user_id == 0 || $row['user_id'] != $user_id) $user_id = $row['user_id'];
38  $users[$user_id][] = $row;
39  }
40 
41  $numRows = 0;
42  foreach($users as $user_id => $mail_data)
43  {
44  $tmp_mail_obj = new ilMail($user_id);
45 
46  $mmail = new ilMimeMail();
47  $mmail->autoCheck(false);
48  $mmail->From('noreply');
49  $mmail->To(ilObjUser::_lookupEmail($user_id));
50  $mmail->Subject($tmp_mail_obj->formatNotificationSubject());
51  $mmail->Body($tmp_mail_obj->formatNotificationMessage($user_id, $mail_data));
52  $mmail->Send();
53 
54  unset($tmp_mail_obj);
55 
56  ++$numRows;
57  }
58 
59  $ilLog->write(__METHOD__.': Send '.$numRows.' messages.');
60 
61  return true;
62  }
63 }
64 ?>