<input type="hidden" name="forward_url" value="<?php echo $forward_url; ?> "> <?php echo __('%create_comment or %cancel', array('%create_comment' => '<input type="submit" class="button button-green" value="' . __('Create comment') . '" />', '%cancel' => javascript_link_tag(__('cancel'), array('onclick' => "\$('comment_add').hide();\$('comment_add_button').show();")))); ?> </div> </form> </div> </div> <?php } ?> <div class="faded_out comments_none" id="comments_none" <?php if (\thebuggenie\core\entities\Comment::countComments($target_id, $target_type) != 0) { ?> style="display: none;"<?php } ?> ><?php echo __('There are no comments'); ?> </div> <div id="comments_box"> <?php foreach (\thebuggenie\core\entities\Comment::getComments($target_id, $target_type, \b2db\Criteria::SORT_DESC) as $comment) { ?> <?php $options = compact('comment', 'comment_count_div', 'mentionable_target_type'); if (isset($issue)) {
');"><?php echo __('Attach a file'); ?> </button> <?php } ?> </h4> <?php include_component('publish/attachments', array('article' => $article, 'attachments' => $attachments)); ?> </div> <div id="article_comments"> <h4> <?php echo __('Article comments (%count)', array('%count' => \thebuggenie\core\entities\Comment::countComments($article->getID(), \thebuggenie\core\entities\Comment::TYPE_ARTICLE))); ?> <?php if ($tbg_user->canPostComments() && (\thebuggenie\core\framework\Context::isProjectContext() && !\thebuggenie\core\framework\Context::getCurrentProject()->isArchived() || !\thebuggenie\core\framework\Context::isProjectContext())) { ?> <button id="comment_add_button" class="button button-silver" onclick="TBG.Main.Comment.showPost();"><?php echo __('Post comment'); ?> </button> <?php } ?> </h4> <?php include_component('main/comments', array('target_id' => $article->getID(), 'mentionable_target_type' => 'article', 'target_type' => \thebuggenie\core\entities\Comment::TYPE_ARTICLE, 'show_button' => false, 'comment_count_div' => 'article_comment_count', 'forward_url' => make_url('publish_article', array('article_name' => $article->getName())))); ?>
public function countUserComments() { if ($this->_num_user_comments === null) { $this->_num_user_comments = Comment::countComments($this->getID(), Comment::TYPE_ISSUE, false); } return (int) $this->_num_user_comments; }
public function runAddComment(framework\Request $request) { $i18n = framework\Context::getI18n(); $comment_applies_type = $request['comment_applies_type']; try { if (!$this->getUser()->canPostComments()) { throw new \Exception($i18n->__('You are not allowed to do this')); } if (!trim($request['comment_body'])) { throw new \Exception($i18n->__('The comment must have some content')); } $comment = new entities\Comment(); $comment->setContent($request->getParameter('comment_body', null, false)); $comment->setPostedBy($this->getUser()->getID()); $comment->setTargetID($request['comment_applies_id']); $comment->setTargetType($request['comment_applies_type']); $comment->setReplyToComment($request['reply_to_comment_id']); $comment->setModuleName($request['comment_module']); $comment->setIsPublic((bool) $request['comment_visibility']); $comment->setSyntax($request['comment_body_syntax']); $comment->save(); if ($comment_applies_type == entities\Comment::TYPE_ISSUE) { $issue = entities\Issue::getB2DBTable()->selectById((int) $request['comment_applies_id']); if (!$request->isAjaxCall() || $request['comment_save_changes']) { $issue->setSaveComment($comment); $issue->save(); } else { \thebuggenie\core\framework\Event::createNew('core', 'thebuggenie\\core\\entities\\Comment::createNew', $comment, compact('issue'))->trigger(); } } elseif ($comment_applies_type == entities\Comment::TYPE_ARTICLE) { $article = \thebuggenie\modules\publish\entities\tables\Articles::getTable()->selectById((int) $request['comment_applies_id']); \thebuggenie\core\framework\Event::createNew('core', 'thebuggenie\\core\\entities\\Comment::createNew', $comment, compact('article'))->trigger(); } switch ($comment_applies_type) { case entities\Comment::TYPE_ISSUE: $issue = entities\Issue::getB2DBTable()->selectById($request['comment_applies_id']); framework\Context::setCurrentProject($issue->getProject()); $comment_html = $this->getComponentHTML('main/comment', array('comment' => $comment, 'issue' => $issue, 'mentionable_target_type' => 'issue', 'comment_count_div' => 'viewissue_comment_count')); break; case entities\Comment::TYPE_ARTICLE: $comment_html = $this->getComponentHTML('main/comment', array('comment' => $comment, 'mentionable_target_type' => 'article', 'comment_count_div' => 'article_comment_count')); break; default: $comment_html = 'OH NO!'; } } catch (\Exception $e) { if ($request->isAjaxCall()) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => $e->getMessage())); } else { framework\Context::setMessage('comment_error', $e->getMessage()); framework\Context::setMessage('comment_error_body', $request['comment_body']); framework\Context::setMessage('comment_error_visibility', $request['comment_visibility']); } } if ($request->isAjaxCall()) { return $this->renderJSON(array('title' => $i18n->__('Comment added!'), 'comment_data' => $comment_html, 'continue_url' => $request['forward_url'], 'commentcount' => entities\Comment::countComments($request['comment_applies_id'], $request['comment_applies_type']))); } if (isset($comment) && $comment instanceof entities\Comment) { $this->forward($request['forward_url'] . "#comment_{$request['comment_applies_type']}_{$request['comment_applies_id']}_{$comment->getID()}"); } else { $this->forward($request['forward_url']); } }