article = $article; $this->commentType = $commentType; $this->roleId = $roleId; $this->assocId = $assocId == null ? $article->getId() : $assocId; $this->user =& Request::getUser(); if ($commentType != COMMENT_TYPE_PEER_REVIEW) $this->addCheck(new FormValidator($this, 'comments', 'required', 'editor.article.commentsRequired')); $this->addCheck(new FormValidatorPost($this)); } /** * Set the user this comment form is associated with. * @param $user object */ function setUser(&$user) { $this->user =& $user; } /** * Display the form. */ function display() { $article = $this->article; $articleCommentDao =& DAORegistry::getDAO('ArticleCommentDAO'); $articleComments =& $articleCommentDao->getArticleComments($article->getId(), $this->commentType, $this->assocId); $templateMgr =& TemplateManager::getManager(); $templateMgr->assign('articleId', $article->getId()); $templateMgr->assign('commentTitle', strip_tags($article->getLocalizedTitle())); $user =& $this->user; $templateMgr->assign('userId', $user->getId()); $templateMgr->assign('articleComments', $articleComments); parent::display(); } /** * Assign form data to user-submitted data. */ function readInputData() { $this->readUserVars( array( 'commentTitle', 'comments', 'viewable' ) ); } /** * Add the comment. */ function execute() { $commentDao =& DAORegistry::getDAO('ArticleCommentDAO'); $article = $this->article; // Insert new comment $comment = new ArticleComment(); $comment->setCommentType($this->commentType); $comment->setRoleId($this->roleId); $comment->setArticleId($article->getId()); $comment->setAssocId($this->assocId); $comment->setAuthorId($this->user->getId()); $comment->setCommentTitle($this->getData('commentTitle')); $comment->setComments($this->getData('comments')); $comment->setDatePosted(Core::getCurrentDate()); $comment->setViewable($this->getData('viewable')); $this->commentId = $commentDao->insertArticleComment($comment); } /** * Email the comment. * @param $recipients array of recipients (email address => name) */ function email($recipients, $request) { $article = $this->article; $articleCommentDao =& DAORegistry::getDAO('ArticleCommentDAO'); $journal =& Request::getJournal(); import('classes.mail.ArticleMailTemplate'); $email = new ArticleMailTemplate($article, 'SUBMISSION_COMMENT'); $email->setReplyTo($this->user->getEmail(), $this->user->getFullName()); $commentText = $this->getData('comments'); // Individually send an email to each of the recipients. foreach ($recipients as $emailAddress => $name) { $email->addRecipient($emailAddress, $name); $paramArray = array( 'name' => $name, 'commentName' => $this->user->getFullName(), 'comments' => String::html2text($commentText) ); $email->sendWithParams($paramArray, $request); $email->clearRecipients(); } } } ?>