新建课程接口

This commit is contained in:
z9hang 2014-12-11 17:11:05 +08:00
parent 9da1f50974
commit 1851181768
2 changed files with 104 additions and 51 deletions

View File

@ -263,57 +263,79 @@ class CoursesController < ApplicationController
end
def create
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)
cs = CoursesService.new
@course = cs.create_course params
if @course.new_record?
respond_to do |format|
format.html { render :action => 'new', :layout => 'base' } #Added by young
format.api { render_validation_errors(@course) }
end
else
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
}
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
#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
def course

View File

@ -79,8 +79,39 @@ class CoursesService
course
end
def create_course
#创建课程
def create_course params
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
@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
@course
end
end