if ($message == '') { $json = array('error' => 'Your reply can not be blank.'); exit(json_encode($json)); } $discussion = Discussion::load($discussionID); $reply = new Discussion(array('creator_id' => Session::getUserID(), 'project_id' => $discussion->getProjectID(), 'parent_id' => $discussion->getID(), 'title' => $discussion->getTitle(), 'message' => $message, 'category' => $discussion->getCategory())); $reply->save(); // attach any uploads // Upload::attachToItem( // $token, // Upload::TYPE_DISCUSSION, // $reply->getID(), // $project->getID() // ); // log it $logEvent = new Event(array('event_type_id' => 'create_discussion_reply', 'project_id' => $discussion->getProjectID(), 'user_1_id' => Session::getUserID(), 'item_1_id' => $reply->getID(), 'item_2_id' => $discussion->getID(), 'data_1' => $message)); $logEvent->save(); // send email notification, if desired // discussion creator $creator = User::load($discussion->getCreatorID()); if ($creator->getID() != Session::getUserID()) { // don't email yourself if ($creator->getNotifyDiscussionStarted()) { // compose email $body = "<p>" . formatUserLink(Session::getUserID()) . ' replied to your discussion <a href="' . Url::discussion($discussionID) . '">' . $discussion->getTitle() . '</a> in the project ' . formatProjectLink($project->getID()) . '. The reply was:</p>'; $body .= "<blockquote>" . formatDiscussionReply($message) . "</blockquote>"; $email = array('to' => $creator->getEmail(), 'subject' => '[' . PIPELINE_NAME . '] New reply to your discussion in ' . $project->getTitle(), 'message' => $body); // send email Email::send($email); } }