Sha256: ed0479c707d001ae7fc1b6830ad3a55349286ce64160faa94b8df5587d6c5053

Contents?: true

Size: 1.49 KB

Versions: 28

Compression:

Stored size: 1.49 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, topics.deleted 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) AND posts.is_deleted IS FALSE AND topics.deleted IS FALSE AND forums.id IN (#{available_forum_ids.join(',')})
                          ORDER BY posts.id DESC LIMIT 10
                        ")
                      end

    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
my_forum-0.0.2.4 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.2.3 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.2.2 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.2.1 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.2 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.1.beta60 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.1.beta59 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.1.beta58 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.1.beta57 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.1.beta56 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.1.beta55 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.1.beta54 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.1.beta53 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.1.beta52 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.1.beta51 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.1.beta50 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.1.beta49 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.1.beta48 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.1.beta47 app/controllers/my_forum/welcome_controller.rb
my_forum-0.0.1.beta46 app/controllers/my_forum/welcome_controller.rb