|
|
|
@ -120,7 +120,7 @@ class CoursesService
|
|
|
|
|
if current_user.nil? || !(current_user.admin? || @course.is_public == 1 || (@course.is_public == 0 && current_user.member_of_course?(@course)))
|
|
|
|
|
raise '403'
|
|
|
|
|
end
|
|
|
|
|
scope = @course ? @course.news.course_visible(current_user) : News.course_visible(current_user)
|
|
|
|
|
scope = @course ? @course.news.order("news.created_on desc").course_visible(current_user) : News.order("news.created_on desc").course_visible(current_user)
|
|
|
|
|
news = []
|
|
|
|
|
scope.each do |n|
|
|
|
|
|
news << {:id => n.id,:title => n.title,:author_name => n.author.name,:author_id => n.author.id, :author=>n.author, :description => n.description,:created_on => format_time(n.created_on),:comments_count => n.comments_count}
|
|
|
|
@ -330,7 +330,7 @@ class CoursesService
|
|
|
|
|
def homework_list params,current_user
|
|
|
|
|
course = Course.find(params[:id])
|
|
|
|
|
if course.is_public != 0 || current_user.member_of_course?(course)
|
|
|
|
|
bids = course.homework_commons.page(1).per(3).order('created_at DESC')
|
|
|
|
|
bids = course.homework_commons.page(1).per(20).order('created_at DESC')
|
|
|
|
|
bids = bids.like(params[:name]) if params[:name].present?
|
|
|
|
|
homeworks = []
|
|
|
|
|
bids.each do |bid|
|
|
|
|
@ -665,58 +665,35 @@ class CoursesService
|
|
|
|
|
course = mp.course
|
|
|
|
|
latest_course_dynamics = []
|
|
|
|
|
dynamics_count = 0
|
|
|
|
|
# 课程学霸 学生总分数排名靠前的5个人
|
|
|
|
|
|
|
|
|
|
# 课程通知
|
|
|
|
|
latest_news = course.news.order("created_on desc").first
|
|
|
|
|
unless latest_news.nil?
|
|
|
|
|
latest_course_dynamics << {:type => 1, :time => latest_news.created_on,:count=>course.news.count,
|
|
|
|
|
:news => latest_news}
|
|
|
|
|
latest_news = course.news.page(1).per(2).order("created_on desc")
|
|
|
|
|
unless latest_news.first.nil?
|
|
|
|
|
latest_course_dynamics << {:type => 1, :time => latest_news.first.created_on,:count=>course.news.count,
|
|
|
|
|
:news => latest_news.all}
|
|
|
|
|
dynamics_count += 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 课程讨论区
|
|
|
|
|
latest_message = course.boards.first.topics[0]
|
|
|
|
|
unless latest_message.nil?
|
|
|
|
|
latest_course_dynamics << {:type => 2, :time => latest_message.created_on, :count =>course.boards.nil? ? 0 : course.boards.first.topics.count,
|
|
|
|
|
:topic => latest_message}
|
|
|
|
|
latest_message = course.boards.first.topics.page(1).per(2)
|
|
|
|
|
unless latest_message.first.nil?
|
|
|
|
|
latest_course_dynamics << {:type => 2, :time => latest_message.first.created_on, :count =>course.boards.nil? ? 0 : course.boards.first.topics.count,
|
|
|
|
|
:topics => latest_message.all}
|
|
|
|
|
dynamics_count += 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 课程资源
|
|
|
|
|
latest_attachment = course.attachments.order("created_on desc").first
|
|
|
|
|
unless latest_attachment.nil?
|
|
|
|
|
latest_course_dynamics << {:type => 3, :time => latest_attachment.created_on,:count =>course.attachments.count , :documents=>latest_attachment}
|
|
|
|
|
latest_attachment = course.attachments.order("created_on desc").page(1).per(2)
|
|
|
|
|
unless latest_attachment.first.nil?
|
|
|
|
|
latest_course_dynamics << {:type => 3, :time => latest_attachment.first.created_on,:count =>course.attachments.count , :documents=>latest_attachment}
|
|
|
|
|
dynamics_count += 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#课程作业 已经交的学生列表(暂定显示6人),未交的学生列表,作业的状态
|
|
|
|
|
homework = course.homework_commons.order('created_at desc').first
|
|
|
|
|
homework_status = "";
|
|
|
|
|
# 判断作业所处的状态,如果是刚发布,就获取剩余时间
|
|
|
|
|
#如果是匿评状态,显示正在匿评
|
|
|
|
|
#如果是匿评结束,显示匿评结束
|
|
|
|
|
#获取作业提交的前6个人,不足6个显示所有
|
|
|
|
|
studentlist = []
|
|
|
|
|
if !homework.nil?
|
|
|
|
|
if homework.homework_type == 1 && homework.homework_detail_manual
|
|
|
|
|
case homework.homework_detail_manual.comment_status
|
|
|
|
|
when 1
|
|
|
|
|
homework_status = show_homework_deadline homework
|
|
|
|
|
when 2
|
|
|
|
|
homework_status = "正在匿评中"
|
|
|
|
|
when 3
|
|
|
|
|
homework_status = "匿评已结束"
|
|
|
|
|
end
|
|
|
|
|
elsif homework.homework_type == 0
|
|
|
|
|
homework_status = "未启用匿评"
|
|
|
|
|
elsif homework.homework_type == 2
|
|
|
|
|
homework_status = "编程作业"
|
|
|
|
|
else
|
|
|
|
|
end
|
|
|
|
|
# 获取提交作业的前六个学生的名字 和 头像路径
|
|
|
|
|
homework.student_works.order("created_at desc").page(1).per(6).each do |work|
|
|
|
|
|
studentlist << {:image_url=> url_to_avatar(work.user),:user_name=>work.user.realname}
|
|
|
|
|
end
|
|
|
|
|
latest_course_dynamics << {:type => 4, :time => homework.updated_at, :count=>course.homework_commons.count,:submit_count => homework.student_works.count , :homework => homework, :homework_status => homework_status, :studentlist => studentlist}
|
|
|
|
|
homeworks = course.homework_commons.page(1).per(2).order('created_at desc')
|
|
|
|
|
unless homeworks.first.nil?
|
|
|
|
|
latest_course_dynamics << {:type => 4, :time => homeworks.first.updated_at, :count=>course.homework_commons.count , :homeworks => homeworks}
|
|
|
|
|
dynamics_count += 1
|
|
|
|
|
end
|
|
|
|
|
latest_course_dynamics.sort! { |order, newer| newer[:time] <=> order[:time] }
|
|
|
|
@ -730,9 +707,5 @@ class CoursesService
|
|
|
|
|
result
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#计算作业的截止日期,剩余日期
|
|
|
|
|
def show_homework_deadline homework
|
|
|
|
|
"距作业截止还有" << (Date.parse(Time.now.to_s) - Date.parse(homework.end_time.to_s)).to_i.to_s << "天"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|