16 global $ilAccess, $ilDB,
$lng;
18 static $cache = array();
19 static $attachments_cache = array();
21 include_once
'Modules/Forum/classes/class.ilObjForum.php';
22 include_once
'Services/Mail/classes/class.ilMail.php';
23 include_once
'Services/User/classes/class.ilObjUser.php';
24 include_once
'Services/Language/classes/class.ilLanguage.php';
27 $frm = $forumObj->Forum;
30 $mail_obj =
new ilMail(ANONYMOUS_USER_ID);
31 $mail_obj->enableSOAP(
false);
32 while(
$row = $ilDB->fetchAssoc(
$res))
35 if(
$row[
'pos_usr_id'] !=
$row[
'user_id'])
38 if(
$row[
'pos_usr_id'])
42 else if(strlen(
$row[
'pos_usr_alias']))
44 $row[
'pos_usr_name'] =
$row[
'pos_usr_alias'].
' ('.$lng->txt(
'frm_pseudonym').
')';
47 if(
$row[
'pos_usr_name'] ==
'')
49 $row[
'pos_usr_name'] = $lng->txt(
'forums_anonymous');
53 if(!isset($cache[
$row[
'obj_id']]))
57 $has_attachments =
false;
58 if(!isset($attachments_cache[$row[
'obj_id']][$row[
'pos_pk']]))
61 $filesOfPost = $fileDataForum->getFilesOfPost();
62 foreach($filesOfPost as $attachment)
64 $attachments_cache[$row[
'obj_id']][$row[
'pos_pk']][] = $attachment[
'name'];
65 $has_attachments =
true;
70 $has_attachments =
true;
75 foreach((array)$cache[$row[
'obj_id']] as
$ref_id)
77 if($ilAccess->checkAccessOfUser($row[
'user_id'],
'read',
'', $ref_id))
84 $attached_files = array();
85 if($has_attachments ==
true)
87 $attached_files = $attachments_cache[$row[
'obj_id']][$row[
'pos_pk']];
95 $frm->formatNotificationSubject($row),
96 $frm->formatNotification($row, 1, $attached_files, $row[
'user_id']),
112 $lng->loadLanguageModule(
'forum');
114 if(!($lastDate = $ilSetting->get(
'cron_forum_notification_last_date')))
120 $datecondition_frm =
'';
124 if($lastDate != null &&
125 checkDate(date(
'm', strtotime($lastDate)), date(
'd', strtotime($lastDate)), date(
'Y', strtotime($lastDate))))
127 $datecondition_frm =
' frm_posts.pos_date >= %s AND ';
128 $types[] =
'timestamp';
129 $values[] = $lastDate;
133 $res = $ilDB->queryf(
'
134 SELECT frm_threads.thr_subject thr_subject,
135 frm_data.top_name top_name,
136 frm_data.top_frm_fk obj_id,
137 frm_notification.user_id user_id,
139 FROM frm_notification, frm_posts, frm_threads, frm_data
140 WHERE '.$datecondition_frm.
' frm_posts.pos_thr_fk = frm_threads.thr_pk
141 AND frm_threads.thr_top_fk = frm_data.top_pk
142 AND frm_data.top_frm_fk = frm_notification.frm_id
143 ORDER BY frm_posts.pos_date ASC',
151 $res = $ilDB->queryf(
'
152 SELECT frm_threads.thr_subject thr_subject,
153 frm_data.top_name top_name,
154 frm_data.top_frm_fk obj_id,
155 frm_notification.user_id user_id,
157 FROM frm_notification, frm_posts, frm_threads, frm_data
158 WHERE '.$datecondition_frm.
' frm_posts.pos_thr_fk = frm_threads.thr_pk
159 AND frm_threads.thr_pk = frm_notification.thread_id
160 AND frm_data.top_pk = frm_threads.thr_top_fk
161 ORDER BY frm_posts.pos_date ASC',
168 $ilSetting->set(
'cron_forum_notification_last_date', date(
'Y-m-d H:i:s'));
170 $ilLog->write(__METHOD__.
': Send '.$numRows.
' messages.');