00001 <?php
00002
00016
00017
00018
00019 import('rt.ocs.RTDAO');
00020 import('rt.ocs.ConferenceRT');
00021 import('handler.Handler');
00022
00023 class CommentHandler extends Handler {
00025 var $paper;
00026
00030 function CommentHandler() {
00031 parent::Handler();
00032
00033 $this->addCheck(new HandlerValidatorConference($this));
00034 $this->addCheck(new HandlerValidatorSchedConf($this));
00035 }
00036
00037 function view($args) {
00038 $paperId = isset($args[0]) ? (int) $args[0] : 0;
00039 $galleyId = isset($args[1]) ? (int) $args[1] : 0;
00040 $commentId = isset($args[2]) ? (int) $args[2] : 0;
00041
00042 $this->validate($paperId);
00043 $conference =& Request::getConference();
00044 $schedConf =& Request::getSchedConf();
00045 $paper =& $this->paper;
00046
00047 $user =& Request::getUser();
00048 $userId = isset($user)?$user->getId():null;
00049
00050 $commentDao =& DAORegistry::getDAO('CommentDAO');
00051 $comment =& $commentDao->getComment($commentId, $paperId, 2);
00052
00053 $roleDao =& DAORegistry::getDAO('RoleDAO');
00054 $isManager = Validation::isConferenceManager($conference->getId());
00055
00056 if (!$comment) $comments =& $commentDao->getRootCommentsByPaperId($paperId, 1);
00057 else $comments =& $comment->getChildren();
00058
00059 $this->setupTemplate($paper, $galleyId, $comment);
00060
00061 $templateMgr =& TemplateManager::getManager();
00062 if (Request::getUserVar('refresh')) $templateMgr->setCacheability(CACHEABILITY_NO_CACHE);
00063 if ($comment) {
00064 $templateMgr->assign_by_ref('comment', $comment);
00065 $templateMgr->assign_by_ref('parent', $commentDao->getComment($comment->getParentCommentId(), $paperId));
00066 }
00067 $templateMgr->assign_by_ref('comments', $comments);
00068 $templateMgr->assign('paperId', $paperId);
00069 $templateMgr->assign('galleyId', $galleyId);
00070 $templateMgr->assign('enableComments', $conference->getSetting('enableComments'));
00071 $templateMgr->assign('commentsRequireRegistration', $conference->getSetting('commentsRequireRegistration'));
00072 $templateMgr->assign('commentsAllowAnonymous', $conference->getSetting('commentsAllowAnonymous'));
00073
00074 $closeCommentsDate = $schedConf->getSetting('closeCommentsDate');
00075 $commentsClosed = $schedConf->getSetting('closeComments')?true:false && (strtotime($closeCommentsDate < time()));
00076
00077 $templateMgr->assign('closeCommentsDate', $closeCommentsDate);
00078 $templateMgr->assign('commentsClosed', $commentsClosed);
00079 $templateMgr->assign('isManager', $isManager);
00080
00081 $templateMgr->display('comment/comments.tpl');
00082 }
00083
00084 function add($args) {
00085 $paperId = isset($args[0]) ? (int) $args[0] : 0;
00086 $galleyId = isset($args[1]) ? (int) $args[1] : 0;
00087 $parentId = isset($args[2]) ? (int) $args[2] : 0;
00088
00089 $conference =& Request::getConference();
00090 $schedConf =& Request::getSchedConf();
00091 $this->validate($paperId);
00092 $paper =& $this->paper;
00093
00094 $commentDao =& DAORegistry::getDAO('CommentDAO');
00095 $parent =& $commentDao->getComment($parentId, $paperId);
00096 if (isset($parent) && $parent->getPaperId() != $paperId) {
00097 Request::redirect(null, null, null, 'view', array($paperId, $galleyId));
00098 }
00099
00100 $this->setupTemplate($paper, $galleyId, $parent);
00101
00102
00103 $commentDao =& DAORegistry::getDAO('CommentDAO');
00104
00105 $enableComments = $conference->getSetting('enableComments');
00106 $commentsRequireRegistration = $conference->getSetting('commentsRequireRegistration');
00107 $commentsAllowAnonymous = $conference->getSetting('commentsAllowAnonymous');
00108
00109 $closeCommentsDate = $schedConf->getSetting('closeCommentsDate');
00110 $commentsClosed = $schedConf->getSetting('closeComments')?true:false && (strtotime($closeCommentsDate < time()));
00111
00112 $enableComments = $enableComments && !$commentsClosed && $paper->getEnableComments();
00113
00114 if (!$enableComments) Request::redirect(null, null, 'index');
00115 if ($commentsRequireRegistration && !Request::getUser()) Validation::redirectLogin();
00116
00117 import('comment.form.CommentForm');
00118 $commentForm = new CommentForm(null, $paperId, $galleyId, isset($parent)?$parentId:null);
00119 $commentForm->initData();
00120
00121 if (isset($args[3]) && $args[3]=='save') {
00122 $commentForm->readInputData();
00123 if ($commentForm->validate()) {
00124 $commentForm->execute();
00125
00126
00127 import('notification.NotificationManager');
00128 $notificationManager = new NotificationManager();
00129 $paperDAO =& DAORegistry::getDAO('PaperDAO');
00130 $paper =& $paperDAO->getPaper($paperId);
00131 $notificationUsers = $paper->getAssociatedUserIds();
00132 foreach ($notificationUsers as $userRole) {
00133 $url = Request::url(null, null, null, 'view', array($paperId, $galleyId, $parentId));
00134 $notificationManager->createNotification(
00135 $userRole['id'], 'notification.type.userComment',
00136 $paper->getLocalizedTitle(), $url, 1, NOTIFICATION_TYPE_USER_COMMENT
00137 );
00138 }
00139
00140 Request::redirect(null, null, null, 'view', array($paperId, $galleyId, $parentId), array('refresh' => 1));
00141 }
00142 }
00143
00144 $commentForm->display();
00145 }
00146
00150 function delete($args) {
00151 $paperId = isset($args[0]) ? (int) $args[0] : 0;
00152 $galleyId = isset($args[1]) ? (int) $args[1] : 0;
00153 $commentId = isset($args[2]) ? (int) $args[2] : 0;
00154
00155 $this->validate($paperId);
00156 $user =& Request::getUser();
00157 $userId = isset($user)?$user->getId():null;
00158
00159 $commentDao =& DAORegistry::getDAO('CommentDAO');
00160
00161 if (!Validation::isConferenceManager()) {
00162 Request::redirect(null, null, 'index');
00163 }
00164
00165 $comment =& $commentDao->getComment($commentId, $paperId, PAPER_COMMENT_RECURSE_ALL);
00166 if ($comment)$commentDao->deleteComment($comment);
00167
00168 Request::redirect(null, null, null, 'view', array($paperId, $galleyId), array('refresh' => 1));
00169 }
00170
00174 function validate($paperId) {
00175 parent::validate();
00176 $conference =& Request::getConference();
00177 $schedConf =& Request::getSchedConf();
00178
00179 $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
00180 $paper =& $publishedPaperDao->getPublishedPaperByPaperId($paperId, $schedConf->getId(), $schedConf->getSetting('previewAbstracts'));
00181 $this->paper =& $paper;
00182
00183 if ($paper == null) {
00184 Request::redirect(null, null, 'index');
00185 }
00186
00187
00188 $commentDao =& DAORegistry::getDAO('CommentDAO');
00189 $enableComments = $conference->getSetting('enableComments');
00190
00191 if (!$enableComments || !$paper->getEnableComments()) {
00192 Request::redirect(null, null, 'index');
00193 }
00194
00195 $restrictPaperAccess = $conference->getSetting('restrictPaperAccess');
00196
00197 if ($restrictPaperAccess && !Validation::isLoggedIn()) {
00198 Validation::redirectLogin();
00199 }
00200
00201 return true;
00202 }
00203
00204 function setupTemplate($paper, $galleyId, $comment = null) {
00205 parent::setupTemplate();
00206 $templateMgr =& TemplateManager::getManager();
00207 $templateMgr->setCacheability(CACHEABILITY_PUBLIC);
00208 AppLocale::requireComponents(array(LOCALE_COMPONENT_PKP_READER));
00209
00210 $pageHierarchy = array(
00211 array(
00212 Request::url(null, null, 'paper', 'view', array(
00213 $paper->getBestPaperId(Request::getConference()), $galleyId
00214 )),
00215 String::stripUnsafeHtml($paper->getLocalizedTitle()),
00216 true
00217 )
00218 );
00219
00220 if ($comment) $pageHierarchy[] = array(Request::url(null, null, 'comment', 'view', array($paper->getId(), $galleyId)), 'comments.readerComments');
00221 $templateMgr->assign('pageHierarchy', $pageHierarchy);
00222 }
00223 }
00224
00225 ?>