|
|
|
@ -154,12 +154,7 @@ class WechatsController < ActionController::Base
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### controller method
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module Controllers
|
|
|
|
|
def get_open_id
|
|
|
|
|
begin
|
|
|
|
@ -228,37 +223,19 @@ class WechatsController < ActionController::Base
|
|
|
|
|
uw = UserWechat.where(openid: openid).first
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def user_activity(user)
|
|
|
|
|
@user = user
|
|
|
|
|
shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id)
|
|
|
|
|
shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id)
|
|
|
|
|
@page = params[:page] ? params[:page].to_i + 1 : 0
|
|
|
|
|
user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")"
|
|
|
|
|
user_course_ids = (@user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")"
|
|
|
|
|
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
|
|
|
|
|
project_types = "('Message','Issue','Project')"
|
|
|
|
|
principal_types = "JournalsForMessage"
|
|
|
|
|
|
|
|
|
|
blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")"
|
|
|
|
|
@user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
|
|
|
|
|
"or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
|
|
|
|
|
"or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " +
|
|
|
|
|
"or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def user_activities
|
|
|
|
|
session[:wechat_code] = params[:code] if params[:code]
|
|
|
|
|
code = params[:code] || session[:wechat_code]
|
|
|
|
|
openid = get_openid_from_code(code)
|
|
|
|
|
@wechat_user = user_binded?(openid)
|
|
|
|
|
unless @wechat_user
|
|
|
|
|
redirect_to :login
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def process_activity(user_activity)
|
|
|
|
|
act= user_activity.act
|
|
|
|
|
case user_activity.container_type.to_s
|
|
|
|
|
when 'Course'
|
|
|
|
|
when 'Project'
|
|
|
|
|
case user_activity.act_type.to_s
|
|
|
|
|
when 'Issue'
|
|
|
|
|
[act.project.name.to_s+" | 项目问题", act.subject.to_s, url_to_avatar(act.author),"http://wechat.trustie.net/app.html#/issue/#{act.id}"]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
render File.join(Rails.root, "public/wechat/app.html"), layout: nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|