function ajaxSaveComment_POST(Web $w) { $p = $w->pathMatch('parent_id'); $comment = new Comment($w); $comment->obj_table = "comment"; $comment->obj_id = $p['parent_id']; $comment->comment = strip_tags($w->request('comment')); $comment->insert(); $w->setLayout(null); echo $w->partial("displaycomment", array("object" => $comment, 'redirect' => $w->request('redirect')), "admin"); }
/** * Hook to notify relevant people when a task has been updated * * @param Web $w * @param Task $object */ function task_comment_comment_added_comment(Web $w, $object) { $w->Log->setLogger("TASK")->debug("task_comment_comment_added_comment"); // Check if the parent comment is attached to a task $comment = $object; while (strtolower($comment->obj_table) == "comment" && $comment->obj_id != NULL) { $comment = $w->Comment->getComment($comment->obj_id); // Check if the comment could not be found if (empty($comment->id)) { $w->Log->setLogger("TASK")->debug("Comment not found"); return; } } // We only want task comments! if (strtolower($comment->obj_table) != "task") { $w->Log->setLogger("TASK")->debug("Comment parent not a task"); return; } $task = $w->Task->getTask($comment->obj_id); if (empty($task->id)) { $w->Log->setLogger("TASK")->debug("Task not found"); return; } $users_to_notify = $w->Task->getNotifyUsersForTask($task, TASK_NOTIFICATION_TASK_COMMENTS); if (!in_array($task->assignee_id, $users_to_notify)) { $users_to_notify[$task->assignee_id] = $task->assignee_id; } // Add all users in comment thread to the notification $reply_comment = $object; $comment_thread_users = array(); while (strtolower($reply_comment->obj_table) == "comment" && $comment->obj_id != NULL) { if (!in_array($reply_comment->creator_id, $users_to_notify)) { $comment_thread_users[$reply_comment->creator_id] = $reply_comment->creator_id; } $reply_comment = $w->Comment->getComment($comment->obj_id); // Check if the comment could not be found if (empty($comment->id)) { return; } } $users_to_notify = array_merge($comment_thread_users, $users_to_notify); $comment_user = $w->Auth->getUser($object->creator_id); if (!empty($users_to_notify)) { $event_title = $object->getHumanReadableAttributeName(TASK_NOTIFICATION_TASK_COMMENTS); // send it to the inbox of the user's on our send list foreach ($users_to_notify as $user) { // prepare our message, add heading, add URL to task, add notification advice in messgae footer $subject = $comment_user->getFullName() . " replied to a comment " . (in_array($w->Auth->user()->id, $comment_thread_users) ? "that you're a part of " : "") . "for " . $task->title; $message = "<p>Comment</p>"; $message .= $w->partial("displaycomment", array("object" => $object, "displayOnly" => true, 'redirect' => '/inbox'), "admin"); $user_object = $w->Auth->getUser($user); if ($task->canView($user_object)) { $message .= "<a href='/task/edit/" . $task->id . "?scroll_comment_id=" . $object->id . "#comments'><p>Click here to view the comment</p></a>"; } else { $message .= "<p><b>You are unable to view this task</b></p>"; } $message .= "<br/><br/><b>Note</b>: Go to " . Html::a(WEBROOT . "/task/tasklist#notifications", "Task > Task List > Notifications") . ", to edit the types of notifications you will receive."; $w->Inbox->addMessage($subject, $message, $user, null, null, true); } } }