00001 <?php
00002
00016
00017
00018
00019 import('form.Form');
00020
00021 class CommentForm extends Form {
00022
00024 var $commentType;
00025
00027 var $roleId;
00028
00030 var $article;
00031
00033 var $user;
00034
00036 var $commentId;
00037
00042 function CommentForm($article, $commentType, $roleId, $assocId = null) {
00043 if ($commentType == COMMENT_TYPE_PEER_REVIEW) {
00044 parent::Form('submission/comment/peerReviewComment.tpl');
00045 } else if ($commentType == COMMENT_TYPE_EDITOR_DECISION) {
00046 parent::Form('submission/comment/editorDecisionComment.tpl');
00047 } else {
00048 parent::Form('submission/comment/comment.tpl');
00049 }
00050
00051 $this->article = $article;
00052 $this->commentType = $commentType;
00053 $this->roleId = $roleId;
00054 $this->assocId = $assocId == null ? $article->getArticleId() : $assocId;
00055
00056 $this->user = &Request::getUser();
00057
00058 if ($commentType != COMMENT_TYPE_PEER_REVIEW) $this->addCheck(new FormValidator($this, 'comments', 'required', 'editor.article.commentsRequired'));
00059 $this->addCheck(new FormValidatorPost($this));
00060 }
00061
00066 function setUser(&$user) {
00067 $this->user =& $user;
00068 }
00069
00073 function display() {
00074 $article = $this->article;
00075
00076 $articleCommentDao = &DAORegistry::getDAO('ArticleCommentDAO');
00077 $articleComments = &$articleCommentDao->getArticleComments($article->getArticleId(), $this->commentType, $this->assocId);
00078
00079 $templateMgr = &TemplateManager::getManager();
00080 $templateMgr->assign('articleId', $article->getArticleId());
00081 $templateMgr->assign('commentTitle', strip_tags($article->getArticleTitle()));
00082 $templateMgr->assign('userId', $this->user->getUserId());
00083 $templateMgr->assign('articleComments', $articleComments);
00084
00085 parent::display();
00086 }
00087
00091 function readInputData() {
00092 $this->readUserVars(
00093 array(
00094 'commentTitle',
00095 'comments',
00096 'viewable'
00097 )
00098 );
00099 }
00100
00104 function execute() {
00105 $commentDao = &DAORegistry::getDAO('ArticleCommentDAO');
00106 $article = $this->article;
00107
00108
00109 $comment = &new ArticleComment();
00110 $comment->setCommentType($this->commentType);
00111 $comment->setRoleId($this->roleId);
00112 $comment->setArticleId($article->getArticleId());
00113 $comment->setAssocId($this->assocId);
00114 $comment->setAuthorId($this->user->getUserId());
00115 $comment->setCommentTitle($this->getData('commentTitle'));
00116 $comment->setComments($this->getData('comments'));
00117 $comment->setDatePosted(Core::getCurrentDate());
00118 $comment->setViewable($this->getData('viewable'));
00119
00120 $this->commentId = $commentDao->insertArticleComment($comment);
00121 }
00122
00127 function email($recipients) {
00128 $article = $this->article;
00129 $articleCommentDao = &DAORegistry::getDAO('ArticleCommentDAO');
00130 $journal = &Request::getJournal();
00131
00132 import('mail.ArticleMailTemplate');
00133 $email = &new ArticleMailTemplate($article, 'SUBMISSION_COMMENT');
00134 $email->setFrom($this->user->getEmail(), $this->user->getFullName());
00135
00136 $commentText = $this->getData('comments');
00137
00138
00139 foreach ($recipients as $emailAddress => $name) {
00140 $email->addRecipient($emailAddress, $name);
00141
00142 $paramArray = array(
00143 'name' => $name,
00144 'commentName' => $this->user->getFullName(),
00145 'comments' => $commentText
00146 );
00147
00148 $email->sendWithParams($paramArray);
00149 $email->clearRecipients();
00150 }
00151 }
00152 }
00153
00154 ?>