Sha256: 95632b7aaa6cb7432d8e7655477e36168344dd22adf4146a59ca43e97a9d43a4

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

require_dependency "my_forum/application_controller"

module MyForum
  class WelcomeController < ApplicationController
    def index
      @forum_categories = if current_user && current_user.is_admin?
                            Category.includes(:forums)
                          else
                            @forum_categories = Category.includes(:forums, :user_groups).
                              reject{|category| (category.user_groups.map(&:name) & (current_user_groups)).blank? }
                          end


      # Don`r forget permissions
      available_forum_ids = MyForum::Forum.where(category_id: @forum_categories.map(&:id)).pluck(:id)
      @recent_posts = if available_forum_ids.blank?
                        []
                      else
                        Topic.find_by_sql("
                          SELECT posts.id, posts.user_id, posts.text, posts.topic_id, posts.updated_at, topics.name as topic_name, topics.forum_id FROM my_forum_posts AS posts
                          LEFT JOIN my_forum_topics AS topics ON posts.topic_id = topics.id
                          LEFT JOIN my_forum_forums AS forums ON forums.id = topics.forum_id
                          WHERE posts.id IN (SELECT MAX(id) FROM my_forum_posts GROUP BY topic_id)
                          ORDER BY posts.id DESC LIMIT 10
                        ")
                      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
my_forum-0.0.1.beta22 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.1.beta21 app/controllers/my_forum/welcome_controller.rb