2014-12-18 17:20:21 +08:00
|
|
|
|
#coding=utf-8
|
2014-12-17 14:50:57 +08:00
|
|
|
|
class HomeworkService
|
2014-12-18 17:20:21 +08:00
|
|
|
|
include CoursesHelper
|
|
|
|
|
include AttachmentsHelper
|
2014-12-20 13:00:13 +08:00
|
|
|
|
include ApplicationHelper
|
|
|
|
|
include WordsHelper
|
|
|
|
|
|
|
|
|
|
# 作业详情(老师才显示启动匿评,学生不显示 )
|
|
|
|
|
# many_times 第几次(作业)
|
|
|
|
|
# state=0 启动匿评
|
|
|
|
|
# state=1 关闭匿评
|
|
|
|
|
# state=2 匿评结束
|
2014-12-17 14:50:57 +08:00
|
|
|
|
def show_homework params
|
|
|
|
|
@bid = Bid.find(params[:id])
|
|
|
|
|
course = @bid.courses.first
|
2015-01-07 16:02:16 +08:00
|
|
|
|
author = @bid.author.lastname + @bid.author.firstname
|
2014-12-17 14:50:57 +08:00
|
|
|
|
many_times = course.homeworks.index(@bid) + 1
|
|
|
|
|
name = @bid.name
|
2015-01-07 16:02:16 +08:00
|
|
|
|
homework_count = @bid.homeworks.count #已提交的作业数量
|
|
|
|
|
student_questions_count = @bid.commit.nil? ? 0 : @bid.commit
|
2014-12-17 14:50:57 +08:00
|
|
|
|
description = @bid.description
|
2015-01-20 15:17:02 +08:00
|
|
|
|
#if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2
|
|
|
|
|
state = @bid.comment_status
|
|
|
|
|
#end
|
|
|
|
|
open_anonymous_evaluation = @bid.open_anonymous_evaluation
|
|
|
|
|
{:course_name => course.name,:id => @bid.id, :course_teacher => author, :homework_times => many_times, :homework_name => name, :homework_count => homework_count,:student_questions_count => student_questions_count,
|
|
|
|
|
:description => description, :homework_state => state,:open_anonymous_evaluation => open_anonymous_evaluation}
|
2014-12-17 14:50:57 +08:00
|
|
|
|
end
|
|
|
|
|
|
2014-12-20 13:00:13 +08:00
|
|
|
|
# 启动作业匿评
|
2014-12-17 14:50:57 +08:00
|
|
|
|
def alert_homework_anonymous_comment params
|
|
|
|
|
@bid = Bid.find params[:id]
|
|
|
|
|
@course = @bid.courses.first
|
|
|
|
|
if @bid.comment_status == 0
|
|
|
|
|
@totle_size = searchStudent(@course).size
|
|
|
|
|
@cur_size = @bid.homeworks.size
|
|
|
|
|
elsif @bid.comment_status == 1
|
|
|
|
|
@totle_size = 0
|
|
|
|
|
@bid.homeworks.map { |homework| @totle_size += homework.homework_evaluations.count}
|
|
|
|
|
teachers = "("
|
|
|
|
|
teacher_members = searchTeacherAndAssistant(@course)
|
|
|
|
|
teacher_members.each do |member|
|
|
|
|
|
if member == teacher_members.last
|
|
|
|
|
teachers += member.user_id.to_s + ")"
|
|
|
|
|
else
|
|
|
|
|
teachers += member.user_id.to_s + ","
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@cur_size = 0
|
|
|
|
|
@bid.homeworks.map { |homework| @cur_size += homework.rates(:quality).where("seems_rateable_rates.rater_id not in #{teachers}").count}
|
|
|
|
|
end
|
|
|
|
|
@percent = format("%.2f",(@cur_size.to_f / ( @totle_size == 0 ? 1 : @totle_size)) * 100)
|
2014-12-18 17:20:21 +08:00
|
|
|
|
[@bid,@totle_size,@cur_size,@percent]
|
2014-12-17 14:50:57 +08:00
|
|
|
|
end
|
|
|
|
|
|
2014-12-20 13:00:13 +08:00
|
|
|
|
# 匿评作品详情
|
|
|
|
|
# attachs 该作品的所有附件
|
|
|
|
|
# filename 文件名
|
|
|
|
|
# filedesc 文件描述
|
2014-12-17 14:50:57 +08:00
|
|
|
|
def anonymous_works_show params
|
2014-12-18 14:48:14 +08:00
|
|
|
|
@homework = HomeworkAttach.find(params[:homework_id])
|
|
|
|
|
name = @homework.name
|
|
|
|
|
desc = @homework.description
|
|
|
|
|
datetime = @homework.created_at
|
|
|
|
|
unless @homework.attachments.empty?
|
|
|
|
|
attachs = @homework.attachments
|
|
|
|
|
attachs.each do |attach|
|
|
|
|
|
filename = attach.name
|
|
|
|
|
filedesc = attach.description unless attachment.description.blank?
|
|
|
|
|
end
|
|
|
|
|
end
|
2014-12-20 13:00:13 +08:00
|
|
|
|
{:name => 'name', :description => 'desc', :datetime => 'datetime',
|
|
|
|
|
:attchs => 'attachs', :filename => 'filename', :filedesc => 'filedesc'}
|
2014-12-18 14:48:14 +08:00
|
|
|
|
end
|
|
|
|
|
|
2014-12-18 17:20:21 +08:00
|
|
|
|
#作品打分/留言
|
|
|
|
|
def add_score_and_jour params
|
2014-12-18 14:48:14 +08:00
|
|
|
|
@is_teacher,@is_anonymous_comments,@m_score = params[:is_teacher]=="true",params[:is_anonymous_comments]=="true",params[:stars_value]
|
|
|
|
|
@cur_page,@cur_type = params[:cur_page] || 1,params[:cur_type] || 5
|
|
|
|
|
@homework = HomeworkAttach.find(params[:homework_id])
|
|
|
|
|
#保存评分
|
|
|
|
|
@homework.rate(@m_score.to_i,User.current.id,:quality) if @m_score
|
|
|
|
|
#保存评论
|
|
|
|
|
@is_comprehensive_evaluation = @is_teacher ? 1 : (@is_anonymous_comments ? 2 : 3) #判断当前评论是老师评论?匿评?留言
|
|
|
|
|
if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "" #有没有留言
|
|
|
|
|
@homework.addjours User.current.id, params[:new_form][:user_message],0,@is_comprehensive_evaluation
|
2014-12-17 14:50:57 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-12-20 13:00:13 +08:00
|
|
|
|
#作品留言列表
|
|
|
|
|
def get_works_jours_list params
|
2014-12-18 17:20:21 +08:00
|
|
|
|
@bid = Bid.find params[:id]
|
|
|
|
|
@user = @bid.author
|
|
|
|
|
@jours = @bid.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
|
|
|
|
|
@jour = paginateHelper @jours,10
|
2014-12-20 13:00:13 +08:00
|
|
|
|
@jour
|
2014-12-18 17:20:21 +08:00
|
|
|
|
end
|
|
|
|
|
|
2014-12-20 13:00:13 +08:00
|
|
|
|
# 学生匿评留言列表
|
|
|
|
|
def anonymous_jour_list params
|
|
|
|
|
#jours留言 is null条件用以兼容历史数据
|
|
|
|
|
jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")
|
|
|
|
|
jours.each do |jour|
|
|
|
|
|
user = jour.user
|
|
|
|
|
img_url = url_to_avatar(jour.user)
|
|
|
|
|
datetime = jour.created_on
|
|
|
|
|
content = jour.notes
|
|
|
|
|
end
|
|
|
|
|
{:user => 'user', :img_url => 'img_url', :datetime => 'datetime', :content => 'content'}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 匿评教师留言/回复列表
|
|
|
|
|
# 图像img_url = url_to_avatar(user)
|
|
|
|
|
# massage_user 留言者
|
|
|
|
|
# parent_jour被回复的留言
|
|
|
|
|
def teacher_jour_list params
|
2014-12-18 17:20:21 +08:00
|
|
|
|
@homework = HomeworkAttach.find(params[:homework_id])
|
|
|
|
|
@stars_reates = @homework.rates(:quality)
|
2014-12-20 13:00:13 +08:00
|
|
|
|
@teacher_stars = @stars_reates.where("rater_id in (#{teachers})") #老师评分列表
|
|
|
|
|
@teacher_stars.each do |ts|
|
|
|
|
|
#留言参数
|
|
|
|
|
jour = get_homework_review @homework,true,massage_user
|
|
|
|
|
massage_content = jour.notes unless jour.nil?
|
|
|
|
|
massage_user = ts.rater
|
|
|
|
|
massage_score = ts.stars
|
|
|
|
|
#回复参数
|
|
|
|
|
anonymous_repy(jour)
|
|
|
|
|
end
|
2014-12-18 17:20:21 +08:00
|
|
|
|
end
|
2014-12-18 14:48:14 +08:00
|
|
|
|
|
2014-12-20 13:00:13 +08:00
|
|
|
|
# 学生匿评列表
|
|
|
|
|
def student_jour_list params
|
|
|
|
|
@homework = HomeworkAttach.find(params[:homework_id])
|
|
|
|
|
@stars_reates = @homework.rates(:quality)
|
|
|
|
|
@student_stars = @stars_reates.where("rater_id not in (#{teachers})") #学生评分列表
|
|
|
|
|
@student_stars.each do |ss|
|
|
|
|
|
#留言参数
|
|
|
|
|
massage_user = ss.rater
|
|
|
|
|
jour = get_homework_review @homework,false,massage_user
|
|
|
|
|
massage_score = ss.stars
|
|
|
|
|
massage_content = jour.notes unless jour.nil?
|
|
|
|
|
#回复参数
|
|
|
|
|
anonymous_repy(jour)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def anonymous_repy jour
|
|
|
|
|
fetch_user_leaveWord_reply(jour).each do |fulr|
|
|
|
|
|
parent_jour = JournalsForMessage.where("id = #{fulr.m_reply_id}").first
|
|
|
|
|
reply_name = fulr.user.name
|
|
|
|
|
parent_name = parent_jour.user.name if parent_jour
|
|
|
|
|
reply_content = fulr.notes
|
|
|
|
|
reply_time = fulr.created_on
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-01-21 11:28:09 +08:00
|
|
|
|
|
|
|
|
|
#我的作品列表
|
|
|
|
|
def my_homework_list params,current_user
|
|
|
|
|
@user = User.find(params[:user_id])
|
|
|
|
|
if !current_user.admin? && !@user.active?
|
|
|
|
|
raise '404'
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
if current_user == @user || current_user.admin?
|
|
|
|
|
membership = @user.coursememberships.all
|
|
|
|
|
else
|
|
|
|
|
membership = @user.coursememberships.all(:conditions => Course.visible_condition(current_user))
|
|
|
|
|
end
|
|
|
|
|
membership.sort! {|older, newer| newer.created_on <=> older.created_on }
|
|
|
|
|
course_list = []
|
|
|
|
|
membership.each do |mp|
|
|
|
|
|
my_homeworks = []
|
|
|
|
|
mp.course.homeworks.each do |bid|
|
|
|
|
|
hw = bid.homeworks.where("user_id = #{current_user.id}")
|
|
|
|
|
my_homeworks << hw[0] unless (hw.nil? || hw[0].nil?)
|
|
|
|
|
end
|
|
|
|
|
course_list << {:course => mp.course,:img_url => url_to_avatar(mp.course),:my_homework => my_homeworks}
|
|
|
|
|
end
|
|
|
|
|
course_list
|
|
|
|
|
end
|
2014-12-17 14:50:57 +08:00
|
|
|
|
end
|