/** * @desc This function display the comments * @param class CommentsTopic $topic * @return Template is a template object */ public static function display(CommentsTopic $topic) { $module_id = $topic->get_module_id(); $id_in_module = $topic->get_id_in_module(); $topic_identifier = $topic->get_topic_identifier(); $authorizations = $topic->get_authorizations(); if (!$authorizations->is_authorized_read()) { self::$template->put('KEEP_MESSAGE', MessageHelper::display(self::$comments_lang['comments.not-authorized.read'], MessageHelper::NOTICE)); } else { $edit_comment_id = AppContext::get_request()->get_getint('edit_comment', 0); $delete_comment_id = AppContext::get_request()->get_getint('delete_comment', 0); try { $lock = AppContext::get_request()->get_getbool('lock'); if ($authorizations->is_authorized_moderation()) { if ($lock) { if (!CommentsTopicDAO::topic_exists($module_id, $id_in_module, $topic_identifier)) { CommentsTopicDAO::create_topic($module_id, $id_in_module, $topic_identifier, $topic->get_path()); } CommentsManager::lock_topic($module_id, $id_in_module, $topic_identifier); } else { CommentsManager::unlock_topic($module_id, $id_in_module, $topic_identifier); } } AppContext::get_response()->redirect($topic->get_path()); } catch (UnexistingHTTPParameterException $e) { } if (!empty($delete_comment_id)) { self::verificate_authorized_edit_or_delete_comment($authorizations, $delete_comment_id); CommentsManager::delete_comment($delete_comment_id); AppContext::get_response()->redirect($topic->get_path()); } elseif (!empty($edit_comment_id)) { self::verificate_authorized_edit_or_delete_comment($authorizations, $edit_comment_id); $edit_comment_form = EditCommentBuildForm::create($edit_comment_id, $topic->get_path()); self::$template->put_all(array('C_DISPLAY_FORM' => true, 'COMMENT_FORM' => $edit_comment_form->display())); } else { if ($authorizations->is_authorized_post() && $authorizations->is_authorized_access_module()) { $comments_topic_locked = CommentsManager::comment_topic_locked($module_id, $id_in_module, $topic_identifier); $user_read_only = self::$user->get_delay_readonly(); if (!$authorizations->is_authorized_moderation() && $comments_topic_locked) { self::$template->put('KEEP_MESSAGE', MessageHelper::display(self::$comments_lang['comment.locked'], MessageHelper::NOTICE)); } elseif (!empty($user_read_only) && $user_read_only > time()) { self::$template->put('KEEP_MESSAGE', MessageHelper::display(self::$comments_lang['comments.user.read-only'], MessageHelper::NOTICE)); } else { $add_comment_form = AddCommentBuildForm::create($topic); self::$template->put_all(array('C_DISPLAY_FORM' => true, 'COMMENT_FORM' => $add_comment_form->display())); } } else { self::$template->put('KEEP_MESSAGE', MessageHelper::display(self::$comments_lang['comments.not-authorized.post'], MessageHelper::NOTICE)); } } $number_comments_display = $topic->get_number_comments_display(); $number_comments = self::$comments_cache->get_count_comments_by_module($module_id, $id_in_module, $topic_identifier); self::$template->put_all(array('COMMENTS_LIST' => self::display_comments($module_id, $id_in_module, $topic_identifier, $number_comments_display, $authorizations), 'MODULE_ID' => $module_id, 'ID_IN_MODULE' => $id_in_module, 'TOPIC_IDENTIFIER' => $topic_identifier, 'C_DISPLAY_VIEW_ALL_COMMENTS' => $number_comments > $number_comments_display, 'C_MODERATE' => $authorizations->is_authorized_moderation(), 'C_IS_LOCKED' => CommentsManager::comment_topic_locked($module_id, $id_in_module, $topic_identifier), 'U_LOCK' => CommentsUrlBuilder::lock_and_unlock($topic->get_path(), true)->rel(), 'U_UNLOCK' => CommentsUrlBuilder::lock_and_unlock($topic->get_path(), false)->rel())); } return self::$template; }
public static function comment_topic_locked($module_id, $id_in_module, $topic_identifier) { if (CommentsTopicDAO::topic_exists($module_id, $id_in_module, $topic_identifier)) { return CommentsTopicDAO::comments_topic_locked($module_id, $id_in_module, $topic_identifier); } return false; }