/** * Check if user may contribute at all and may edit posting (if given) * * @param int $a_posting_id * @param int $a_author_id * @return boolean */ protected function mayContribute($a_posting_id = null, $a_author_id = null) { global $ilUser; // single author blog (owner) in personal workspace if ($this->id_type == self::WORKSPACE_NODE_ID) { return $this->checkPermissionBool("write"); } if ($this->checkPermissionBool("contribute")) { // check owner of posting if ($a_posting_id) { if (!$a_author_id) { include_once "Modules/Blog/classes/class.ilBlogPosting.php"; $post = new ilBlogPosting($a_posting_id); $a_author_id = $post->getAuthor(); } if ($ilUser->getId() == $a_author_id) { return true; } else { return false; } } return true; } return false; }
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); } }