|
|
|
@ -2,9 +2,13 @@
|
|
|
|
|
class ForumsController < ApplicationController
|
|
|
|
|
# GET /forums
|
|
|
|
|
# GET /forums.json
|
|
|
|
|
before_filter :find_forum_if_available
|
|
|
|
|
before_filter :authenticate_user_edit, :only => [:edit, :update]
|
|
|
|
|
before_filter :authenticate_user_destroy, :only => [:destroy]
|
|
|
|
|
|
|
|
|
|
helper :sort
|
|
|
|
|
include SortHelper
|
|
|
|
|
|
|
|
|
|
PageLimit = 20
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
@ -26,15 +30,33 @@ class ForumsController < ApplicationController
|
|
|
|
|
# GET /forums/1
|
|
|
|
|
# GET /forums/1.json
|
|
|
|
|
def show
|
|
|
|
|
@memo = Memo.new
|
|
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
|
|
|
|
@forum = Forum.find(params[:id])
|
|
|
|
|
@memos_all = @forum.topics
|
|
|
|
|
@topic_count = @memos_all.count
|
|
|
|
|
@topic_pages = Paginator.new @topic_count, @limit, params['page']
|
|
|
|
|
sort_init 'updated_at', 'desc'
|
|
|
|
|
sort_update 'created_at' => "#{Memo.table_name}.created_at",
|
|
|
|
|
'replies' => "#{Memo.table_name}.replies_count",
|
|
|
|
|
'updated_at' => "COALESCE (last_replies_memos.created_at, #{Memo.table_name}.created_at)"
|
|
|
|
|
|
|
|
|
|
@memo = Memo.new(:forum => @forum)
|
|
|
|
|
@topic_count = @forum.topics.count
|
|
|
|
|
@topic_pages = Paginator.new @topic_count, per_page_option, params['page']
|
|
|
|
|
@memos = @forum.topics.
|
|
|
|
|
reorder("#{Memo.table_name}.sticky DESC").
|
|
|
|
|
includes(:last_reply).
|
|
|
|
|
limit(@topic_pages.per_page).
|
|
|
|
|
offset(@topic_pages.offset).
|
|
|
|
|
order(sort_clause).
|
|
|
|
|
preload(:author, {:last_reply => :author}).
|
|
|
|
|
all
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# @offset, @limit = api_offset_and_limit({:limit => 10})
|
|
|
|
|
# @forum = Forum.find(params[:id])
|
|
|
|
|
# @memos_all = @forum.topics
|
|
|
|
|
# @topic_count = @memos_all.count
|
|
|
|
|
# @topic_pages = Paginator.new @topic_count, @limit, params['page']
|
|
|
|
|
|
|
|
|
|
@offset ||= @topic_pages.offset
|
|
|
|
|
@memos = @memos_all.offset(@offset).limit(@limit).all
|
|
|
|
|
# @offset ||= @topic_pages.offset
|
|
|
|
|
# @memos = @memos_all.offset(@offset).limit(@limit).all
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html {
|
|
|
|
|
render :layout => 'base_forums'
|
|
|
|
@ -144,20 +166,20 @@ class ForumsController < ApplicationController
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def find_forum
|
|
|
|
|
@forum = Forum.find(params[:id])
|
|
|
|
|
def find_forum_if_available
|
|
|
|
|
@forum = Forum.find(params[:id]) if params[:id]
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
|
render_404
|
|
|
|
|
nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def authenticate_user_edit
|
|
|
|
|
find_forum
|
|
|
|
|
find_forum_if_available
|
|
|
|
|
render_403 unless @forum.editable_by? User.current
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def authenticate_user_destroy
|
|
|
|
|
find_forum
|
|
|
|
|
find_forum_if_available
|
|
|
|
|
render_403 unless @forum.destroyable_by? User.current
|
|
|
|
|
end
|
|
|
|
|
end
|