4 * @file classes/submission/form/comment/EditCommentForm.inc.php
6 * Copyright (c) 2003-2008 John Willinsky
7 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
9 * @class EditCommentForm
10 * @ingroup submission_form
12 * @brief Edit comment form.
15 // $Id: EditCommentForm.inc.php,v 1.5 2009/06/09 23:37:14 tylerl Exp $
20 class EditCommentForm
extends Form
{
22 /** @var object the monograph */
25 /** @var MonographComment the comment */
28 /** @var int the role of the comment author */
31 /** @var User the user */
36 * @param $monograph object
37 * @param $comment object
39 function EditCommentForm(&$monograph, &$comment) {
40 parent
::Form('submission/comment/editComment.tpl');
41 $this->addCheck(new FormValidatorPost($this));
43 $this->comment
= $comment;
44 $this->roleId
= $comment->getRoleId();
46 $this->monograph
= $monograph;
47 $this->user
=& Request
::getUser();
51 * Initialize form data from current comment.
54 $comment =& $this->comment
;
56 'commentId' => $comment->getCommentId(),
57 'commentTitle' => $comment->getCommentTitle(),
58 'comments' => $comment->getComments(),
59 'viewable' => $comment->getViewable(),
66 function display($additionalHiddenParams = null) {
67 $hiddenFormParams = array(
68 'monographId' => $this->monograph
->getMonographId(),
69 'commentId' => $this->comment
->getCommentId()
71 if (isset($additionalHiddenParams)) {
72 $hiddenFormParams = array_merge ($hiddenFormParams, $additionalHiddenParams);
75 $templateMgr =& TemplateManager
::getManager();
77 $isPeerReviewComment = $this->comment
->getCommentType() == COMMENT_TYPE_PEER_REVIEW
;
78 $templateMgr->assign('isPeerReviewComment', $isPeerReviewComment); // FIXME
79 $templateMgr->assign_by_ref('comment', $this->comment
);
80 $templateMgr->assign_by_ref('hiddenFormParams', $hiddenFormParams);
86 * Assign form data to user-submitted data.
88 function readInputData() {
102 $commentDao =& DAORegistry
::getDAO('MonographCommentDAO');
105 $comment = $this->comment
;
106 $comment->setCommentTitle($this->getData('commentTitle'));
107 $comment->setComments($this->getData('comments'));
108 $comment->setViewable($this->getData('viewable') ?
1 : 0);
109 $comment->setDateModified(Core
::getCurrentDate());
111 $commentDao->updateMonographComment($comment);
115 * UGLEEE function that gets the recipients for a comment.
116 * @return $recipients array of recipients (email address => name)
118 function emailHelper() {
119 $roleDao =& DAORegistry
::getDAO('RoleDAO');
120 $userDao =& DAORegistry
::getDAO('UserDAO');
121 $press =& Request
::getPress();
123 $recipients = array();
125 // Get editors for monograph
126 $editAssignmentDao =& DAORegistry
::getDAO('EditAssignmentDAO');
127 $editAssignments =& $editAssignmentDao->getByIdsByMonographId($this->monograph
->getMonographId());
128 $editAssignments =& $editAssignments->toArray();
129 $editorAddresses = array();
130 foreach ($editAssignments as $editAssignment) {
131 $editorAddresses[$editAssignment->getEditorEmail()] = $editAssignment->getEditorFullName();
134 // If no editors are currently assigned, send this message to
135 // all of the press's editors.
136 if (empty($editorAddresses)) {
137 $editors =& $roleDao->getUsersByRoleId(ROLE_ID_EDITOR
, $press->getId());
138 while (!$editors->eof()) {
139 $editor =& $editors->next();
140 $editorAddresses[$editor->getEmail()] = $editor->getFullName();
145 $proofAssignmentDao =& DAORegistry
::getDAO('ProofAssignmentDAO');
146 $proofAssignment =& $proofAssignmentDao->getProofAssignmentByMonographId($this->monograph
->getMonographId());
147 if ($proofAssignment != null && $proofAssignment->getProofreaderId() > 0) {
148 $proofreader =& $userDao->getUser($proofAssignment->getProofreaderId());
154 $layoutAssignmentDao =& DAORegistry
::getDAO('LayoutAssignmentDAO');
155 $layoutAssignment =& $layoutAssignmentDao->getLayoutAssignmentByMonographId($this->monograph
->getMonographId());
156 if ($layoutAssignment != null && $layoutAssignment->getEditorId() > 0) {
157 $layoutEditor =& $userDao->getUser($layoutAssignment->getEditorId());
159 $layoutEditor = null;
163 $copyAssignmentDao =& DAORegistry
::getDAO('CopyAssignmentDAO');
164 $copyAssignment =& $copyAssignmentDao->getCopyAssignmentByMonographId($this->monograph
->getMonographId());
165 if ($copyAssignment != null && $copyAssignment->getCopyeditorId() > 0) {
166 $copyeditor =& $userDao->getUser($copyAssignment->getCopyeditorId());
172 $reviewAssignmentDao =& DAORegistry
::getDAO('ReviewAssignmentDAO');
173 $reviewAssignment =& $reviewAssignmentDao->getById($this->comment
->getAssocId());
174 if ($reviewAssignment != null && $reviewAssignment->getReviewerId() != null) {
175 $reviewer =& $userDao->getUser($reviewAssignment->getReviewerId());
181 $author =& $userDao->getUser($this->monograph
->getUserId());
183 switch ($this->comment
->getCommentType()) {
184 case COMMENT_TYPE_PEER_REVIEW
:
185 if ($this->roleId
== ROLE_ID_EDITOR ||
$this->roleId
== ROLE_ID_ACQUISITIONS_EDITOR
) {
187 if ($reviewer != null) {
188 $recipients = array_merge($recipients, array($reviewer->getEmail() => $reviewer->getFullName()));
193 case COMMENT_TYPE_EDITOR_DECISION
:
194 if ($this->roleId
== ROLE_ID_EDITOR ||
$this->roleId
== ROLE_ID_ACQUISITIONS_EDITOR
) {
196 if (isset($author)) $recipients = array_merge($recipients, array($author->getEmail() => $author->getFullName()));
199 $recipients = array_merge($recipients, $editorAddresses);
203 case COMMENT_TYPE_COPYEDIT
:
204 if ($this->roleId
== ROLE_ID_EDITOR ||
$this->roleId
== ROLE_ID_ACQUISITIONS_EDITOR
) {
205 // Then add copyeditor and author
206 if ($copyeditor != null) {
207 $recipients = array_merge($recipients, array($copyeditor->getEmail() => $copyeditor->getFullName()));
210 $recipients = array_merge($recipients, array($author->getEmail() => $author->getFullName()));
212 } else if ($this->roleId
== ROLE_ID_COPYEDITOR
) {
213 // Then add editors and author
214 $recipients = array_merge($recipients, $editorAddresses);
216 if (isset($author)) $recipients = array_merge($recipients, array($author->getEmail() => $author->getFullName()));
219 // Then add editors and copyeditor
220 $recipients = array_merge($recipients, $editorAddresses);
222 if ($copyeditor != null) {
223 $recipients = array_merge($recipients, array($copyeditor->getEmail() => $copyeditor->getFullName()));
227 case COMMENT_TYPE_LAYOUT
:
228 if ($this->roleId
== ROLE_ID_EDITOR ||
$this->roleId
== ROLE_ID_ACQUISITIONS_EDITOR
) {
229 // Then add layout editor
231 // Check to ensure that there is a layout editor assigned to this monograph.
232 if ($layoutEditor != null) {
233 $recipients = array_merge($recipients, array($layoutEditor->getEmail() => $layoutEditor->getFullName()));
237 $recipients = array_merge($recipients, $editorAddresses);
240 case COMMENT_TYPE_PROOFREAD
:
241 if ($this->roleId
== ROLE_ID_EDITOR ||
$this->roleId
== ROLE_ID_ACQUISITIONS_EDITOR
) {
242 // Then add layout editor, proofreader and author
243 if ($layoutEditor != null) {
244 $recipients = array_merge($recipients, array($layoutEditor->getEmail() => $layoutEditor->getFullName()));
247 if ($proofreader != null) {
248 $recipients = array_merge($recipients, array($proofreader->getEmail() => $proofreader->getFullName()));
251 if (isset($author)) $recipients = array_merge($recipients, array($author->getEmail() => $author->getFullName()));
253 } else if ($this->roleId
== ROLE_ID_LAYOUT_EDITOR
) {
254 // Then add editors, proofreader and author
255 $recipients = array_merge($recipients, $editorAddresses);
257 if ($proofreader != null) {
258 $recipients = array_merge($recipients, array($proofreader->getEmail() => $proofreader->getFullName()));
261 if (isset($author)) $recipients = array_merge($recipients, array($author->getEmail() => $author->getFullName()));
263 } else if ($this->roleId
== ROLE_ID_PROOFREADER
) {
264 // Then add editors, layout editor, and author
265 $recipients = array_merge($recipients, $editorAddresses);
267 if ($layoutEditor != null) {
268 $recipients = array_merge($recipients, array($layoutEditor->getEmail() => $layoutEditor->getFullName()));
271 if (isset($author)) $recipients = array_merge($recipients, array($author->getEmail() => $author->getFullName()));
274 // Then add editors, layout editor, and proofreader
275 $recipients = array_merge($recipients, $editorAddresses);
277 if ($layoutEditor != null) {
278 $recipients = array_merge($recipients, array($layoutEditor->getEmail() => $layoutEditor->getFullName()));
281 if ($proofreader != null) {
282 $recipients = array_merge($recipients, array($proofreader->getEmail() => $proofreader->getFullName()));
293 * @param $recipients array of recipients (email address => name)
295 function email($recipients) {
296 import('mail.MonographMailTemplate');
297 $email = new MonographMailTemplate($this->monograph
, 'SUBMISSION_COMMENT');
298 $press =& Request
::getPress();
299 if ($press) $email->setFrom($press->getSetting('contactEmail'), $press->getSetting('contactName'));
301 foreach ($recipients as $emailAddress => $name) {
302 $email->addRecipient($emailAddress, $name);
303 $email->setSubject(strip_tags($this->monograph
->getMonographTitle()));
307 'commentName' => $this->user
->getFullName(),
308 'comments' => $this->getData('comments')
310 $email->assignParams($paramArray);
313 $email->clearRecipients();