Пример #1
0
 /**
  * Add a comment
  * @param $args array
  * @param $request Request
  */
 function add($args, $request)
 {
     $articleId = isset($args[0]) ? (int) $args[0] : 0;
     $galleyId = isset($args[1]) ? (int) $args[1] : 0;
     $parentId = isset($args[2]) ? (int) $args[2] : 0;
     $journal =& $request->getJournal();
     $commentDao =& DAORegistry::getDAO('CommentDAO');
     $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
     $publishedArticle =& $publishedArticleDao->getPublishedArticleByArticleId($articleId);
     $parent =& $commentDao->getById($parentId, $articleId);
     if (isset($parent) && $parent->getSubmissionId() != $articleId) {
         $request->redirect(null, null, 'view', array($articleId, $galleyId));
     }
     $this->validate($request, $articleId);
     $this->setupTemplate($request, $publishedArticle, $galleyId, $parent);
     // Bring in comment constants
     $enableComments = $journal->getSetting('enableComments');
     switch ($enableComments) {
         case COMMENTS_UNAUTHENTICATED:
             break;
         case COMMENTS_AUTHENTICATED:
         case COMMENTS_ANONYMOUS:
             // The user must be logged in to post comments.
             if (!$request->getUser()) {
                 Validation::redirectLogin();
             }
             break;
         default:
             // Comments are disabled.
             Validation::redirectLogin();
     }
     import('classes.comment.form.CommentForm');
     $commentForm = new CommentForm(null, $articleId, $galleyId, isset($parent) ? $parentId : null);
     $commentForm->initData();
     if (isset($args[3]) && $args[3] == 'save') {
         $commentForm->readInputData();
         if ($commentForm->validate()) {
             $commentForm->execute();
             // Send a notification to associated users
             import('classes.notification.NotificationManager');
             $notificationManager = new NotificationManager();
             $articleDao =& DAORegistry::getDAO('ArticleDAO');
             $article =& $articleDao->getArticle($articleId);
             $notificationUsers = $article->getAssociatedUserIds();
             foreach ($notificationUsers as $userRole) {
                 $notificationManager->createNotification($request, $userRole['id'], NOTIFICATION_TYPE_USER_COMMENT, $article->getJournalId(), ASSOC_TYPE_ARTICLE, $article->getId());
             }
             $request->redirect(null, null, 'view', array($articleId, $galleyId, $parentId), array('refresh' => 1));
         }
     }
     $commentForm->display();
 }
Пример #2
0
 function add($args)
 {
     $paperId = isset($args[0]) ? (int) $args[0] : 0;
     $galleyId = isset($args[1]) ? (int) $args[1] : 0;
     $parentId = isset($args[2]) ? (int) $args[2] : 0;
     $conference =& Request::getConference();
     $schedConf =& Request::getSchedConf();
     $this->validate($paperId);
     $paper =& $this->paper;
     $parent =& $commentDao->getComment($parentId, $paperId);
     if (isset($parent) && $parent->getPaperId() != $paperId) {
         Request::redirect(null, null, null, 'view', array($paperId, $galleyId));
     }
     $this->setupTemplate($paper, $galleyId, $parent);
     // Bring in comment constants
     $commentDao =& DAORegistry::getDAO('CommentDAO');
     $enableComments = $conference->getSetting('enableComments');
     $commentsRequireRegistration = $conference->getSetting('commentsRequireRegistration');
     $commentsAllowAnonymous = $conference->getSetting('commentsAllowAnonymous');
     $closeCommentsDate = $schedConf->getSetting('closeCommentsDate');
     $commentsClosed = $schedConf->getSetting('closeComments') ? true : false && strtotime($closeCommentsDate < time());
     $enableComments = $enableComments && !$commentsClosed && $paper->getEnableComments();
     if (!$enableComments) {
         Request::redirect(null, null, 'index');
     }
     if ($commentsRequireRegistration && !Request::getUser()) {
         Validation::redirectLogin();
     }
     import('comment.form.CommentForm');
     $commentForm = new CommentForm(null, $paperId, $galleyId, isset($parent) ? $parentId : null);
     $commentForm->initData();
     if (isset($args[3]) && $args[3] == 'save') {
         $commentForm->readInputData();
         if ($commentForm->validate()) {
             $commentForm->execute();
             // Send a notification to associated users
             import('notification.Notification');
             $paperDAO =& DAORegistry::getDAO('PaperDAO');
             $paper =& $paperDAO->getPaper($paperId);
             $notificationUsers = $paper->getAssociatedUserIds();
             foreach ($notificationUsers as $userRole) {
                 $url = Request::url(null, null, null, 'view', array($paperId, $galleyId, $parentId));
                 Notification::createNotification($userRole['id'], "notification.type.userComment", $paper->getLocalizedTitle(), $url, 1, NOTIFICATION_TYPE_USER_COMMENT);
             }
             Request::redirect(null, null, null, 'view', array($paperId, $galleyId, $parentId), array('refresh' => 1));
         }
     }
     $commentForm->display();
 }