|
|
|
@ -26,36 +26,38 @@ class CoursesController < ApplicationController
|
|
|
|
|
|
|
|
|
|
def join
|
|
|
|
|
if User.current.logged?
|
|
|
|
|
course = Course.find_by_id params[:object_id]
|
|
|
|
|
if course
|
|
|
|
|
if course_endTime_timeout? course
|
|
|
|
|
@state = 2
|
|
|
|
|
else
|
|
|
|
|
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 = 4
|
|
|
|
|
end
|
|
|
|
|
cs = CoursesService.new
|
|
|
|
|
@state,course = cs.join_course params
|
|
|
|
|
#course = Course.find_by_id params[:object_id]
|
|
|
|
|
#if course
|
|
|
|
|
# if course_endTime_timeout? course
|
|
|
|
|
# @state = 2
|
|
|
|
|
# else
|
|
|
|
|
# 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 = 4
|
|
|
|
|
#end
|
|
|
|
|
else
|
|
|
|
|
@state = 5
|
|
|
|
|
@state = 5 #未登录
|
|
|
|
|
end
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => course, :object_id => params[:object_id]} }
|
|
|
|
|
end
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
@state = 4
|
|
|
|
|
@state = 4 #已经加入了课程
|
|
|
|
|
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 => nil, :object_id => nil} }
|
|
|
|
@ -64,15 +66,18 @@ class CoursesController < ApplicationController
|
|
|
|
|
|
|
|
|
|
def unjoin
|
|
|
|
|
if User.current.logged?
|
|
|
|
|
|
|
|
|
|
@member = Member.where('course_id = ? and user_id = ?', params[:object_id], User.current.id)
|
|
|
|
|
@member.first.destroy
|
|
|
|
|
|
|
|
|
|
joined = StudentsForCourse.where('student_id = ? and course_id = ?', User.current.id, params[:object_id])
|
|
|
|
|
joined.each do |join|
|
|
|
|
|
join.delete
|
|
|
|
|
end
|
|
|
|
|
#
|
|
|
|
|
# @member = Member.where('course_id = ? and user_id = ?', params[:object_id], User.current.id)
|
|
|
|
|
# @member.first.destroy
|
|
|
|
|
#
|
|
|
|
|
# joined = StudentsForCourse.where('student_id = ? and course_id = ?', User.current.id, params[:object_id])
|
|
|
|
|
# joined.each do |join|
|
|
|
|
|
# join.delete
|
|
|
|
|
# end
|
|
|
|
|
cs = CoursesService.new
|
|
|
|
|
cs.exit_course params,User.current
|
|
|
|
|
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]} }
|
|
|
|
@ -87,27 +92,16 @@ class CoursesController < ApplicationController
|
|
|
|
|
|
|
|
|
|
#更新课程信息
|
|
|
|
|
def update
|
|
|
|
|
@course.safe_attributes = params[:course]
|
|
|
|
|
@course.time = params[:time]
|
|
|
|
|
@course.term = params[:term]
|
|
|
|
|
@course.class_period = params[:class_period]
|
|
|
|
|
if @course.save
|
|
|
|
|
if params[:course][:is_public] == '0'
|
|
|
|
|
course_status = CourseStatus.find_by_course_id(@course.id)
|
|
|
|
|
course_status.destroy if course_status
|
|
|
|
|
elsif params[:course][:is_public] == '1'
|
|
|
|
|
course_status = CourseStatus.find_by_course_id(@course.id)
|
|
|
|
|
course_status.destroy if course_status
|
|
|
|
|
course_status = CourseStatus.create(:course_id => @course.id, :grade => 0)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html {
|
|
|
|
|
flash[:notice] = l(:notice_successful_update)
|
|
|
|
|
redirect_to settings_course_url(@course)
|
|
|
|
|
}
|
|
|
|
|
format.api { render_api_ok }
|
|
|
|
|
end
|
|
|
|
|
cs = CoursesService.new
|
|
|
|
|
@course = cs.edit_course params,@course
|
|
|
|
|
if @course.errors.full_messages.count <= 0
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html {
|
|
|
|
|
flash[:notice] = l(:notice_successful_update)
|
|
|
|
|
redirect_to settings_course_url(@course)
|
|
|
|
|
}
|
|
|
|
|
format.api { render_api_ok }
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html {
|
|
|
|
@ -117,6 +111,36 @@ class CoursesController < ApplicationController
|
|
|
|
|
format.api { render_validation_errors(@course) }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
#@course.safe_attributes = params[:course]
|
|
|
|
|
#@course.time = params[:time]
|
|
|
|
|
#@course.term = params[:term]
|
|
|
|
|
#@course.class_period = params[:class_period]
|
|
|
|
|
#if @course.save
|
|
|
|
|
# if params[:course][:is_public] == '0'
|
|
|
|
|
# course_status = CourseStatus.find_by_course_id(@course.id)
|
|
|
|
|
# course_status.destroy if course_status
|
|
|
|
|
# elsif params[:course][:is_public] == '1'
|
|
|
|
|
# course_status = CourseStatus.find_by_course_id(@course.id)
|
|
|
|
|
# course_status.destroy if course_status
|
|
|
|
|
# course_status = CourseStatus.create(:course_id => @course.id, :grade => 0)
|
|
|
|
|
# end
|
|
|
|
|
#
|
|
|
|
|
# respond_to do |format|
|
|
|
|
|
# format.html {
|
|
|
|
|
# flash[:notice] = l(:notice_successful_update)
|
|
|
|
|
# redirect_to settings_course_url(@course)
|
|
|
|
|
# }
|
|
|
|
|
# format.api { render_api_ok }
|
|
|
|
|
# end
|
|
|
|
|
#else
|
|
|
|
|
# respond_to do |format|
|
|
|
|
|
# format.html {
|
|
|
|
|
# settings
|
|
|
|
|
# render :action => 'settings'
|
|
|
|
|
# }
|
|
|
|
|
# format.api { render_validation_errors(@course) }
|
|
|
|
|
# end
|
|
|
|
|
#end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def new_join
|
|
|
|
|