This commit is contained in:
albert
2011-06-21 17:29:58 -04:00
parent 2f1fdcb459
commit 9ac7f85f0b
4 changed files with 44 additions and 31 deletions

View File

@@ -1,13 +1,20 @@
module PostSets
class Base
def has_wiki?
false
is_single_tag?
end
def wiki_page
nil
end
def has_artist?
is_single_tag?
end
def artist
end
def presenter
@presenter ||= PostSetPresenter.new(self)
end
@@ -16,10 +23,6 @@ module PostSets
false
end
def tag
tag_string
end
def arbitrary_sql_order_clause(ids, table_name)
if ids.empty?
return "#{table_name}.id desc"

View File

@@ -2,11 +2,11 @@ module PostSets
class Favorite < Base
attr_reader :user, :page, :favorites, :posts
def initialize(params)
@user = ::User.find(params[:id])
@page = [params[:page].to_i, 1].max
@favorites = ::Favorite.model_for(@user.id).for_user(@user.id).paginate(page)
@posts = ::Post.where("id in (?)", post_ids).order(arbitrary_sql_order_clause(post_ids, "posts")).paginate("a0")
def initialize(user_id, page)
@user = ::User.find(user_id)
@page = [page.to_i, 1].max
@favorites = ::Favorite.model_for(user.id).for_user(user.id).page(page)
@posts = ::Post.where("id in (?)", post_ids).order(arbitrary_sql_order_clause(post_ids, "posts")).page("b0")
end
def post_ids
@@ -17,8 +17,12 @@ module PostSets
(page - 1) * records_per_page
end
def tag_array
@tag_array ||= ["fav:#{user.name}"]
end
def tag_string
@tag_string ||= "fav:#{user.name}"
tag_array.join(" ")
end
end
end

View File

@@ -1,15 +1,15 @@
module PostSets
class Post < Base
attr_reader :tags, :page, :posts
attr_reader :tag_array, :page, :posts
def initialize(params)
@tags = Tag.scan_query(params[:tags])
@tag_array = Tag.scan_query(params[:tags])
@page = [params[:page].to_i, 1].max
@posts = ::Post.tag_match(tag_string).paginate(page)
end
def tag_string
@tag_string ||= tags.join(" ")
@tag_string ||= tag_array.join(" ")
end
def has_wiki?
@@ -29,7 +29,7 @@ module PostSets
end
def is_single_tag?
tags.size == 1
tag_array.size == 1
end
end
end