1.修改下载作业时的错误

2.修改判断是不是为当前课程学生、老师的方法
This commit is contained in:
sw 2014-06-10 09:56:00 +08:00
parent 26b933dddb
commit 787e043650
4 changed files with 24 additions and 49 deletions

View File

@ -417,7 +417,7 @@ class BidsController < ApplicationController
@homework = HomeworkAttach.new
#@homework_list = @bid.homeworks
#增加作业按评分排序,
@homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC')
@homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC').order("#{HomeworkAttach.table_name}.created_at ASC")
if params[:student_id].present?
@temp = []
@homework_list.each do |pro|

View File

@ -1,6 +1,6 @@
class ZipdownController < ApplicationController
#查找项目(课程)
before_filter :find_project_by_bid_id, :only => [:assort,:download_user_homework]
before_filter :find_project_by_bid_id, :only => [:assort]
#检查权限
#勿删 before_filter :authorize, :only => [:assort,:download_user_homework]
SAVE_FOLDER = "#{Rails.root}/files"

View File

@ -138,46 +138,33 @@ module CoursesHelper
end
#判断制定用户是不是当前课程的老师
def is_course_teacher (user,course)
#people = []
#course.members.includes(:roles, :user).each do |member|
# role_id = member.roles.first.id
# if TeacherRoles.include? role_id
# people << member.user
course.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and members.user_id = #{user.id}", {:role_id => TeacherRoles}).count != 0
#修改为根据用户是否有发布任务的权限来判断用户是否是课程的老师
#is_teacher = false
#@membership = user.memberships.all(:conditions => Project.visible_condition(User.current))
#@membership.each do |membership|
# unless(membership.project.project_type==0)
# if user.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false)
# is_teacher = true
# end
# end
#end
#people.include?(user)
#修改为根据用户是否有发布任务的权限来判断用户是否是课程的老师
is_teacher = false
@membership = user.memberships.all(:conditions => Project.visible_condition(User.current))
@membership.each do |membership|
unless(membership.project.project_type==0)
if user.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false)
is_teacher = true
end
end
end
is_teacher
#is_teacher
end
#当前用户是不是指定课程的学生
def is_cur_course_student? course
#people = []
#course.members.includes(:roles, :user).each do |member|
# if StudentRoles.include? member.roles.first.id
# people << member.user
def is_cur_course_student course
course.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and members.user_id = #{User.current.id}", {:role_id => StudentRoles}).count != 0
#修改:能新建占位且不能新建任务的角色判定为学生
#is_student = false
#@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
#@membership.each do |membership|
# unless(membership.project.project_type==0)
# if !User.current.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false) && User.current.allowed_to?({:controller => "homework_attach", :action => "new"}, membership.project, :global => false)
# is_student = true
# end
# end
#end
#people.include?(User.current)
#修改:能新建占位且不能新建任务的角色判定为学生
is_student = false
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
@membership.each do |membership|
unless(membership.project.project_type==0)
if !User.current.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false) && User.current.allowed_to?({:controller => "homework_attach", :action => "new"}, membership.project, :global => false)
is_student = true
end
end
end
is_student
#is_student
end
#获取当前用户在指定作业下提交的作业的集合
def cur_user_homework_for_bid bid
@ -190,15 +177,4 @@ module CoursesHelper
seem_count = homework.rates(:quality).where("rater_id = ?",User.current).count
seem_count > 0
end
#获取指定作业的平均评分
def homework_score homework
stars_reates = homework.rates(:quality)
sum = 0
stars_reates.each do |star_reates|
sum = sum + star_reates.stars
end
stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count
format("%.2f", sum * 1.0 / stars_reates_count)
end
end

View File

@ -1,9 +1,8 @@
<!-- fq -->
<% is_student = is_cur_course_student? @bid.courses.first %>
<% is_student = is_cur_course_student(@bid.courses.first) %>
<% is_teacher = is_course_teacher User.current,@bid.courses.first %>
<!-- 当is_evaluation为1或者null(null主要是为了兼容前面数据)时代表启用互评功能2表示未启用 -->
<% is_evaluation = @bid.is_evaluation == 1 || @bid.is_evaluation == nil %>
<%= form_tag(:controller => 'bids', :action => "show_project", :method => :get) do %>
<div class="project-search-block">
<table width="100%" valign="center">