|
|
|
@ -21,30 +21,37 @@ class CoursesController < ApplicationController
|
|
|
|
|
before_filter :toggleCourse, only: [:finishcourse, :restartcourse]
|
|
|
|
|
|
|
|
|
|
before_filter :require_login, :only => [:join, :unjoin]
|
|
|
|
|
before_filter :allow_join, :only => [:join]
|
|
|
|
|
#before_filter :allow_join, :only => [:join]
|
|
|
|
|
|
|
|
|
|
def join
|
|
|
|
|
if User.current.logged?
|
|
|
|
|
course = Course.find(params[:object_id])
|
|
|
|
|
unless User.current.member_of_course? course
|
|
|
|
|
if params[:course_password] == course.password
|
|
|
|
|
members = []
|
|
|
|
|
members << Member.new(:role_ids => [10], :user_id => User.current.id)
|
|
|
|
|
course.members << members
|
|
|
|
|
StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id])
|
|
|
|
|
@state = 0
|
|
|
|
|
course = Course.find_by_id params[:object_id]
|
|
|
|
|
if course
|
|
|
|
|
if course_endTime_timeout? course
|
|
|
|
|
@state = 2
|
|
|
|
|
else
|
|
|
|
|
@state = 1
|
|
|
|
|
if User.current.member_of_course?(course)
|
|
|
|
|
@state = 3
|
|
|
|
|
else
|
|
|
|
|
if params[:course_password] == course.password
|
|
|
|
|
members = []
|
|
|
|
|
members << Member.new(:role_ids => [10], :user_id => User.current.id)
|
|
|
|
|
course.members << members
|
|
|
|
|
StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id])
|
|
|
|
|
@state = 0
|
|
|
|
|
else
|
|
|
|
|
@state = 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
@state = 3
|
|
|
|
|
@state = 4
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
@state = 4
|
|
|
|
|
@state = 5
|
|
|
|
|
end
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
|
|
|
|
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} }
|
|
|
|
|
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => course, :object_id => params[:object_id]} }
|
|
|
|
|
end
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
@state = 4
|
|
|
|
@ -424,9 +431,7 @@ class CoursesController < ApplicationController
|
|
|
|
|
@course_type = params[:course_type]
|
|
|
|
|
@school_id = params[:school_id]
|
|
|
|
|
per_page_option = 10
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if @school_id == "0" or @school_id.nil?
|
|
|
|
|
if @school_id == "0" || @school_id.nil?
|
|
|
|
|
@courses_all = Course.active.visible.
|
|
|
|
|
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id")
|
|
|
|
|
else
|
|
|
|
@ -434,49 +439,37 @@ class CoursesController < ApplicationController
|
|
|
|
|
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id").
|
|
|
|
|
where("#{Course.table_name}.school_id = ?", @school_id)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@course_count = @courses_all.count
|
|
|
|
|
@course_pages = Paginator.new @course_count, per_page_option, params['page']
|
|
|
|
|
|
|
|
|
|
@course_activity_count=Hash.new
|
|
|
|
|
@courses_all.each do |course|
|
|
|
|
|
@course_activity_count[course.id]=0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case params[:course_sort_type]
|
|
|
|
|
when '0'
|
|
|
|
|
@courses = @courses_all.order("created_at desc")
|
|
|
|
|
@s_type = 0
|
|
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
|
|
|
|
|
|
|
|
|
@course_activity_count=get_course_activity @courses, @course_activity_count
|
|
|
|
|
@course_activity_count=get_course_activity @courses, @course_activity_count
|
|
|
|
|
when '1'
|
|
|
|
|
@courses = @courses_all.order("course_ac_para desc")
|
|
|
|
|
@s_type = 1
|
|
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
|
|
|
|
|
|
|
|
|
@course_activity_count=get_course_activity @courses, @course_activity_count
|
|
|
|
|
when '2'
|
|
|
|
|
@courses = @courses_all.order("watchers_count desc")
|
|
|
|
|
@s_type = 2
|
|
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
|
|
|
|
|
|
|
|
|
@course_activity_count=get_course_activity @courses, @course_activity_count
|
|
|
|
|
|
|
|
|
|
when '3'
|
|
|
|
|
|
|
|
|
|
@course_activity_count=get_course_activity @courses_all, @course_activity_count
|
|
|
|
|
|
|
|
|
|
@courses=handle_course @courses_all, @course_activity_count
|
|
|
|
|
|
|
|
|
|
@s_type = 3
|
|
|
|
|
@courses = @courses[@course_pages.offset, @course_pages.per_page]
|
|
|
|
|
else
|
|
|
|
|
@s_type = 0
|
|
|
|
|
@courses = @courses_all.order("created_at desc")
|
|
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
|
|
|
|
|
|
|
|
|
@course_activity_count=get_course_activity @courses, @course_activity_count
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -518,18 +511,14 @@ class CoursesController < ApplicationController
|
|
|
|
|
# 新建作业
|
|
|
|
|
def new_homework
|
|
|
|
|
@homework = Bid.new
|
|
|
|
|
@homework.proportion
|
|
|
|
|
@homework.safe_attributes = params[:bid]
|
|
|
|
|
if (User.current.logged? && User.current.member_of_course?(Course.find params[:id] ))
|
|
|
|
|
render :layout => 'base_courses'
|
|
|
|
|
else
|
|
|
|
|
render_403
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def toggleCourse
|
|
|
|
|
@course_prefs = Course.find_by_extra(@course.extra)
|
|
|
|
|
unless (@course_prefs.teacher == User.current || User.current.admin?)
|
|
|
|
@ -697,8 +686,8 @@ class CoursesController < ApplicationController
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def allow_join
|
|
|
|
|
if course_endTime_timeout? Course.find(params[:object_id])
|
|
|
|
|
def allow_join course
|
|
|
|
|
if course_endTime_timeout? course
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.js {
|
|
|
|
|
@state = 2
|
|
|
|
@ -719,7 +708,4 @@ class CoursesController < ApplicationController
|
|
|
|
|
render_404
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|