# encoding: utf-8 module Mobile module Entities class Activity 0 lc = ac.act.student_works.has_committed.reorder("commit_time desc").first {:lasttime=>time_from_now(lc.commit_time), :lastname=>lc.user.show_name} end end when :last_score_info if ac.act_type == "HomeworkCommon" if ac.act.student_works.has_committed.count > 0 sw_id = "("+ac.act.student_works.map{|sw| sw.id}.join(",")+")" student_work_scores = StudentWorksScore.where("student_work_id in #{sw_id} and score is not null").reorder("created_at desc") unless student_work_scores.empty? last_score = student_work_scores.first {:lasttime=>time_from_now(last_score.created_at), :lastname=>last_score.user.show_name} end end end end end end end end expose :act_type #缺陷/作业/讨论区/留言等类型 expose :act_id expose :id expose :container_type #课程/项目/博客/个人 expose :author, using: Mobile::Entities::User do |a, opt| #用户信息 if a.is_a? ::UserActivity if a.act_type == "Project" get_user(get_project(a.act_id).user_id) elsif !a.act.nil? if a.act_type == 'Issue' || a.act_type == 'News' || a.act_type == 'Message' || a.act_type == 'BlogComment' a.act.author elsif a.act_type == 'HomeworkCommon' || a.act_type == 'Poll' || a.act_type == 'JournalsForMessage' a.act.user elsif a.act_type == 'Course' a.act.teacher end end end end expose :homework_common_detail , using: Mobile::Entities::Whomework do |a, opt| #作业相关信息 if a.act_type == "HomeworkCommon" a.act end end expose :issue_detail, using: Mobile::Entities::Issue do |a, opt| #缺陷信息 if a.act_type == "Issue" a.act end end act_expose :reply_count #回复数 act_expose :praise_count #点赞数 #act_expose :user_act #某个动态 act_expose :subject #标题 act_expose :description #描述 act_expose :latest_update #最新更新时间 act_expose :course_project_id #课程/项目ID act_expose :course_project_name #课程/项目名字 act_expose :syllabus_title #课程名字 act_expose :activity_type_name #课程问答区/项目缺陷等 act_expose :homework_commit_count #作品提交数 act_expose :last_commit_info #最近提交信息 act_expose :last_score_info #最近评阅信息 expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| if instance.act_type == "HomeworkCommon" || instance.act_type == "News" || instance.act_type == "Message" || instance.act_type == "BlogComment" || instance.act_type == "JournalsForMessage" || instance.act_type == "Issue" has_praise = false current_user = options[:user] obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.act_id,instance.act_type.to_s,current_user.id) has_praise = obj.empty? ? false : true has_praise end end end end end