protected function handle_submit()
 {
     $form = $this->get_form();
     CommentsManager::edit_comment($this->id_comment, $form->get_value('message'));
     AppContext::get_response()->redirect(CommentsUrlBuilder::comment_added($this->topic_path, $this->id_comment));
 }
    private function build_view($request)
    {
        $template = new FileTemplate('framework/content/comments/comments_list.tpl');
        $page = $request->get_getint('page', 1);
        $id_module = $this->module === null ? null : $this->module->get_id();
        $pagination = $this->get_pagination($page);
        $this->tpl->put_all(array('C_PAGINATION' => $pagination->has_several_pages(), 'PAGINATION' => $pagination->display()));
        $result = PersistenceContext::get_querier()->select('
			SELECT comments.*, comments.timestamp AS comment_timestamp, comments.id AS id_comment,
			topic.*,
			member.user_id, member.display_name, member.level, member.groups,
			ext_field.user_avatar
			FROM ' . DB_TABLE_COMMENTS . ' comments
			LEFT JOIN ' . DB_TABLE_COMMENTS_TOPIC . ' topic ON comments.id_topic = topic.id_topic
			LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = comments.user_id
			LEFT JOIN ' . DB_TABLE_MEMBER_EXTENDED_FIELDS . ' ext_field ON ext_field.user_id = comments.user_id
			' . $this->build_where_request() . '
			ORDER BY comments.timestamp DESC
			LIMIT :number_items_per_page OFFSET :display_from', array('number_items_per_page' => $pagination->get_number_items_per_page(), 'display_from' => $pagination->get_display_from()));
        $user_accounts_config = UserAccountsConfig::load();
        $comments_authorizations = new CommentsAuthorizations();
        $number_comment = 0;
        while ($row = $result->fetch()) {
            $id = $row['id_comment'];
            $path = $row['path'];
            //Avatar
            $user_avatar = !empty($row['user_avatar']) ? Url::to_rel($row['user_avatar']) : ($user_accounts_config->is_default_avatar_enabled() ? Url::to_rel('/templates/' . AppContext::get_current_user()->get_theme() . '/images/' . $user_accounts_config->get_default_avatar_name()) : '');
            $timestamp = new Date($row['comment_timestamp'], Timezone::SERVER_TIMEZONE);
            $group_color = User::get_group_color($row['groups'], $row['level']);
            $template->assign_block_vars('comments', array('C_MODERATOR' => $comments_authorizations->is_authorized_moderation(), 'C_VISITOR' => empty($row['login']), 'C_VIEW_TOPIC' => true, 'C_GROUP_COLOR' => !empty($group_color), 'C_AVATAR' => $row['user_avatar'] || $user_accounts_config->is_default_avatar_enabled(), 'U_TOPIC' => Url::to_rel($path), 'U_EDIT' => CommentsUrlBuilder::edit($path, $id)->rel(), 'U_DELETE' => CommentsUrlBuilder::delete($path, $id)->rel(), 'U_PROFILE' => UserUrlBuilder::profile($row['user_id'])->rel(), 'U_AVATAR' => $user_avatar, 'ID_COMMENT' => $id, 'DATE' => $timestamp->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE), 'DATE_ISO8601' => $timestamp->format(Date::FORMAT_ISO8601), 'MESSAGE' => FormatingHelper::second_parse($row['message']), 'USER_ID' => $row['user_id'], 'PSEUDO' => empty($row['login']) ? $row['pseudo'] : $row['login'], 'LEVEL_CLASS' => UserService::get_level_class($row['level']), 'GROUP_COLOR' => $group_color, 'L_LEVEL' => UserService::get_level_lang($row['level'] !== null ? $row['level'] : '-1')));
            $template->put_all(array('MODULE_ID' => $row['module_id'], 'ID_IN_MODULE' => $row['id_in_module'], 'L_VIEW_TOPIC' => $this->lang['view-topic']));
            $number_comment++;
        }
        $result->dispose();
        $this->tpl->put('C_NO_COMMENT', $number_comment == 0);
        $comments_tpl = new FileTemplate('framework/content/comments/comments.tpl');
        $comments_tpl->put_all(array('COMMENTS_LIST' => $template, 'MODULE_ID' => $row['module_id'], 'ID_IN_MODULE' => $row['id_in_module']));
        return $comments_tpl;
    }
 protected function handle_submit()
 {
     $form = $this->get_form();
     if ($form->has_field('name')) {
         $id_comment = CommentsManager::add_comment($this->module_id, $this->id_in_module, $this->topic_identifier, $this->topic_path, $form->get_value('message'), $form->get_value('name'));
     } else {
         $id_comment = CommentsManager::add_comment($this->module_id, $this->id_in_module, $this->topic_identifier, $this->topic_path, $form->get_value('message'));
     }
     $this->comments_topic->get_events()->execute_add_comment_event();
     AppContext::get_response()->redirect(CommentsUrlBuilder::comment_added($this->topic_path, $id_comment));
 }
Пример #4
0
 /**
  * @desc Do not use, this is used for ajax display comments
  * @param string $module_id the module identifier
  * @param integer $id_in_module id in module used in comments system
  * @param string $topic_identifier topic identifier (use if you have several comments system)
  * @return object View is a view
  */
 public static function display_comments($module_id, $id_in_module, $topic_identifier, $number_comments_display, $authorizations, $display_from_number_comments = false)
 {
     $template = new FileTemplate('framework/content/comments/comments_list.tpl');
     if ($authorizations->is_authorized_read() && $authorizations->is_authorized_access_module()) {
         $user_accounts_config = UserAccountsConfig::load();
         $condition = !$display_from_number_comments ? ' LIMIT ' . $number_comments_display : ' LIMIT ' . $number_comments_display . ',18446744073709551615';
         $result = PersistenceContext::get_querier()->select("\n\t\t\t\tSELECT comments.*, comments.timestamp AS comment_timestamp, comments.id AS id_comment,\n\t\t\t\ttopic.is_locked, topic.path,\n\t\t\t\tmember.user_id, member.display_name, member.level, member.groups, \n\t\t\t\text_field.user_avatar\n\t\t\t\tFROM " . DB_TABLE_COMMENTS . " comments\n\t\t\t\tLEFT JOIN " . DB_TABLE_COMMENTS_TOPIC . " topic ON comments.id_topic = topic.id_topic\n\t\t\t\tLEFT JOIN " . DB_TABLE_MEMBER . " member ON member.user_id = comments.user_id\n\t\t\t\tLEFT JOIN " . DB_TABLE_MEMBER_EXTENDED_FIELDS . " ext_field ON ext_field.user_id = comments.user_id\n\t\t\t\tWHERE topic.module_id = '" . $module_id . "' AND topic.id_in_module = '" . $id_in_module . "' AND topic.topic_identifier = '" . $topic_identifier . "'\n\t\t\t\tORDER BY comments.timestamp " . CommentsConfig::load()->get_order_display_comments() . " " . $condition);
         while ($row = $result->fetch()) {
             $id = $row['id_comment'];
             $path = $row['path'];
             //Avatar
             $user_avatar = !empty($row['user_avatar']) ? Url::to_rel($row['user_avatar']) : ($user_accounts_config->is_default_avatar_enabled() ? Url::to_rel('/templates/' . AppContext::get_current_user()->get_theme() . '/images/' . $user_accounts_config->get_default_avatar_name()) : '');
             $timestamp = new Date($row['comment_timestamp'], Timezone::SERVER_TIMEZONE);
             $group_color = User::get_group_color($row['groups'], $row['level']);
             $template->assign_block_vars('comments', array('C_MODERATOR' => self::is_authorized_edit_or_delete_comment($authorizations, $id), 'C_VISITOR' => empty($row['display_name']), 'C_GROUP_COLOR' => !empty($group_color), 'C_AVATAR' => $row['user_avatar'] || $user_accounts_config->is_default_avatar_enabled(), 'U_EDIT' => CommentsUrlBuilder::edit($path, $id)->rel(), 'U_DELETE' => CommentsUrlBuilder::delete($path, $id)->rel(), 'U_PROFILE' => UserUrlBuilder::profile($row['user_id'])->rel(), 'U_AVATAR' => $user_avatar, 'ID_COMMENT' => $id, 'DATE' => $timestamp->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE), 'DATE_ISO8601' => $timestamp->format(Date::FORMAT_ISO8601), 'MESSAGE' => FormatingHelper::second_parse($row['message']), 'USER_ID' => $row['user_id'], 'PSEUDO' => empty($row['display_name']) ? $row['pseudo'] : $row['display_name'], 'LEVEL_CLASS' => UserService::get_level_class($row['level']), 'GROUP_COLOR' => $group_color, 'L_LEVEL' => UserService::get_level_lang($row['level'] !== null ? $row['level'] : '-1')));
             $template->put_all(array('L_UPDATE' => self::$common_lang['edit'], 'L_DELETE' => self::$common_lang['delete']));
         }
         $result->dispose();
     }
     self::$template->put_all(array('MODULE_ID' => $module_id, 'ID_IN_MODULE' => $id_in_module, 'TOPIC_IDENTIFIER' => $topic_identifier));
     return $template;
 }