2016-12-22 20:00:08 +08:00
|
|
|
module MainHelper
|
2016-12-22 20:05:38 +08:00
|
|
|
|
|
|
|
def read_newest_post offset_num
|
|
|
|
micro_posts_array = []
|
|
|
|
micro_posts = MicroPost.all.order(post_time: :desc).limit(20).offset(offset_num)
|
|
|
|
if !micro_posts.empty?
|
|
|
|
micro_posts.each do |micro_post|
|
|
|
|
x = Hash.new()
|
|
|
|
x["username"] = micro_post.user.name
|
|
|
|
x["userpic"] = micro_post.user.picurl
|
|
|
|
x["postid"] = micro_post.id
|
|
|
|
x["title"] = micro_post.title
|
|
|
|
x["content"] = micro_post.content
|
|
|
|
case micro_post.post_type
|
|
|
|
when 1
|
|
|
|
x["type"] = "新鲜事"
|
|
|
|
when 2
|
|
|
|
x["type"] = "组团信息"
|
|
|
|
when 3
|
|
|
|
x["type"] = "失物招领"
|
|
|
|
else
|
|
|
|
x["type"] = "新鲜事"
|
|
|
|
end
|
2016-12-27 10:46:28 +08:00
|
|
|
x["time"] = get_strftime(micro_post.post_time)
|
2016-12-26 14:24:20 +08:00
|
|
|
x["pics"] = micro_post.pic.split(',') if micro_post.pic
|
2016-12-22 20:05:38 +08:00
|
|
|
x["peo_num"] = micro_post.engage_people
|
|
|
|
micro_posts_array << x
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return micro_posts_array
|
|
|
|
end
|
2016-12-26 15:36:00 +08:00
|
|
|
|
|
|
|
def get_post posts
|
|
|
|
micro_posts_array = []
|
|
|
|
if !posts.empty?
|
|
|
|
posts.each do |micro_post|
|
|
|
|
x = Hash.new()
|
|
|
|
x["username"] = micro_post.user.name
|
|
|
|
x["userpic"] = micro_post.user.picurl
|
|
|
|
x["postid"] = micro_post.id
|
|
|
|
x["title"] = micro_post.title
|
|
|
|
x["content"] = micro_post.content
|
|
|
|
case micro_post.post_type
|
|
|
|
when 1
|
|
|
|
x["type"] = "新鲜事"
|
|
|
|
when 2
|
|
|
|
x["type"] = "组团信息"
|
|
|
|
when 3
|
|
|
|
x["type"] = "失物招领"
|
|
|
|
else
|
|
|
|
x["type"] = "新鲜事"
|
|
|
|
end
|
2016-12-27 10:46:28 +08:00
|
|
|
x["time"] = get_strftime(micro_post.post_time)
|
2016-12-26 15:36:00 +08:00
|
|
|
x["pics"] = micro_post.pic.split(',') if micro_post.pic
|
|
|
|
x["peo_num"] = micro_post.engage_people
|
|
|
|
micro_posts_array << x
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return micro_posts_array
|
|
|
|
end
|
|
|
|
|
2016-12-27 11:53:07 +08:00
|
|
|
def get_engaged_people micropost_id
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2016-12-22 20:00:08 +08:00
|
|
|
end
|