static function sendNotification($a_action, $a_in_wsp, $a_blog_node_id, $a_posting_id, $a_comment = null)
 {
     global $ilUser, $ilAccess;
     // get blog object id (repository or workspace)
     if ($a_in_wsp) {
         include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
         include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
         $tree = new ilWorkspaceTree($ilUser->getId());
         // owner of tree is irrelevant
         $blog_obj_id = $tree->lookupObjectId($a_blog_node_id);
         $access_handler = new ilWorkspaceAccessHandler($tree);
         $link = ilWorkspaceAccessHandler::getGotoLink($a_blog_node_id, $blog_obj_id, "_" . $a_posting_id);
     } else {
         $blog_obj_id = ilObject::_lookupObjId($a_blog_node_id);
         $access_handler = null;
         include_once "Services/Link/classes/class.ilLink.php";
         $link = ilLink::_getStaticLink($a_blog_node_id, "blog", true, "_" . $a_posting_id);
     }
     if (!$blog_obj_id) {
         return;
     }
     include_once "./Modules/Blog/classes/class.ilBlogPosting.php";
     $posting = new ilBlogPosting($a_posting_id);
     // #11138
     $ignore_threshold = $a_action == "comment";
     // approval handling
     $admin_only = false;
     if (!$posting->isApproved()) {
         $blog = new self($blog_obj_id, false);
         if ($blog->hasApproval()) {
             switch ($a_action) {
                 case "update":
                     // un-approved posting was updated - no notifications
                     return;
                 case "new":
                     // un-approved posting was activated - admin-only notification
                     $admin_only = true;
                     $ignore_threshold = true;
                     break;
             }
         }
     }
     // recipients
     include_once "./Services/Notification/classes/class.ilNotification.php";
     $users = ilNotification::getNotificationsForObject(ilNotification::TYPE_BLOG, $blog_obj_id, $a_posting_id, $ignore_threshold);
     if (!sizeof($users)) {
         return;
     }
     // send mails
     include_once "./Services/Mail/classes/class.ilMail.php";
     include_once "./Services/User/classes/class.ilObjUser.php";
     include_once "./Services/Language/classes/class.ilLanguageFactory.php";
     include_once "./Services/User/classes/class.ilUserUtil.php";
     $posting_title = $posting->getTitle();
     $blog_title = ilObject::_lookupTitle($blog_obj_id);
     $author = $posting->getAuthor();
     $notified = array();
     foreach (array_unique($users) as $idx => $user_id) {
         // the user responsible for the action should not be notified
         if ($user_id == $ilUser->getId()) {
             continue;
         }
         // workspace
         if ($access_handler) {
             if ($admin_only && !$access_handler->checkAccessOfUser($tree, $user_id, 'write', '', $a_blog_node_id)) {
                 continue;
             }
             if (!$access_handler->checkAccessOfUser($tree, $user_id, 'read', '', $a_blog_node_id)) {
                 continue;
             }
         } else {
             if ($admin_only && !$ilAccess->checkAccessOfUser($user_id, 'write', '', $a_blog_node_id)) {
                 continue;
             }
             if (!$ilAccess->checkAccessOfUser($user_id, 'read', '', $a_blog_node_id)) {
                 continue;
             }
         }
         // use language of recipient to compose message
         $ulng = ilLanguageFactory::_getLanguageOfUser($user_id);
         $ulng->loadLanguageModule('blog');
         $subject = sprintf($ulng->txt('blog_change_notification_subject'), $blog_title);
         $message = sprintf($ulng->txt('blog_change_notification_salutation'), ilObjUser::_lookupFullname($user_id)) . "\n\n";
         $message .= $ulng->txt('blog_change_notification_body_' . $a_action) . ":\n\n";
         $message .= $ulng->txt('obj_blog') . ": " . $blog_title . "\n";
         $message .= $ulng->txt('blog_posting') . ": " . $posting_title . "\n";
         $message .= $ulng->txt('blog_changed_by') . ": " . ilUserUtil::getNamePresentation($ilUser->getId()) . "\n";
         if ($a_comment) {
             $message .= "\n" . $ulng->txt('comment') . ":\n\"" . trim($a_comment) . "\"\n";
         }
         $message .= "\n" . $ulng->txt('blog_change_notification_link') . ": " . $link;
         $mail_obj = new ilMail(ANONYMOUS_USER_ID);
         $mail_obj->appendInstallationSignature(true);
         $mail_obj->sendMail(ilObjUser::_lookupLogin($user_id), "", "", $subject, $message, array(), array("system"));
         $notified[] = $user_id;
     }
     if (sizeof($notified)) {
         ilNotification::updateNotificationTime(ilNotification::TYPE_BLOG, $blog_obj_id, $notified);
     }
 }
Example #2
0
 static function sendNotification($a_action, $a_in_wsp, $a_blog_node_id, $a_posting_id, $a_comment = null)
 {
     global $ilUser;
     // get blog object id (repository or workspace)
     if ($a_in_wsp) {
         include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
         include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
         $tree = new ilWorkspaceTree($ilUser->getId());
         // owner of tree is irrelevant
         $blog_obj_id = $tree->lookupObjectId($a_blog_node_id);
         $access_handler = new ilWorkspaceAccessHandler($tree);
     } else {
         $blog_obj_id = ilObject::_lookupObjId($a_blog_node_id);
         $access_handler = null;
     }
     if (!$blog_obj_id) {
         return;
     }
     include_once "./Modules/Blog/classes/class.ilBlogPosting.php";
     $posting = new ilBlogPosting($a_posting_id);
     // #11138
     $ignore_threshold = $a_action == "comment";
     // approval handling
     $admin_only = false;
     if (!$posting->isApproved()) {
         $blog = new self($blog_obj_id, false);
         if ($blog->hasApproval()) {
             switch ($a_action) {
                 case "update":
                     // un-approved posting was updated - no notifications
                     return;
                 case "new":
                     // un-approved posting was activated - admin-only notification
                     $admin_only = true;
                     $ignore_threshold = true;
                     break;
             }
         }
     }
     // recipients
     include_once "./Services/Notification/classes/class.ilNotification.php";
     $users = ilNotification::getNotificationsForObject(ilNotification::TYPE_BLOG, $blog_obj_id, $a_posting_id, $ignore_threshold);
     if (!sizeof($users)) {
         return;
     }
     include_once "./Services/Notification/classes/class.ilSystemNotification.php";
     $ntf = new ilSystemNotification($a_in_wsp);
     $ntf->setLangModules(array("blog"));
     $ntf->setRefId($a_blog_node_id);
     $ntf->setChangedByUserId($ilUser->getId());
     $ntf->setSubjectLangId('blog_change_notification_subject');
     $ntf->setIntroductionLangId('blog_change_notification_body_' . $a_action);
     $ntf->addAdditionalInfo('blog_posting', $posting->getTitle());
     if ($a_comment) {
         $ntf->addAdditionalInfo('comment', $a_comment, true);
     }
     $ntf->setGotoLangId('blog_change_notification_link');
     $ntf->setReasonLangId('blog_change_notification_reason');
     $notified = $ntf->sendMail($users, "_" . $a_posting_id, $admin_only ? "write" : "read");
     ilNotification::updateNotificationTime(ilNotification::TYPE_BLOG, $blog_obj_id, $notified);
 }