修改微信获取课程大纲的代码
This commit is contained in:
parent
e06f09406c
commit
85b3df889c
|
@ -28,9 +28,10 @@ module Mobile
|
|||
ss = SyllabusesService.new
|
||||
|
||||
sy = ::Syllabus.find(params[:id])
|
||||
sy.courses = sy.courses.not_deleted
|
||||
|
||||
present :data, sy, with: Mobile::Entities::Syllabus,user: current_user
|
||||
result = {:title=>sy.title, :id=>sy.id , :user_id=>sy.user_id,:courses=>sy.courses.not_deleted}
|
||||
|
||||
present :data, result, with: Mobile::Entities::Syllabus,user: current_user
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ module Mobile
|
|||
expose :id
|
||||
expose :can_setting, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
current_user = options[:user]
|
||||
can_setting = instance.user_id == current_user.id ? true : false
|
||||
can_setting = false if instance.id.nil?
|
||||
can_setting = instance[:user_id] == current_user.id ? true : false
|
||||
can_setting = false if instance[:id].nil?
|
||||
can_setting
|
||||
end
|
||||
expose :courses, using: Mobile::Entities::Course
|
||||
|
|
|
@ -36,24 +36,21 @@ class SyllabusesService
|
|||
# courses.each do |c|
|
||||
# other.courses << c[:course] unless c[:course].syllabus
|
||||
# end
|
||||
result = []
|
||||
i = 0
|
||||
|
||||
courses = user.courses.not_deleted
|
||||
syllabus_ids = courses.empty? ? '(-1)' : "(" + courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")"
|
||||
syllabuses = Syllabus.where("id in #{syllabus_ids} or user_id = #{user.id}").order("updated_at desc")
|
||||
|
||||
syllabuses.each do |syllabus|
|
||||
syllabus.courses = courses.where("syllabus_id = #{syllabus.id}").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("time desc")
|
||||
tmp_courses = courses.where("syllabus_id = #{syllabus.id}").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc")
|
||||
result[i] = {:title=>syllabus.title, :id=>syllabus.id , :user_id=>syllabus.user_id,:courses=>tmp_courses }
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
# syllabuses.to_a << other
|
||||
|
||||
syllabuses.to_a
|
||||
#管理权限 can_setting
|
||||
# syllabuses.each do |s|
|
||||
# s = judge_can_setting(s,user)
|
||||
# end
|
||||
|
||||
syllabuses
|
||||
# syllabuses.to_a
|
||||
# syllabuses
|
||||
result
|
||||
end
|
||||
|
||||
def after_create_course(course, user)
|
||||
|
|
Loading…
Reference in New Issue