课程作业列表当当前用户为课程学生时,输出分配给改学生匿评的作业集合

This commit is contained in:
z9hang 2015-01-30 16:58:05 +08:00
parent 2978d9020f
commit 6bd202e80a
4 changed files with 40 additions and 12 deletions

View File

@ -35,6 +35,11 @@ module Mobile
#作业状态 0:新建1已开启匿评2已关闭匿评 #作业状态 0:新建1已开启匿评2已关闭匿评
#只有作业启用了匿评功能且当前用户是课程老师且已提交的作品数量大于或等于2才能开启匿评 #只有作业启用了匿评功能且当前用户是课程老师且已提交的作品数量大于或等于2才能开启匿评
homework_expose :homework_state homework_expose :homework_state
expose :homework_for_anonymous_comments,using: Mobile::Entities::HomeworkAttach do |f, opt|
f[:homework_for_anonymous_comments] if f.is_a?(Hash) && f.key?(:homework_for_anonymous_comments)
end
end end
end end
end end

View File

@ -101,13 +101,7 @@ class HomeworkAttachController < ApplicationController
#获取学生匿评列表 #获取学生匿评列表
def get_student_batch_homework def get_student_batch_homework
@is_student_batch_homework = true @is_student_batch_homework = true
all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*, all_homework_list = get_student_batch_homework_list @bid,User.current
(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 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 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 = 0) AS m_score
FROM homework_attaches
INNER JOIN homework_evaluations ON homework_evaluations.homework_attach_id = homework_attaches.id
WHERE homework_attaches.bid_id = #{@bid.id} AND homework_evaluations.user_id = #{User.current.id} ORDER BY m_score DESC")
@cur_page = params[:page] || 1 @cur_page = params[:page] || 1
@cur_type = 4 @cur_type = 4
@homework_list = paginateHelper all_homework_list,10 @homework_list = paginateHelper all_homework_list,10

View File

@ -119,4 +119,15 @@ module HomeworkAttachHelper
#end #end
ary ary
end end
def get_student_batch_homework_list bid,user
student_batch_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).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 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 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 = 0) AS m_score
FROM homework_attaches
INNER JOIN homework_evaluations ON homework_evaluations.homework_attach_id = homework_attaches.id
WHERE homework_attaches.bid_id = #{bid.id} AND homework_evaluations.user_id = #{user.id} ORDER BY m_score DESC")
student_batch_homework_list
end
end end

View File

@ -1,6 +1,7 @@
class CoursesService class CoursesService
include ApplicationHelper include ApplicationHelper
include CoursesHelper include CoursesHelper
include HomeworkAttachHelper
#TODO:尚未整合权限系统 #TODO:尚未整合权限系统
#参数school_id为0或不传时返回所有课程否则返回对应学校的课程 #参数school_id为0或不传时返回所有课程否则返回对应学校的课程
#参数per_page_count分页功能每页显示的课程数 #参数per_page_count分页功能每页显示的课程数
@ -306,10 +307,8 @@ class CoursesService
bids = course.homeworks.order('deadline DESC') bids = course.homeworks.order('deadline DESC')
bids = bids.like(params[:name]) if params[:name].present? bids = bids.like(params[:name]) if params[:name].present?
homeworks = [] homeworks = []
if is_course_teacher(current_user,course) bids.each do |bid|
bids.each do |bid| homeworks << show_homework_info(course,bid,current_user,is_course_teacher(current_user,course))
homeworks << show_homework_info(course,bid)
end
end end
homeworks homeworks
else else
@ -318,7 +317,7 @@ class CoursesService
end end
private private
def show_homework_info course,bid def show_homework_info course,bid,current_user,is_course_teacher
author = bid.author.lastname + bid.author.firstname author = bid.author.lastname + bid.author.firstname
many_times = course.homeworks.index(bid) + 1 many_times = course.homeworks.index(bid) + 1
name = bid.name name = bid.name
@ -327,8 +326,27 @@ class CoursesService
description = bid.description description = bid.description
#if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2 #if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2
state = bid.comment_status state = bid.comment_status
unless is_course_teacher
homework_for_anonymous_comments = get_student_batch_homework_list bid,current_user
end
#end #end
open_anonymous_evaluation = bid.open_anonymous_evaluation 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,:homework_for_anonymous_comments => homework_for_anonymous_comments}
end
#显示作业列表的同时显示分配给当前学生匿评的作业
def show_homework_info_with_batch course,bid
author = bid.author.lastname + bid.author.firstname
many_times = course.homeworks.index(bid) + 1
name = bid.name
homework_count = bid.homeworks.count #已提交的作业数量
student_questions_count = bid.commit.nil? ? 0 : bid.commit
description = bid.description
#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, {: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} :description => description, :homework_state => state,:open_anonymous_evaluation => open_anonymous_evaluation}
end end