|
|
@ -263,37 +263,14 @@ class CoursesController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
def create
|
|
|
|
if User.current.user_extensions.identity
|
|
|
|
cs = CoursesService.new
|
|
|
|
@course = Course.new
|
|
|
|
@course = cs.create_course params
|
|
|
|
@course.extra='course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s
|
|
|
|
if @course.new_record?
|
|
|
|
@course.safe_attributes = params[:course]
|
|
|
|
respond_to do |format|
|
|
|
|
@course.tea_id = User.current.id
|
|
|
|
format.html { render :action => 'new', :layout => 'base' } #Added by young
|
|
|
|
# added by bai
|
|
|
|
format.api { render_validation_errors(@course) }
|
|
|
|
@course.term = params[:term]
|
|
|
|
|
|
|
|
@course.time = params[:time]
|
|
|
|
|
|
|
|
#@course.school_id = params[:occupation]
|
|
|
|
|
|
|
|
@course.school_id = User.current.user_extensions.school_id
|
|
|
|
|
|
|
|
@course.setup_time = params[:setup_time]
|
|
|
|
|
|
|
|
@course.endup_time = params[:endup_time]
|
|
|
|
|
|
|
|
@course.class_period = params[:class_period]
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
@issue_custom_fields = IssueCustomField.sorted.all
|
|
|
|
|
|
|
|
@trackers = Tracker.sorted.all
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if @course.save
|
|
|
|
|
|
|
|
#unless User.current.admin?
|
|
|
|
|
|
|
|
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
|
|
|
|
|
|
|
|
m = Member.new(:user => User.current, :roles => [r])
|
|
|
|
|
|
|
|
m.project_id = -1
|
|
|
|
|
|
|
|
course = CourseInfos.new(:user_id => User.current.id, :course_id => @course.id)
|
|
|
|
|
|
|
|
#user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id)
|
|
|
|
|
|
|
|
if params[:course][:is_public] == '1'
|
|
|
|
|
|
|
|
course_status = CourseStatus.create(:course_id => @course.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :course_type => @course_tag)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
@course.members << m
|
|
|
|
|
|
|
|
@course.course_infos << course
|
|
|
|
|
|
|
|
#end
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
format.html {
|
|
|
|
flash[:notice] = l(:notice_successful_create)
|
|
|
|
flash[:notice] = l(:notice_successful_create)
|
|
|
@ -307,13 +284,58 @@ class CoursesController < ApplicationController
|
|
|
|
}
|
|
|
|
}
|
|
|
|
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) }
|
|
|
|
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
|
|
|
|
#@course.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
|
|
format.html { render :action => 'new', :layout => 'base' } #Added by young
|
|
|
|
|
|
|
|
format.api { render_validation_errors(@course) }
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#if User.current.user_extensions.identity
|
|
|
|
|
|
|
|
# @course = Course.new
|
|
|
|
|
|
|
|
# @course.extra='course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s
|
|
|
|
|
|
|
|
# @course.safe_attributes = params[:course]
|
|
|
|
|
|
|
|
# @course.tea_id = User.current.id
|
|
|
|
|
|
|
|
# # added by bai
|
|
|
|
|
|
|
|
# @course.term = params[:term]
|
|
|
|
|
|
|
|
# @course.time = params[:time]
|
|
|
|
|
|
|
|
# #@course.school_id = params[:occupation]
|
|
|
|
|
|
|
|
# @course.school_id = User.current.user_extensions.school_id
|
|
|
|
|
|
|
|
# @course.setup_time = params[:setup_time]
|
|
|
|
|
|
|
|
# @course.endup_time = params[:endup_time]
|
|
|
|
|
|
|
|
# @course.class_period = params[:class_period]
|
|
|
|
|
|
|
|
#end
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
#@issue_custom_fields = IssueCustomField.sorted.all
|
|
|
|
|
|
|
|
#@trackers = Tracker.sorted.all
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
#if @course.save
|
|
|
|
|
|
|
|
# #unless User.current.admin?
|
|
|
|
|
|
|
|
# r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
|
|
|
|
|
|
|
|
# m = Member.new(:user => User.current, :roles => [r])
|
|
|
|
|
|
|
|
# m.project_id = -1
|
|
|
|
|
|
|
|
# course = CourseInfos.new(:user_id => User.current.id, :course_id => @course.id)
|
|
|
|
|
|
|
|
# #user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id)
|
|
|
|
|
|
|
|
# if params[:course][:is_public] == '1'
|
|
|
|
|
|
|
|
# course_status = CourseStatus.create(:course_id => @course.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :course_type => @course_tag)
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# @course.members << m
|
|
|
|
|
|
|
|
# @course.course_infos << course
|
|
|
|
|
|
|
|
# #end
|
|
|
|
|
|
|
|
# respond_to do |format|
|
|
|
|
|
|
|
|
# format.html {
|
|
|
|
|
|
|
|
# flash[:notice] = l(:notice_successful_create)
|
|
|
|
|
|
|
|
# if params[:continue]
|
|
|
|
|
|
|
|
# redirect_to new_course_url(attrs, :course => '0')
|
|
|
|
|
|
|
|
# elsif params[:course_continue]
|
|
|
|
|
|
|
|
# redirect_to new_course_url(:course => '1')
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# redirect_to settings_course_url(@course, :course_type => 1)
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
# format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) }
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# #@course.destroy
|
|
|
|
|
|
|
|
# respond_to do |format|
|
|
|
|
|
|
|
|
# format.html { render :action => 'new', :layout => 'base' } #Added by young
|
|
|
|
|
|
|
|
# format.api { render_validation_errors(@course) }
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def course
|
|
|
|
def course
|
|
|
|