|
|
|
@ -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.order('end_time DESC')
|
|
|
|
|
bids = course.homework_commons.page(1).per(3).order('end_time DESC')
|
|
|
|
|
bids = bids.like(params[:name]) if params[:name].present?
|
|
|
|
|
homeworks = []
|
|
|
|
|
bids.each do |bid|
|
|
|
|
@ -540,14 +540,35 @@ class CoursesService
|
|
|
|
|
#student_questions_count = bid.journals_for_messages.where('m_parent_id IS NULL').count
|
|
|
|
|
description = bid.description
|
|
|
|
|
#if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2
|
|
|
|
|
state = bid.homework_detail_manual.comment_status
|
|
|
|
|
#state = bid.homework_detail_manual.comment_status
|
|
|
|
|
if !bid.nil?
|
|
|
|
|
if bid.homework_type == 1 && bid.homework_detail_manual
|
|
|
|
|
case bid.homework_detail_manual.comment_status
|
|
|
|
|
when 1
|
|
|
|
|
state = show_homework_deadline bid
|
|
|
|
|
when 2
|
|
|
|
|
state = "正在匿评中"
|
|
|
|
|
when 3
|
|
|
|
|
state = "匿评已结束"
|
|
|
|
|
end
|
|
|
|
|
elsif bid.homework_type == 0
|
|
|
|
|
state = "未启用匿评"
|
|
|
|
|
elsif bid.homework_type == 2
|
|
|
|
|
state = "编程作业"
|
|
|
|
|
else
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
studentlist = []
|
|
|
|
|
bid.student_works.order("created_at desc").page(1).per(6).each do |work|
|
|
|
|
|
studentlist << work.user
|
|
|
|
|
end
|
|
|
|
|
unless is_course_teacher
|
|
|
|
|
homework_for_anonymous_comments = get_student_batch_homework_list bid,current_user
|
|
|
|
|
end
|
|
|
|
|
#end
|
|
|
|
|
open_anonymous_evaluation = bid.homework_detail_manual.comment_status
|
|
|
|
|
{:course_name => course.name,:course_id => course.id,:id => bid.id, :author => bid.user,:author_real_name => author_real_name, :homework_times => many_times, :homework_name => name, :homework_count => homework_count,:student_questions_count => 0,
|
|
|
|
|
:description => description, :homework_state => state,:open_anonymous_evaluation => open_anonymous_evaluation,:homework_for_anonymous_comments => homework_for_anonymous_comments,:created_on => bid.created_at,:deadline => bid.end_time}
|
|
|
|
|
:description => description, :homework_state => state,:open_anonymous_evaluation => open_anonymous_evaluation,:homework_for_anonymous_comments => homework_for_anonymous_comments,:created_on => bid.created_at,:deadline => bid.end_time,:studentlist => studentlist}
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -615,9 +636,103 @@ class CoursesService
|
|
|
|
|
homework_scores
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#app新版api
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
#课程动态
|
|
|
|
|
public
|
|
|
|
|
def all_course_dynamics params, current_user
|
|
|
|
|
#获取当前用户的所有课程
|
|
|
|
|
@user = User.find(params[:id])
|
|
|
|
|
if current_user.nil? && !current_user.admin? && !@user.active?
|
|
|
|
|
raise '404'
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
if current_user == @user || current_user.admin?
|
|
|
|
|
membership = @user.coursememberships.page(1).per(10)
|
|
|
|
|
else
|
|
|
|
|
membership = @user.coursememberships.page(1).per(10).all(:conditions => Course.visible_condition(current_user))
|
|
|
|
|
end
|
|
|
|
|
if membership.nil? || membership.count == 0
|
|
|
|
|
raise l(:label_no_courses, :locale => get_user_language(current_user))
|
|
|
|
|
end
|
|
|
|
|
membership.sort! { |older, newer| newer.created_on <=> older.created_on }
|
|
|
|
|
|
|
|
|
|
#定义一个数组集合,存放hash数组,该hash数组包括课程的信息,并包含课程的最新发布的资源,最新的讨论区留言,最新的作业,最新的通知
|
|
|
|
|
result = []
|
|
|
|
|
#对用户所有的课程进行循环,找到每个课程最新发布的资源,最新的讨论区留言,最新的作业,最新的通知,并存进数组
|
|
|
|
|
membership.each do |mp|
|
|
|
|
|
course = mp.course
|
|
|
|
|
latest_course_dynamics = []
|
|
|
|
|
dynamics_count = 0
|
|
|
|
|
# 课程通知
|
|
|
|
|
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}
|
|
|
|
|
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}
|
|
|
|
|
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}
|
|
|
|
|
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}
|
|
|
|
|
dynamics_count += 1
|
|
|
|
|
end
|
|
|
|
|
latest_course_dynamics.sort! { |order, newer| newer[:time] <=> order[:time] }
|
|
|
|
|
latest_course_dynamic = latest_course_dynamics.first
|
|
|
|
|
unless latest_course_dynamic.nil?
|
|
|
|
|
result << {:course_name => course.name, :course_id => course.id, :course_img_url => url_to_avatar(course), :course_time => course.time, :course_term => course.term,:message => dynamics_count, :dynamics => latest_course_dynamics, :count => dynamics_count}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
#返回数组集合
|
|
|
|
|
result.sort! { |order, newer| newer[:update_time] <=> order[:update_time] }
|
|
|
|
|
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
|