@ -22,6 +22,7 @@ class HomeworkAttachController < ApplicationController
#获取未批作业列表
#获取未批作业列表
def get_not_batch_homework
def get_not_batch_homework
@not_batch_homework = true
@not_batch_homework = true
@search_name = params [ :name ]
sort , direction = params [ :sort ] || " s_socre " , params [ :direction ] || " desc "
sort , direction = params [ :sort ] || " s_socre " , params [ :direction ] || " desc "
get_not_batch_homework_list sort , direction , @bid . id
get_not_batch_homework_list sort , direction , @bid . id
@cur_page = params [ :page ] || 1
@cur_page = params [ :page ] || 1
@ -39,6 +40,7 @@ class HomeworkAttachController < ApplicationController
#获取已评作业列表
#获取已评作业列表
def get_batch_homeworks
def get_batch_homeworks
@search_name = params [ :name ]
sort , direction = params [ :sort ] || " s_socre " , params [ :direction ] || " desc "
sort , direction = params [ :sort ] || " s_socre " , params [ :direction ] || " desc "
@is_batch_homeworks = true
@is_batch_homeworks = true
if sort == 't_socre'
if sort == 't_socre'
@ -49,11 +51,12 @@ class HomeworkAttachController < ApplicationController
order_by = " created_at #{ direction } "
order_by = " created_at #{ direction } "
end
end
all_homework_list = HomeworkAttach . eager_load ( :attachments , :user , :rate_averages ) . find_by_sql ( " SELECT * FROM (SELECT homework_attaches.*,
all_homework_list = HomeworkAttach . eager_load ( :attachments , :user , :rate_averages ) . find_by_sql ( " SELECT * FROM (SELECT homework_attaches.*,
( 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 ,
( 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 AND stars > 0 ORDER BY updated_at DESC limit 0 , 1 ) AS t_score ,
( 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
( 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
FROM homework_attaches WHERE bid_id = #{@bid.id}
FROM homework_attaches WHERE bid_id = #{@bid.id}
ORDER BY #{order_by}) AS table1
ORDER BY #{order_by}) AS table1
WHERE table1 . t_score IS NOT NULL " )
WHERE table1 . t_score IS NOT NULL " )
all_homework_list = search_homework_member ( all_homework_list , @search_name . to_s . downcase ) if @search_name
@cur_page = params [ :page ] || 1
@cur_page = params [ :page ] || 1
@cur_type = 2
@cur_type = 2
@homework_list = paginateHelper all_homework_list , 10
@homework_list = paginateHelper all_homework_list , 10
@ -72,6 +75,7 @@ class HomeworkAttachController < ApplicationController
#获取所有作业列表
#获取所有作业列表
def get_homeworks
def get_homeworks
@is_all_homeworks = true
@is_all_homeworks = true
@search_name = params [ :name ]
sort , direction = params [ :sort ] || " s_socre " , params [ :direction ] || " desc "
sort , direction = params [ :sort ] || " s_socre " , params [ :direction ] || " desc "
if sort == 't_socre'
if sort == 't_socre'
order_by = " t_score #{ direction } "
order_by = " t_score #{ direction } "
@ -85,6 +89,8 @@ class HomeworkAttachController < ApplicationController
( 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
( 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
FROM homework_attaches WHERE bid_id = #{@bid.id}
FROM homework_attaches WHERE bid_id = #{@bid.id}
ORDER BY #{order_by}")
ORDER BY #{order_by}")
all_homework_list = search_homework_member ( all_homework_list , @search_name . to_s . downcase ) if @search_name
@cur_page = params [ :page ] || 1
@cur_page = params [ :page ] || 1
@cur_type = 3
@cur_type = 3
@homework_list = paginateHelper all_homework_list , 10
@homework_list = paginateHelper all_homework_list , 10
@ -477,7 +483,7 @@ class HomeworkAttachController < ApplicationController
get_not_batch_homework_list params [ :cur_sort ] || " s_socre " , params [ :cur_direction ] || " desc " , @homework . bid_id
get_not_batch_homework_list params [ :cur_sort ] || " s_socre " , params [ :cur_direction ] || " desc " , @homework . bid_id
elsif @cur_type == " 2 " #老师已批列表
elsif @cur_type == " 2 " #老师已批列表
@result_homework = HomeworkAttach . find_by_sql ( " SELECT homework_attaches.*,
@result_homework = HomeworkAttach . find_by_sql ( " SELECT homework_attaches.*,
( 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 ,
( 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 AND stars > 0 ORDER BY updated_at DESC limit 0 , 1 ) AS t_score ,
( 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
( 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
FROM homework_attaches WHERE id = #{@homework.id}").first
FROM homework_attaches WHERE id = #{@homework.id}").first
elsif @cur_type == " 3 " #全部作业列表
elsif @cur_type == " 3 " #全部作业列表
@ -538,6 +544,14 @@ class HomeworkAttachController < ApplicationController
end
end
private
private
#根据条件过滤作业结果
def search_homework_member homeworks , name
select_homework = homeworks . select { | homework |
homework . user [ :login ] . to_s . downcase . include? ( name ) || homework . user . user_extensions [ :student_id ] . to_s . downcase . include? ( name ) || ( homework . user [ :lastname ] . to_s . downcase + homework . user [ :firstname ] . to_s . downcase ) . include? ( name )
}
select_homework
end
#验证是否显示课程
#验证是否显示课程
def can_show_course
def can_show_course
@first_page = FirstPage . find_by_page_type ( 'project' )
@first_page = FirstPage . find_by_page_type ( 'project' )
@ -596,7 +610,8 @@ class HomeworkAttachController < ApplicationController
( 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
( 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
FROM homework_attaches WHERE bid_id = #{bid_id}
FROM homework_attaches WHERE bid_id = #{bid_id}
ORDER BY #{order_by}) AS table1
ORDER BY #{order_by}) AS table1
WHERE table1 . t_score IS NULL " )
WHERE table1 . t_score IS NULL OR table1 . t_score = 0 " )
@all_homework_list = search_homework_member ( @all_homework_list , @search_name . to_s . downcase ) if @search_name
@homework_list = paginateHelper @all_homework_list , 10
@homework_list = paginateHelper @all_homework_list , 10
end
end