protected function sendMails($res) { global $ilAccess, $ilDB, $lng; static $cache = array(); static $attachments_cache = array(); include_once 'Modules/Forum/classes/class.ilObjForum.php'; include_once 'Services/Mail/classes/class.ilMail.php'; include_once 'Services/User/classes/class.ilObjUser.php'; include_once 'Services/Language/classes/class.ilLanguage.php'; $forumObj = new ilObjForum(); $frm = $forumObj->Forum; $numRows = 0; $mail_obj = new ilMail(ANONYMOUS_USER_ID); $mail_obj->enableSOAP(false); while ($row = $ilDB->fetchAssoc($res)) { // don not send a notification to the post author if ($row['pos_display_user_id'] != $row['user_id']) { // GET AUTHOR OF NEW POST if ($row['pos_display_user_id']) { $row['pos_usr_name'] = ilObjUser::_lookupLogin($row['pos_display_user_id']); } else { if (strlen($row['pos_usr_alias'])) { $row['pos_usr_name'] = $row['pos_usr_alias'] . ' (' . $lng->txt('frm_pseudonym') . ')'; } } if ($row['pos_usr_name'] == '') { $row['pos_usr_name'] = $lng->txt('forums_anonymous'); } // get all references of obj_id if (!isset($cache[$row['obj_id']])) { $cache[$row['obj_id']] = ilObject::_getAllReferences($row['obj_id']); } // check for attachments $has_attachments = false; if (!isset($attachments_cache[$row['obj_id']][$row['pos_pk']])) { $fileDataForum = new ilFileDataForum($row['obj_id'], $row['pos_pk']); $filesOfPost = $fileDataForum->getFilesOfPost(); foreach ($filesOfPost as $attachment) { $attachments_cache[$row['obj_id']][$row['pos_pk']][] = $attachment['name']; $has_attachments = true; } } else { $has_attachments = true; } // do rbac check before sending notification $send_mail = false; foreach ((array) $cache[$row['obj_id']] as $ref_id) { if ($ilAccess->checkAccessOfUser($row['user_id'], 'read', '', $ref_id)) { $row['ref_id'] = $ref_id; $send_mail = true; break; } } $attached_files = array(); if ($has_attachments == true) { $attached_files = $attachments_cache[$row['obj_id']][$row['pos_pk']]; } if ($send_mail) { $frm->setLanguage(ilForum::_getLanguageInstanceByUsrId($row['user_id'])); $mail_obj->sendMail(ilObjUser::_lookupLogin($row['user_id']), '', '', $frm->formatNotificationSubject($row), $frm->formatNotification($row, 1, $attached_files, $row['user_id']), array(), array('normal')); $numRows++; } } } return $numRows; }