2014-10-23 11:30:34 +08:00
class HomeworkAttachController < ApplicationController
layout " course_base "
include CoursesHelper
2014-11-03 11:01:17 +08:00
include HomeworkAttachHelper
2014-10-31 14:06:40 +08:00
helper :words
2014-10-23 11:30:34 +08:00
###############################
before_filter :can_show_course , except : [ ]
#判断当前角色权限时需先找到当前操作的project
2015-03-09 17:28:17 +08:00
before_filter :logged_user_by_apptoken , :find_course_by_bid_id , :only = > [ :new ]
2014-11-01 11:02:13 +08:00
before_filter :find_bid_and_course , :only = > [ :get_not_batch_homework , :get_batch_homeworks , :get_homeworks , :get_homework_jours , :get_student_batch_homework , :get_my_homework ]
2014-11-02 09:39:18 +08:00
before_filter :find_course_by_hoemwork_id , :only = > [ :edit , :update , :destroy , :show , :add_homework_users , :destory_homework_users , :praise_homework ]
2014-10-23 11:30:34 +08:00
#判断当前角色是否有操作权限
#勿删 before_filter :authorize, :only => [:new,:edit,:update,:destroy]
2014-11-04 10:41:34 +08:00
#@cur_type:
#1.未批作业列表
#2.已批作业列表
#3.全部作业列表
#4.匿评作业列表
#根据此字段判断关闭homework_attach的show界面后是否要调用js刷新页面
2014-10-30 15:12:45 +08:00
#获取未批作业列表
def get_not_batch_homework
2014-12-30 14:29:30 +08:00
@not_batch_homework = true
2014-11-04 16:01:55 +08:00
sort , direction = params [ :sort ] || " s_socre " , params [ :direction ] || " desc "
2014-12-29 16:03:21 +08:00
get_not_batch_homework_list sort , direction , @bid . id
2014-11-04 10:41:34 +08:00
@cur_page = params [ :page ] || 1
@cur_type = 1
2015-01-22 15:16:15 +08:00
@cur_sort , @cur_direction = params [ :sort ] || " s_socre " , params [ :direction ] || " desc "
2014-10-30 21:08:37 +08:00
@direction = direction == 'asc' ? 'desc' : 'asc'
2014-10-30 16:33:14 +08:00
respond_to do | format |
format . js
2014-12-30 14:29:30 +08:00
format . xls {
send_data ( homework_to_xls ( @all_homework_list ) , :type = > " text/excel;charset=utf-8; header=present " ,
2014-12-31 09:48:17 +08:00
:filename = > " #{ @course . teacher . lastname . to_s + @course . teacher . firstname } _ #{ @course . name } _ #{ @course . time . to_s + @course . term } _ #{ @bid . name } #{ l ( :excel_homework_list ) } ( #{ l ( :excel_not_rated ) } ).xls " )
2014-12-30 14:29:30 +08:00
}
2014-10-30 16:33:14 +08:00
end
end
#获取已评作业列表
def get_batch_homeworks
2014-11-04 16:01:55 +08:00
sort , direction = params [ :sort ] || " s_socre " , params [ :direction ] || " desc "
2014-12-30 14:29:30 +08:00
@is_batch_homeworks = true
2014-11-04 16:01:55 +08:00
if sort == 't_socre'
order_by = " t_score #{ direction } "
elsif sort == 's_socre'
order_by = " s_score #{ direction } "
elsif sort == 'time'
order_by = " created_at #{ direction } "
end
2014-10-30 17:27:07 +08:00
all_homework_list = HomeworkAttach . eager_load ( :attachments , :user , :rate_averages ) . find_by_sql ( " SELECT * FROM (SELECT homework_attaches.*,
2014-12-31 11:18:22 +08:00
( SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0 , 1 ) AS t_score ,
2014-12-29 16:03:21 +08:00
( SELECT AVG ( stars ) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND is_teacher_score = 0 ) AS s_score
2014-10-30 17:42:08 +08:00
FROM homework_attaches WHERE bid_id = #{@bid.id}
2014-10-31 09:17:30 +08:00
ORDER BY #{order_by}) AS table1
2014-10-30 17:27:07 +08:00
WHERE table1 . t_score IS NOT NULL " )
2014-11-04 10:41:34 +08:00
@cur_page = params [ :page ] || 1
@cur_type = 2
2014-10-30 17:27:07 +08:00
@homework_list = paginateHelper all_homework_list , 10
2014-10-30 21:08:37 +08:00
@direction = direction == 'asc' ? 'desc' : 'asc'
2014-10-30 16:33:14 +08:00
respond_to do | format |
2014-10-30 22:04:14 +08:00
format . js
2014-12-30 14:29:30 +08:00
format . xls {
send_data ( homework_to_xls ( all_homework_list ) , :type = > " text/excel;charset=utf-8; header=present " ,
2014-12-31 09:48:17 +08:00
:filename = > " #{ @course . teacher . lastname . to_s + @course . teacher . firstname } _ #{ @course . name } _ #{ @course . time . to_s + @course . term } _ #{ @bid . name } #{ l ( :excel_homework_list ) } ( #{ l ( :excel_been_rated ) } ).xls " )
2014-12-29 17:44:39 +08:00
}
2014-10-30 16:33:14 +08:00
end
end
2014-12-29 17:44:39 +08:00
2014-10-30 16:33:14 +08:00
#获取所有作业列表
def get_homeworks
2014-12-30 14:29:30 +08:00
@is_all_homeworks = true
2014-11-04 16:01:55 +08:00
sort , direction = params [ :sort ] || " s_socre " , params [ :direction ] || " desc "
if sort == 't_socre'
order_by = " t_score #{ direction } "
elsif sort == 's_socre'
order_by = " s_score #{ direction } "
elsif sort == 'time'
order_by = " created_at #{ direction } "
end
2014-10-30 17:27:07 +08:00
all_homework_list = HomeworkAttach . eager_load ( :attachments , :user , :rate_averages ) . find_by_sql ( " SELECT homework_attaches.*,
2014-12-31 11:18:22 +08:00
( SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0 , 1 ) AS t_score ,
2014-12-29 16:03:21 +08:00
( SELECT AVG ( stars ) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND is_teacher_score = 0 ) AS s_score
2014-10-30 16:33:14 +08:00
FROM homework_attaches WHERE bid_id = #{@bid.id}
2014-10-31 09:17:30 +08:00
ORDER BY #{order_by}")
2014-11-04 10:41:34 +08:00
@cur_page = params [ :page ] || 1
@cur_type = 3
2014-10-30 17:27:07 +08:00
@homework_list = paginateHelper all_homework_list , 10
2014-10-30 21:08:37 +08:00
@direction = direction == 'asc' ? 'desc' : 'asc'
2014-10-30 16:33:14 +08:00
respond_to do | format |
format . js
2014-12-30 14:29:30 +08:00
format . xls {
send_data ( homework_to_xls ( all_homework_list ) , :type = > " text/excel;charset=utf-8; header=present " ,
2014-12-31 09:48:17 +08:00
:filename = > " #{ @course . teacher . lastname . to_s + @course . teacher . firstname } _ #{ @course . name } _ #{ @course . time . to_s + @course . term } _ #{ @bid . name } #{ l ( :excel_homework_list ) } .xls " )
2014-12-30 14:29:30 +08:00
}
2014-10-30 16:33:14 +08:00
end
end
2014-11-01 11:02:13 +08:00
#获取学生匿评列表
def get_student_batch_homework
2014-11-01 14:33:50 +08:00
@is_student_batch_homework = true
2015-01-30 16:58:05 +08:00
all_homework_list = get_student_batch_homework_list @bid , User . current
2014-11-04 10:41:34 +08:00
@cur_page = params [ :page ] || 1
@cur_type = 4
2014-11-01 11:02:13 +08:00
@homework_list = paginateHelper all_homework_list , 10
respond_to do | format |
format . js
end
end
#获取我的作业
def get_my_homework
2014-11-01 14:33:50 +08:00
@is_my_homework = true
2014-11-01 11:02:13 +08:00
all_homework_list = HomeworkAttach . find_by_sql ( " SELECT homework_attaches.*,
2014-12-31 11:18:22 +08:00
( SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0 , 1 ) AS t_score ,
2014-12-29 16:03:21 +08:00
( SELECT AVG ( stars ) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND is_teacher_score = 0 ) AS s_score
2014-11-01 11:02:13 +08:00
FROM homework_attaches
2014-11-01 14:33:50 +08:00
WHERE homework_attaches . bid_id = #{@bid.id} AND homework_attaches.user_id = #{User.current.id}")
2014-11-01 11:02:13 +08:00
#如果我没有创建过作业,就检索我是否参与了某个作业
if all_homework_list . empty?
all_homework_list = HomeworkAttach . find_by_sql ( " SELECT homework_attaches.*,
2014-12-31 11:18:22 +08:00
( SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0 , 1 ) AS t_score ,
2014-12-29 16:03:21 +08:00
( SELECT AVG ( stars ) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND is_teacher_score = 0 ) AS s_score
2014-11-01 11:02:13 +08:00
FROM homework_attaches
INNER JOIN homework_users ON homework_users . homework_attach_id = homework_attaches . id
WHERE homework_attaches . bid_id = #{@bid.id} AND homework_users.user_id = #{User.current.id}")
end
2014-11-04 10:41:34 +08:00
@cur_page = params [ :page ] || 1
2014-11-01 11:02:13 +08:00
@homework_list = paginateHelper all_homework_list , 10
respond_to do | format |
format . js
end
end
2014-10-30 16:33:14 +08:00
#获取作业的留言列表
def get_homework_jours
2014-11-04 10:07:15 +08:00
@user = @bid . author
2014-10-31 14:06:40 +08:00
@jours = @bid . journals_for_messages . where ( 'm_parent_id IS NULL' ) . order ( 'created_on DESC' )
2014-11-01 15:06:03 +08:00
@jour = paginateHelper @jours , 10
2014-10-31 14:06:40 +08:00
@state = false
2014-10-30 15:12:45 +08:00
respond_to do | format |
format . js
end
2014-10-23 11:30:34 +08:00
end
2014-11-02 09:39:18 +08:00
#为作业点赞
def praise_homework
pt = PraiseTread . new
pt . user_id = User . current . id
pt . praise_tread_object_id = @homework . id
pt . praise_tread_object_type = " HomeworkAttach "
pt . praise_or_tread = 1
if pt . save
respond_to do | format |
format . js
end
else
render_404
end
end
2014-10-23 11:30:34 +08:00
#获取作业的成员
def get_homework_member homework
@hoemwork_users = users_for_homework ( @homework )
@members = members_for_homework ( @homework , @hoemwork_users , params [ :q ] )
@members = paginateHelper @members , 10
end
def index
@homeworks = HomeworkAttach . all
respond_to do | format |
format . html # index.html.erb
format . json { render json : @homeworks }
end
end
#作业添加成员(参与人员)
def add_homework_users
if User . current . admin? || User . current . member_of_course? ( @homework . bid . courses . first )
#@homework = HomeworkAttach.find(params[:id])
if params [ :membership ]
if params [ :membership ] [ :user_ids ]
attrs = params [ :membership ] . dup
user_ids = attrs . delete ( :user_ids )
user_ids . each do | user_id |
@homework . homework_users . build ( :user_id = > user_id )
end
end
end
@homework . save
get_homework_member @homework
respond_to do | format |
format . js
end
else
render_403 :message = > :notice_not_authorized
end
end
#作业删除成员(参与人员)
def destory_homework_users
#@homework = HomeworkAttach.find(params[:id])
if User . current . admin? || User . current . member_of_course? ( @homework . bid . courses . first )
homework_user = @homework . homework_users . where ( " user_id = #{ params [ :user_id ] } " ) . first
homework_user . destroy
get_homework_member @homework
2014-11-02 13:18:02 +08:00
@homework_list = [ ]
@is_my_homework = true
2014-10-23 11:30:34 +08:00
respond_to do | format |
format . js
end
else
render_403 :message = > :notice_not_authorized
end
end
def create
bid = Bid . find params [ :bid_id ]
if User . current . admin? || User . current . member_of_course? ( bid . courses . first ) # modify by nwb
2014-11-05 10:54:39 +08:00
if bid . homeworks . where ( " user_id = ? " , User . current ) . empty?
2014-10-23 11:30:34 +08:00
user_id = params [ :user_id ]
bid_id = params [ :bid_id ]
if params [ :homework_attach ]
if params [ :homework_attach ] [ :project_id ]
project_id = params [ :homework_attach ] [ :project_id ]
else
project_id = 0
end
else
project_id = 0
end
sta = 0
2014-11-02 17:08:19 +08:00
name = params [ :homework_attach ] [ :name ]
description = params [ :homework_attach ] [ :description ]
2014-10-23 11:30:34 +08:00
options = {
:user_id = > user_id ,
:state = > sta ,
:name = > name ,
:description = > description ,
:bid_id = > bid_id ,
:project_id = > project_id
}
@homework = HomeworkAttach . new ( options )
@homework . save_attachments ( params [ :attachments ] )
render_attachment_warning_if_needed ( @homework )
if @homework . save
respond_to do | format |
format . html { redirect_to course_for_bid_url @homework . bid }
format . json { head :no_content }
end
else
render_403 :message = > :notice_not_authorized
end
else
render_403 :message = > :notice_has_homework
end
else
render_403 :message = > :notice_not_authorized
end
end
def new
@bid = Bid . find ( params [ :id ] )
2014-10-29 17:42:12 +08:00
if User . current . admin? || User . current . member_of_course? ( @bid . courses . first )
2014-10-23 11:30:34 +08:00
@homework = HomeworkAttach . new
respond_to do | format |
format . html # new.html.erb
format . json { render json : @homework }
end
else
render_403 :message = > :notice_not_authorized
end
end
#获取作业成员的集合
def get_homework_member_list
@homework = HomeworkAttach . find ( params [ :bid_id ] )
course = @homework . bid . courses . first
if User . current . admin? || User . current . member_of_course? ( course )
get_homework_member @homework
else
raise " error "
end
respond_to do | format |
format . js
end
end
#获取可选成员列表
#homework: 作业
#users: 该作业所有成员
#q:模糊匹配的用户的昵称
def members_for_homework homework , users , q
unpartin_users = homework . bid . courses . first . members . where ( " user_id not in (:users) " , { :users = > users } ) . joins ( :user ) . where ( " users.login like '% #{ q } %' " )
canpartin_users = [ ]
unpartin_users . each do | m |
if m . user . allowed_to? ( :paret_in_homework , homework . bid . courses . first )
canpartin_users << m
end
end
canpartin_users
end
def edit
2014-12-04 15:13:26 +08:00
bid = @homework . bid
if ( bid . comment_status == 0 || bid . open_anonymous_evaluation == 0 ) && ( User . current . admin? || User . current . member_of_course? ( bid . courses . first ) )
2014-10-23 11:30:34 +08:00
get_homework_member @homework
else
render_403 :message = > :notice_not_authorized
end
end
def update
#@homework = HomeworkAttach.find(params[:id])
course = @homework . bid . courses . first
if User . current . admin? || User . current . member_of_course? ( course )
name = params [ :homework_name ]
description = params [ :homework_description ]
@homework . name = name
@homework . description = description
2014-11-25 16:51:22 +08:00
@homework . project_id = params [ :project_id ] || 0
2014-10-23 11:30:34 +08:00
if params [ :attachments ]
@homework . save_attachments ( params [ :attachments ] )
end
if @homework . save
respond_to do | format |
format . html { redirect_to course_for_bid_url @homework . bid }
format . json { head :no_content }
end
else
end
else
render_403 :message = > :notice_not_authorized
end
end
def destroy
2014-12-04 15:13:26 +08:00
bid = @homework . bid
if ( bid . comment_status == 0 || bid . open_anonymous_evaluation == 0 ) && ( User . current . admin? || User . current == @homework . user )
2014-10-23 11:30:34 +08:00
if @homework . destroy
2014-11-01 14:33:50 +08:00
#respond_to do |format|
# format.html { redirect_to course_for_bid_url @homework.bid }
# format.json { head :no_content }
#end
@homework_list = [ ]
@is_my_homework = true
2014-10-23 11:30:34 +08:00
respond_to do | format |
2014-11-01 14:33:50 +08:00
format . js
2014-10-23 11:30:34 +08:00
end
else
end
else
2014-12-15 16:20:58 +08:00
render_403
2014-10-23 11:30:34 +08:00
end
end
#显示作业信息
def show
2014-12-04 18:01:53 +08:00
if User . current . admin? || User . current . member_of_course? ( @course )
# 作业打分列表
@stars_reates = @homework . rates ( :quality )
#我的评分
@is_teacher = is_course_teacher User . current , @course
2014-12-29 16:59:22 +08:00
@has_evaluation = @stars_reates . where ( " rater_id = #{ User . current . id } and is_teacher_score= #{ @is_teacher ? 1 : 0 } " ) . first
2014-12-04 18:01:53 +08:00
@m_score = @has_evaluation . nil? ? 0 : @has_evaluation . stars
2014-12-29 16:03:21 +08:00
@teacher_stars = @stars_reates . where ( " is_teacher_score = 1 " ) #老师评分列表
@student_stars = @stars_reates . where ( " is_teacher_score = 0 " ) #学生评分列表
2014-12-04 18:01:53 +08:00
@is_anonymous_comments = @bid . comment_status == 1 && ! @homework . users . include? ( User . current ) && @homework . user != User . current && ! @is_teacher #判断是不是匿评(开启匿评,当前用户不是作业的创建者或者参与者,不是老师)
jours = @homework . journals_for_messages . where ( " is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null " ) . order ( " created_on DESC " ) #jours留言 is null条件用以兼容历史数据
@jour = paginateHelper jours , 5 #留言
2014-11-04 10:41:34 +08:00
@cur_page = params [ :cur_page ] || 1
@cur_type = params [ :cur_type ] || 5
2014-11-22 09:49:51 +08:00
2014-10-30 19:32:43 +08:00
respond_to do | format |
2014-11-02 09:46:07 +08:00
format . html
2014-10-30 19:32:43 +08:00
format . js
end
2014-10-23 11:30:34 +08:00
else
render_403 :message = > :notice_not_authorized
end
end
#删除留言
def destroy_jour
2014-12-05 09:43:03 +08:00
@homework = HomeworkAttach . find ( params [ :homework_id ] )
2014-11-03 17:31:04 +08:00
@journal_destroyed = JournalsForMessage . find ( params [ :object_id ] )
2014-12-05 09:43:03 +08:00
if @journal_destroyed . is_comprehensive_evaluation == 3 && @journal_destroyed . destroy
render_403 unless User . current == @journal_destroyed . user || User . current . admin?
@stars_reates = @homework . rates ( :quality )
2014-12-29 16:03:21 +08:00
@teacher_stars = @stars_reates . where ( " is_teacher_score = 1) " ) #老师评分列表
@student_stars = @stars_reates . where ( " is_teacher_score = 0 " ) #学生评分列表
2014-12-05 09:43:03 +08:00
jours = @homework . journals_for_messages . where ( " is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null " ) . order ( " created_on DESC " ) #jours留言 is null条件用以兼容历史数据
@jour = paginateHelper jours , 5 #留言
else
render_404
2014-11-03 17:31:04 +08:00
end
2014-12-05 09:43:03 +08:00
#@course=@homework.bid.courses.first
#@journal_destroyed = JournalsForMessage.find(params[:object_id])
#@is_comprehensive_evaluation = @journal_destroyed.is_comprehensive_evaluation
#@journal_destroyed.destroy
#if @is_comprehensive_evaluation == 3
# @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")
# @jour = paginateHelper @jours,5
#elsif @is_comprehensive_evaluation == 2
# annymous_users = @homework.homework_evaluations.map { |homework_evaluation| homework_evaluation.user.id}.join(',')
# unless annymous_users.nil? || annymous_users.count == ""
# @anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in (#{annymous_users})").order("created_on DESC")
# end
#elsif @is_comprehensive_evaluation == 1
# teachers = searchTeacherAndAssistant @course
# @comprehensive_evaluation = []
# teachers.each do|teacher|
# temp = @homework.journals_for_messages.where("is_comprehensive_evaluation = 1 and user_id = #{teacher.user_id}").order("created_on DESC").first
# @comprehensive_evaluation << temp if temp
# end
#end
2014-10-23 11:30:34 +08:00
respond_to do | format |
format . js
end
end
#添加留言
def addjours
2014-12-05 09:43:03 +08:00
@is_teacher , @is_anonymous_comments , @m_score = params [ :is_teacher ] == " true " , params [ :is_anonymous_comments ] == " true " , params [ :stars_value ]
2015-01-22 15:16:15 +08:00
@cur_page , @cur_type = params [ :page ] || 1 , params [ :cur_type ] || 5
2014-12-05 09:43:03 +08:00
@homework = HomeworkAttach . find ( params [ :homework_id ] )
2014-12-31 10:45:21 +08:00
@stars_reates = @homework . rates ( :quality )
2014-12-31 08:48:14 +08:00
homework = @homework
2014-12-29 16:59:22 +08:00
is_teacher = @is_teacher ? 1 : 0
2014-12-29 16:03:21 +08:00
#保存评分@homework.rate(@m_score.to_i,User.current.id,:quality, (@is_teacher ? 1 : 0))
2014-12-31 16:00:45 +08:00
if @m_score
rate = @homework . rates ( :quality ) . where ( :rater_id = > User . current . id , :is_teacher_score = > is_teacher ) . first
2014-12-29 16:59:22 +08:00
if rate
2014-12-29 16:03:21 +08:00
rate . stars = @m_score
rate . save!
else
2014-12-29 16:59:22 +08:00
@homework . rates ( :quality ) . new ( :stars = > @m_score , :rater_id = > User . current . id , :is_teacher_score = > is_teacher ) . save!
2014-12-29 16:03:21 +08:00
end
2014-12-31 10:45:21 +08:00
2014-12-31 08:48:14 +08:00
if homework . is_teacher_score == 0
if is_teacher == 1
homework . score = @m_score
homework . is_teacher_score = 1
else
2014-12-31 15:48:45 +08:00
sql = " SELECT AVG(stars) as stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = #{ homework . id } "
score = HomeworkAttach . find_by_sql ( sql ) . first . stars
homework . score = score
2014-12-31 08:48:14 +08:00
end
else
if is_teacher == 1
homework . score = @m_score
homework . is_teacher_score = 1
end
end
homework . save!
end
2014-12-01 15:41:49 +08:00
#保存评论
2014-12-05 09:43:03 +08:00
@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-11-03 15:28:54 +08:00
end
2014-12-29 16:03:21 +08:00
@teacher_stars = @stars_reates . where ( " is_teacher_score = 1 " ) #老师评分列表
@student_stars = @stars_reates . where ( " is_teacher_score = 0 " ) #学生评分列表
2014-12-05 09:43:03 +08:00
jours = @homework . journals_for_messages . where ( " is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null " ) . order ( " created_on DESC " ) #jours留言 is null条件用以兼容历史数据
@jour = paginateHelper jours , 5 #留言
2014-11-04 14:49:36 +08:00
2014-12-02 16:21:36 +08:00
if @cur_type == " 1 " #如果当前是老师未批列表,需要刷新整个作业列表界面
@bid = @homework . bid
2015-01-22 15:16:15 +08:00
get_not_batch_homework_list params [ :cur_sort ] || " s_socre " , params [ :cur_direction ] || " desc " , @homework . bid_id
2014-12-02 16:21:36 +08:00
elsif @cur_type == " 2 " #老师已批列表
2014-12-29 16:59:22 +08:00
@result_homework = HomeworkAttach . find_by_sql ( " SELECT homework_attaches.*,
2014-12-31 11:18:22 +08:00
( SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0 , 1 ) AS t_score ,
2014-12-29 16:03:21 +08:00
( SELECT AVG ( stars ) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND is_teacher_score = 0 ) AS s_score
2014-12-02 16:21:36 +08:00
FROM homework_attaches WHERE id = #{@homework.id}").first
elsif @cur_type == " 3 " #全部作业列表
2014-12-29 16:59:22 +08:00
@result_homework = HomeworkAttach . find_by_sql ( " SELECT homework_attaches.*,
2014-12-31 11:18:22 +08:00
( SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0 , 1 ) AS t_score ,
2014-12-29 16:03:21 +08:00
( SELECT AVG ( stars ) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND is_teacher_score = 0 ) AS s_score
2014-12-02 16:21:36 +08:00
FROM homework_attaches WHERE id = #{@homework.id}").first
elsif @cur_type == " 4 " #匿评作业列表
@is_student_batch_homework = true
2014-12-29 16:59:22 +08:00
@result_homework = HomeworkAttach . find_by_sql ( " SELECT homework_attaches.*,
2014-12-31 11:18:22 +08:00
( SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0 , 1 ) AS t_score ,
2014-12-29 16:03:21 +08:00
( SELECT AVG ( stars ) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND is_teacher_score = 0 ) AS s_score ,
2014-12-29 16:59:22 +08:00
( SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND rater_id = #{User.current.id} AND is_teacher_score = #{is_teacher}) AS m_score
2014-12-02 16:21:36 +08:00
FROM homework_attaches
WHERE homework_attaches . id = #{@homework.id}").first
else #其他的不用管
end
2014-10-23 11:30:34 +08:00
respond_to do | format |
format . js
end
end
#教师综评
def comprehensive_evaluation_jour
@homework = HomeworkAttach . find ( params [ :jour_id ] )
@add_jour = @homework . addjours User . current . id , params [ :new_form ] [ :user_message ] , 0 , params [ :is_comprehensive_evaluation ]
respond_to do | format |
format . html { redirect_to homework_attach_url @homework }
format . json { head :no_content }
end
end
#获取指定作业的平均得分
def score
end
#添加回复
def add_jour_reply
parent_id = params [ :reference_id ]
author_id = User . current . id
reply_user_id = params [ :reference_user_id ]
reply_id = params [ :reference_message_id ] # 暂时不实现
content = params [ :user_notes ]
options = { :user_id = > author_id ,
:m_parent_id = > parent_id ,
:m_reply_id = > reply_id ,
:reply_id = > reply_user_id ,
:notes = > content ,
:is_readed = > false }
@jfm = JournalsForMessage . new ( options )
@jfm . save
respond_to do | format |
format . js {
@save_succ = true if @jfm . errors . empty?
}
end
end
2014-10-30 15:12:45 +08:00
private
2014-10-23 11:30:34 +08:00
#验证是否显示课程
def can_show_course
@first_page = FirstPage . find_by_page_type ( 'project' )
if @first_page . show_course == 2
render_404
end
end
2014-10-30 15:12:45 +08:00
2014-10-31 10:21:38 +08:00
def find_bid_and_course
@bid = Bid . find ( params [ :bid_id ] )
@course = @bid . courses . first
rescue ActiveRecord :: RecordNotFound
render_404
end
2014-10-30 15:12:45 +08:00
def find_course_by_bid_id
@bid = Bid . find ( params [ :id ] )
2014-10-30 16:33:14 +08:00
@course = @bid . courses . first
2014-10-30 15:12:45 +08:00
rescue ActiveRecord :: RecordNotFound
render_404
end
def find_course_by_hoemwork_id
@homework = HomeworkAttach . find ( params [ :id ] )
2014-11-01 14:33:50 +08:00
@bid = @homework . bid
@course = @bid . courses . first
rescue ActiveRecord :: RecordNotFound
render_404
2014-10-30 15:12:45 +08:00
end
2014-10-30 16:33:14 +08:00
#获取课程的老师列表
def find_course_teachers course
2014-12-02 16:21:36 +08:00
searchTeacherAndAssistant ( course ) . map { | teacher | teacher . user_id } . join ( " , " )
2014-10-30 16:33:14 +08:00
end
2014-10-30 17:42:08 +08:00
#获取作业教师评分所占比例
def get_teacher_proportion bid
if bid . proportion
teacher_proportion = bid . proportion * 1 . 0 / 100
else
teacher_proportion = 1 . 0
end
teacher_proportion
end
2014-12-02 16:21:36 +08:00
2014-12-29 16:03:21 +08:00
def get_not_batch_homework_list sort , direction , bid_id
2014-12-02 16:21:36 +08:00
if sort == 't_socre'
order_by = " t_score #{ direction } "
elsif sort == 's_socre'
order_by = " s_score #{ direction } "
elsif sort == 'time'
order_by = " created_at #{ direction } "
end
2014-12-30 14:29:30 +08:00
@all_homework_list = HomeworkAttach . eager_load ( :attachments , :user , :rate_averages ) . find_by_sql ( " SELECT * FROM (SELECT homework_attaches.*,
2014-12-31 11:18:22 +08:00
( SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0 , 1 ) AS t_score ,
2014-12-29 16:03:21 +08:00
( SELECT AVG ( stars ) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND is_teacher_score = 0 ) AS s_score
2014-12-02 16:21:36 +08:00
FROM homework_attaches WHERE bid_id = #{bid_id}
ORDER BY #{order_by}) AS table1
WHERE table1 . t_score IS NULL " )
2014-12-30 14:29:30 +08:00
@homework_list = paginateHelper @all_homework_list , 10
2014-12-02 16:21:36 +08:00
end
2014-12-04 18:01:53 +08:00
#获取指定作业的所有成员
def users_for_homework homework
homework . nil? ? [ ] : ( homework . users + [ homework . user ] )
end
2014-12-30 14:29:30 +08:00
def homework_to_csv items
encoding = l ( :general_csv_encoding )
columns = [ " student_id " , " user_name " , " login " , " student_num " , " mail " , " work_name " , " teacher_score " , " ni_score " , " commit_time " ]
export = FCSV . generate ( :col_sep = > l ( :general_csv_separator ) ) do | csv |
# csv header fields
csv << columns . collect { | c | Redmine :: CodesetUtil . from_utf8 ( c , encoding ) }
# csv lines
items . each do | homework |
csv << [ homework . user . id , Redmine :: CodesetUtil . from_utf8 ( homework . user . lastname . to_s + homework . user . firstname . to_s , encoding ) , Redmine :: CodesetUtil . from_utf8 ( homework . user . login , encoding ) ,
Redmine :: CodesetUtil . from_utf8 ( homework . user . user_extensions . student_id , encoding ) , Redmine :: CodesetUtil . from_utf8 ( homework . user . mail , encoding ) , Redmine :: CodesetUtil . from_utf8 ( homework . name , encoding ) ,
Redmine :: CodesetUtil . from_utf8 ( ( homework . t_score . nil? || ( homework . t_score && homework . t_score . to_i == 0 ) ) ? l ( :label_without_score ) : format ( " %.2f " , homework . t_score ) , encoding ) ,
Redmine :: CodesetUtil . from_utf8 ( homework . s_score . nil? ? l ( :label_without_score ) : format ( " %.2f " , homework . s_score ) , encoding ) , Redmine :: CodesetUtil . from_utf8 ( format_time ( homework . created_at ) , encoding ) ]
end
end
export
end
def homework_to_xls items
xls_report = StringIO . new
book = Spreadsheet :: Workbook . new
sheet1 = book . create_worksheet :name = > " homework "
blue = Spreadsheet :: Format . new :color = > :blue , :weight = > :bold , :size = > 10
sheet1 . row ( 0 ) . default_format = blue
sheet1 . row ( 0 ) . concat ( [ l ( :excel_user_id ) , l ( :excel_user_name ) , l ( :excel_nickname ) , l ( :excel_student_id ) , l ( :excel_mail ) , l ( :excel_homework_name ) ,
l ( :excel_t_score ) , l ( :excel_n_score ) , l ( :excel_commit_time ) ] )
count_row = 1
items . each do | homework |
sheet1 [ count_row , 0 ] = homework . user . id
sheet1 [ count_row , 1 ] = homework . user . lastname . to_s + homework . user . firstname . to_s
sheet1 [ count_row , 2 ] = homework . user . login
sheet1 [ count_row , 3 ] = homework . user . user_extensions . student_id
sheet1 [ count_row , 4 ] = homework . user . mail
sheet1 [ count_row , 5 ] = homework . name
sheet1 [ count_row , 6 ] = ( homework . t_score . nil? || ( homework . t_score && homework . t_score . to_i == 0 ) ) ? l ( :label_without_score ) : format ( " %.2f " , homework . t_score )
sheet1 [ count_row , 7 ] = homework . s_score . nil? ? l ( :label_without_score ) : format ( " %.2f " , homework . s_score )
sheet1 [ count_row , 8 ] = format_time ( homework . created_at )
count_row += 1
end
book . write xls_report
xls_report . string
end
2014-10-23 11:30:34 +08:00
end