Merge remote-tracking branch 'origin/szzh' into szzh

This commit is contained in:
lizanle 2015-10-30 17:28:45 +08:00
commit 55db83d31c
2 changed files with 16 additions and 1770 deletions

View File

@ -368,12 +368,22 @@ class UsersController < ApplicationController
if User.current == @user
@page = params[:page] ? params[:page].to_i + 1 : 0
user_course_ids = @user.courses.empty? ? "(-1)" :"(" + @user.courses.visible.map{|course| course.id}.join(",") + ")"
@is_teacher = User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true)
if @is_teacher
@homework_commons = HomeworkCommon.where("course_id in #{user_course_ids}").order("created_at desc").limit(10).offset(@page * 10)
else
@homework_commons = HomeworkCommon.where("course_id in #{user_course_ids} and publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10)
#判断当前用户在当前课程的身份
visibleCourse = @user.courses.empty? ? [] : @user.courses.visible
homework_ids = []
visibleCourse.each do |course|
if User.current.allowed_to?(:as_teacher,course)
homeworks = HomeworkCommon.where("course_id = #{course.id}")
homework_ids << homeworks.pluck(:id) unless homeworks.empty?
else
homeworks = HomeworkCommon.where("course_id = #{course.id} and publish_time <= '#{Date.today}'")
homework_ids << homeworks.pluck(:id) unless homeworks.empty?
end
end
visible_homework_ids = homework_ids.size == 0 ? "(-1)" :"(" + homework_ids.join(",") + ")"
@homework_commons = HomeworkCommon.where("id in #{visible_homework_ids}").order("created_at desc").limit(10).offset(@page * 10)
@is_teacher = User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true)
@is_in_course = params[:is_in_course].to_i || 0
respond_to do |format|
format.js

File diff suppressed because it is too large Load Diff