@ -13,6 +13,7 @@ class CoursesController < ApplicationController
include ApplicationHelper
helper SyllabusesHelper
before_filter :local_exam , :except = > [ :show ]
# before_filter :auth_login1, :only => [:show, :course_activity, :feedback]
if Redmine :: Configuration [ 'gitlab_address' ] . include? ( " test " )
skip_before_filter :verify_authenticity_token , :only = > [ :update_course_module , :join_course_multi_role ]
@ -1617,76 +1618,78 @@ class CoursesController < ApplicationController
end
def show
# 被删除的课程只有超级管理员才能看到, is_delete为1的时候, 标记课程被删除
# if @course.is_delete == 1 && !User.current.admin?
# render_403
# return
# end
#更新创建课程消息状态
# course_request_messages = CourseMessage.where(:user_id => User.current.id, :course_id => @course.id, :course_message_type => ["CourseRequestDealResult", "Course"], :viewed => false)
# course_request_messages.update_all(:viewed => true)
# create_course_messages = @course.course_messages.where("user_id =? and course_message_type =? and course_id =? and viewed =?", User.current.id, 'Course', @course.id, 0)
# create_course_messages.update_all(:viewed => true)
#更新申请结果反馈消息的状态
# course_request_messages = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?", User.current.id, @course.id, 'CourseRequestDealResult', false)
# course_request_messages.update_all(:viewed => true)
@course_modules = @course . course_modules . where ( :hidden = > 0 )
course_module_type = @course_modules . map ( & :module_type )
@is_teacher = User . current . allowed_to? ( :as_teacher , @course ) || User . current . admin?
if User . current . member_of_course? ( @course ) && ! @is_teacher
member = @course . members . where ( :user_id = > User . current . id ) . first
if member . try ( :course_group_id ) . to_i == 0
common_homework_ids = @course . homework_commons . where ( " homework_type = 1 and unified_setting = 1 " )
shixun_homework_ids = @course . homework_commons . where ( " homework_type = 4 and unified_setting = 1 " )
group_homework_ids = @course . homework_commons . where ( " homework_type = 3 and unified_setting = 1 " )
exercise_ids = @course . exercises . where ( " unified_setting = 1 " )
poll_ids = @course . polls . where ( " unified_setting = 1 " )
atta_ids = @course . attachments . where ( " unified_setting = 1 " )
if LocalSetting . first . try ( :exam ) && ! User . current . admin?
else
# 被删除的课程只有超级管理员才能看到, is_delete为1的时候, 标记课程被删除
# if @course.is_delete == 1 && !User.current.admin?
# render_403
# return
# end
#更新创建课程消息状态
# course_request_messages = CourseMessage.where(:user_id => User.current.id, :course_id => @course.id, :course_message_type => ["CourseRequestDealResult", "Course"], :viewed => false)
# course_request_messages.update_all(:viewed => true)
# create_course_messages = @course.course_messages.where("user_id =? and course_message_type =? and course_id =? and viewed =?", User.current.id, 'Course', @course.id, 0)
# create_course_messages.update_all(:viewed => true)
#更新申请结果反馈消息的状态
# course_request_messages = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?", User.current.id, @course.id, 'CourseRequestDealResult', false)
# course_request_messages.update_all(:viewed => true)
@course_modules = @course . course_modules . where ( :hidden = > 0 )
course_module_type = @course_modules . map ( & :module_type )
@is_teacher = User . current . allowed_to? ( :as_teacher , @course ) || User . current . admin?
if User . current . member_of_course? ( @course ) && ! @is_teacher
member = @course . members . where ( :user_id = > User . current . id ) . first
if member . try ( :course_group_id ) . to_i == 0
common_homework_ids = @course . homework_commons . where ( " homework_type = 1 and unified_setting = 1 " )
shixun_homework_ids = @course . homework_commons . where ( " homework_type = 4 and unified_setting = 1 " )
group_homework_ids = @course . homework_commons . where ( " homework_type = 3 and unified_setting = 1 " )
exercise_ids = @course . exercises . where ( " unified_setting = 1 " )
poll_ids = @course . polls . where ( " unified_setting = 1 " )
atta_ids = @course . attachments . where ( " unified_setting = 1 " )
else
not_homework_ids = @course . homework_group_settings . where ( " course_group_id = #{ member . try ( :course_group_id ) } and (publish_time > ' #{ Time . now } ' or publish_time is null) " )
not_homework_ids = not_homework_ids . blank? ? " (-1) " : " ( " + not_homework_ids . map ( & :homework_common_id ) . join ( " , " ) + " ) "
common_homework_ids = @course . homework_commons . where ( " homework_type = 1 and id not in #{ not_homework_ids } " )
shixun_homework_ids = @course . homework_commons . where ( " homework_type = 4 and id not in #{ not_homework_ids } " )
group_homework_ids = @course . homework_commons . where ( " homework_type = 3 and id not in #{ not_homework_ids } " )
not_exercise_ids = @course . exercise_group_settings . where ( " course_group_id = #{ member . try ( :course_group_id ) } and (publish_time > ' #{ Time . now } ' or publish_time is null) " )
not_exercise_ids = not_exercise_ids . blank? ? " (-1) " : " ( " + not_exercise_ids . map ( & :exercise_id ) . join ( " , " ) + " ) "
exercise_ids = @course . exercises . where ( " id not in #{ not_exercise_ids } " )
not_poll_ids = @course . poll_group_settings . where ( " course_group_id = #{ member . try ( :course_group_id ) } and (publish_time > ' #{ Time . now } ' or publish_time is null) " )
not_poll_ids = not_poll_ids . blank? ? " (-1) " : " ( " + not_poll_ids . map ( & :poll_id ) . join ( " , " ) + " ) "
poll_ids = @course . polls . where ( " id not in #{ not_poll_ids } " )
not_atta_ids = @course . attachment_group_settings . where ( " course_group_id = #{ member . try ( :course_group_id ) } and publish_time > ' #{ Time . now } ' " )
not_atta_ids = not_atta_ids . blank? ? " (-1) " : " ( " + not_atta_ids . map ( & :attachment_id ) . join ( " , " ) + " ) "
atta_ids = @course . attachments . where ( " id not in #{ not_atta_ids } " )
end
else
not_homework_ids = @course . homework_group_settings . where ( " course_group_id = #{ member . try ( :course_group_id ) } and (publish_time > ' #{ Time . now } ' or publish_time is null) " )
not_homework_ids = not_homework_ids . blank? ? " (-1) " : " ( " + not_homework_ids . map ( & :homework_common_id ) . join ( " , " ) + " ) "
common_homework_ids = @course . homework_commons . where ( " homework_type = 1 and id not in #{ not_homework_ids } " )
shixun_homework_ids = @course . homework_commons . where ( " homework_type = 4 and id not in #{ not_homework_ids } " )
group_homework_ids = @course . homework_commons . where ( " homework_type = 3 and id not in #{ not_homework_ids } " )
not_exercise_ids = @course . exercise_group_settings . where ( " course_group_id = #{ member . try ( :course_group_id ) } and (publish_time > ' #{ Time . now } ' or publish_time is null) " )
not_exercise_ids = not_exercise_ids . blank? ? " (-1) " : " ( " + not_exercise_ids . map ( & :exercise_id ) . join ( " , " ) + " ) "
exercise_ids = @course . exercises . where ( " id not in #{ not_exercise_ids } " )
not_poll_ids = @course . poll_group_settings . where ( " course_group_id = #{ member . try ( :course_group_id ) } and (publish_time > ' #{ Time . now } ' or publish_time is null) " )
not_poll_ids = not_poll_ids . blank? ? " (-1) " : " ( " + not_poll_ids . map ( & :poll_id ) . join ( " , " ) + " ) "
poll_ids = @course . polls . where ( " id not in #{ not_poll_ids } " )
not_atta_ids = @course . attachment_group_settings . where ( " course_group_id = #{ member . try ( :course_group_id ) } and publish_time > ' #{ Time . now } ' " )
not_atta_ids = not_atta_ids . blank? ? " (-1) " : " ( " + not_atta_ids . map ( & :attachment_id ) . join ( " , " ) + " ) "
atta_ids = @course . attachments . where ( " id not in #{ not_atta_ids } " )
common_homework_ids = @course . homework_commons . where ( " homework_type = 1 " )
shixun_homework_ids = @course . homework_commons . where ( " homework_type = 4 " )
group_homework_ids = @course . homework_commons . where ( " homework_type = 3 " )
exercise_ids = @course . exercises
poll_ids = @course . polls
atta_ids = @course . attachments
end
common_homework_ids = common_homework_ids . blank? ? " (-1) " : " ( " + common_homework_ids . map ( & :id ) . join ( " , " ) + " ) "
shixun_homework_ids = shixun_homework_ids . blank? ? " (-1) " : " ( " + shixun_homework_ids . map ( & :id ) . join ( " , " ) + " ) "
group_homework_ids = group_homework_ids . blank? ? " (-1) " : " ( " + group_homework_ids . map ( & :id ) . join ( " , " ) + " ) "
exercise_ids = exercise_ids . blank? ? " (-1) " : " ( " + exercise_ids . map ( & :id ) . join ( " , " ) + " ) "
poll_ids = poll_ids . blank? ? " (-1) " : " ( " + poll_ids . map ( & :id ) . join ( " , " ) + " ) "
atta_ids = atta_ids . blank? ? " (-1) " : " ( " + atta_ids . map ( & :id ) . join ( " , " ) + " ) "
if @is_teacher && course_module_type . include? ( 'board' )
course_act_type = " ('Message', 'JoinCourse') "
elsif @is_teacher
course_act_type = " ('JoinCourse') "
elsif course_module_type . include? ( 'board' )
course_act_type = " ('Message') "
else
course_act_type = " ('0') "
end
else
common_homework_ids = @course . homework_commons . where ( " homework_type = 1 " )
shixun_homework_ids = @course . homework_commons . where ( " homework_type = 4 " )
group_homework_ids = @course . homework_commons . where ( " homework_type = 3 " )
exercise_ids = @course . exercises
poll_ids = @course . polls
atta_ids = @course . attachments
end
common_homework_ids = common_homework_ids . blank? ? " (-1) " : " ( " + common_homework_ids . map ( & :id ) . join ( " , " ) + " ) "
shixun_homework_ids = shixun_homework_ids . blank? ? " (-1) " : " ( " + shixun_homework_ids . map ( & :id ) . join ( " , " ) + " ) "
group_homework_ids = group_homework_ids . blank? ? " (-1) " : " ( " + group_homework_ids . map ( & :id ) . join ( " , " ) + " ) "
exercise_ids = exercise_ids . blank? ? " (-1) " : " ( " + exercise_ids . map ( & :id ) . join ( " , " ) + " ) "
poll_ids = poll_ids . blank? ? " (-1) " : " ( " + poll_ids . map ( & :id ) . join ( " , " ) + " ) "
atta_ids = atta_ids . blank? ? " (-1) " : " ( " + atta_ids . map ( & :id ) . join ( " , " ) + " ) "
if @is_teacher && course_module_type . include? ( 'board' )
course_act_type = " ('Message', 'JoinCourse') "
elsif @is_teacher
course_act_type = " ('JoinCourse') "
elsif course_module_type . include? ( 'board' )
course_act_type = " ('Message') "
else
course_act_type = " ('0') "
end
sql_str = " course_act_type in #{ course_act_type } "
@course_modules . each do | course_module |
case course_module . module_type
sql_str = " course_act_type in #{ course_act_type } "
@course_modules . each do | course_module |
case course_module . module_type
when " shixun_homework "
sql_str += " or (course_act_type = 'HomeworkCommon' && course_act_id in #{ shixun_homework_ids } ) "
when " common_homework "
@ -1701,11 +1704,11 @@ class CoursesController < ApplicationController
sql_str += " or (course_act_type = 'Poll' && course_act_id in #{ poll_ids } ) "
when " attachment "
sql_str += " or (course_act_type = 'Attachment' && course_act_id in #{ atta_ids } ) "
end
end
end
@page = params [ :page ] ? params [ :page ] . to_i + 1 : 0
if params [ :type ] . present?
case params [ :type ]
@page = params [ :page ] ? params [ :page ] . to_i + 1 : 0
if params [ :type ] . present?
case params [ :type ]
when " common_homework "
# homework_ids = @course.homework_commons.where("homework_type = 1 and id in #{homework_ids}")
@course_activities = @course . course_activities . where ( " course_act_type = 'HomeworkCommon' and course_act_id in #{ common_homework_ids } " ) . order ( 'updated_at desc' )
@ -1735,16 +1738,17 @@ class CoursesController < ApplicationController
@course_activities = @course . course_activities . where ( " course_act_type = 'JournalsForMessage' " ) . order ( 'updated_at desc' )
else
@course_activities = @course . course_activities . where ( " #{ sql_str } " ) . order ( 'updated_at desc' )
end
else
@course_activities = @course . course_activities . where ( " #{ sql_str } " ) . order ( 'updated_at desc' )
end
else
@course_activities = @course . course_activities . where ( " #{ sql_str } " ) . order ( 'updated_at desc' )
end
@course_activities_count = @course_activities . size
@course_activities = @course_activities . limit ( 10 ) . offset ( @page * 10 )
@type = params [ :type ]
@course_activities_count = @course_activities . size
@course_activities = @course_activities . limit ( 10 ) . offset ( @page * 10 )
@type = params [ :type ]
@left_nav_type = 1
@show_page = true
@left_nav_type = 1
@show_page = true
end
respond_to do | format |
format . js
format . html { render :layout = > 'base_courses' }