Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00034 class ilCronForumNotification
00035 {
00036 function ilCronForumNotification()
00037 {
00038 global $ilLog,$ilDB;
00039
00040 $this->log =& $ilLog;
00041 $this->db =& $ilDB;
00042 }
00043
00044 function sendNotifications()
00045 {
00046 global $ilias, $ilUser, $rbacsystem, $lng;
00047
00048 include_once "./classes/class.ilObjForum.php";
00049 include_once "./classes/class.ilMail.php";
00050 include_once "./classes/class.ilObjUser.php";
00051 include_once "./classes/class.ilLanguage.php";
00052
00053 $forumObj = new ilObjForum($_GET["ref_id"]);
00054 $frm =& $forumObj->Forum;
00055
00056 if(!($lastDate = $ilias->getSetting("cron_forum_notification_last_date")))
00057 {
00058 $lastDate = "0000-00-00 00:00:00";
00059 }
00060
00061 $q = "SELECT frm_threads.thr_subject AS thr_subject, frm_data.top_name AS top_name, frm_data.top_frm_fk AS obj_id, frm_notification.user_id AS user_id, frm_posts.* FROM frm_notification, frm_posts, frm_threads, frm_data WHERE ";
00062 $q .= "frm_posts.pos_date >= '" . $lastDate . "' AND ";
00063 $q .= "frm_posts.pos_thr_fk = frm_threads.thr_pk AND ";
00064 $q .= "frm_threads.thr_pk = frm_notification.thread_id AND ";
00065 $q .= "frm_data.top_pk >= frm_threads.thr_top_fk ";
00066 $q .= "ORDER BY frm_posts.pos_date ASC";
00067 $res = $this->db->query($q);
00068 if (!DB::isError($res) &&
00069 is_object($res) &&
00070 $res->numRows() > 0)
00071 {
00072 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
00073 {
00074 if ($row["pos_usr_id"] != $row["user_id"])
00075 {
00076
00077 $tmp_user =& new ilObjUser($row["pos_usr_id"]);
00078 $row["pos_usr_name"] = $tmp_user->getLogin();
00079
00080
00081 $tmp_user =& new ilObjUser($row["user_id"]);
00082
00083 if (is_array($obj_data = ilObject::_getAllReferences($row["obj_id"])))
00084 {
00085 foreach($obj_data as $ref_id)
00086 {
00087 if ($rbacsystem->checkAccessOfUser($row["user_id"], "read", $ref_id))
00088 {
00089 $row["ref_id"] = $ref_id;
00090 break;
00091 }
00092 }
00093 }
00094
00095 if ($row["ref_id"] != "")
00096 {
00097
00098 $lng =& new ilLanguage($tmp_user->getLanguage());
00099 $lng->loadLanguageModule("forum");
00100 $frm->setLanguage($lng);
00101 $tmp_mail_obj = new ilMail($row["pos_usr_id"]);
00102 $message = $tmp_mail_obj->sendMail($tmp_user->getLogin(),"","",
00103 $frm->formatNotificationSubject(),
00104 $frm->formatNotification($row, 1),
00105 array(),array("normal"));
00106 unset($tmp_mail_obj);
00107 }
00108
00109 unset($tmp_user);
00110 }
00111 }
00112 }
00113
00114 $ilias->setSetting("cron_forum_notification_last_date", date("Y-m-d H:i:s"));
00115
00116 return true;
00117 }
00118 }
00119 ?>