加入课堂

dev_winse
cxt 6 years ago
parent 3d019e0727
commit 4e5d87f41c

@ -567,6 +567,10 @@ class ApplicationController < ActionController::Base
time.blank? ? '' : time.strftime("%Y-%m-%d %H:%M:%S")
end
def strf_date(date)
date.blank? ? '' : date.strftime("%Y-%m-%d")
end
def logger_error(error)
Rails.logger.error(error.message)
error.backtrace.each { |msg| Rails.logger.error(msg) }

@ -117,13 +117,18 @@ class CoursesController < ApplicationController
authentication: params[:authentication], professional_certification: params[:professional_certification])
@course.tea_id = current_user.id
@course_list_name = params[:course_list_name].strip
@course_list = CourseList.find_by(name: @course_list_name)
if @course_list
@course.course_list_id = @course_list.id
if params[:subject_id].blank?
@course_list_name = params[:course_list_name].strip
@course_list = CourseList.find_by(name: @course_list_name)
if @course_list
@course.course_list_id = @course_list.id
else
new_course_list = CourseList.create!(name: @course_list_name, user_id: current_user.id, is_admin: 0)
@course.course_list_id = new_course_list.id
end
else
new_course_list = CourseList.create!(name: @course_list_name, user_id: current_user.id, is_admin: 0)
@course.course_list_id = new_course_list.id
@course.start_date = params[:start_date]
@course.subject_id = params[:subject_id]
end
@course.is_end = @course.end_date.present? && @course.end_date < Date.today
@ -151,7 +156,6 @@ class CoursesController < ApplicationController
begin
extra_params = Hash.new
extra_params[:school_id] = @school.id
extra_params[:is_public] = params[:is_public].present? ? params[:is_public] : 0
if @course.is_end && (course_params[:end_date].blank? || course_params[:end_date].to_date > Date.today)
extra_params[:is_end] = 0
@ -162,13 +166,18 @@ class CoursesController < ApplicationController
extra_params[:authentication] = params[:authentication]
extra_params[:professional_certification] = params[:professional_certification]
@course_list_name = params[:course_list_name].strip
@course_list = CourseList.find_by(name: @course_list_name)
if @course_list
extra_params[:course_list_id] = @course_list.id
if @course.subject
@course.start_date = params[:start_date]
else
new_course_list = CourseList.create(name: @course_list_name, user_id: current_user.id, is_admin: 0)
extra_params[:course_list_id] = new_course_list.id
extra_params[:is_public] = params[:is_public].present? ? params[:is_public] : 0
@course_list_name = params[:course_list_name].strip
@course_list = CourseList.find_by(name: @course_list_name)
if @course_list
extra_params[:course_list_id] = @course_list.id
else
new_course_list = CourseList.create(name: @course_list_name, user_id: current_user.id, is_admin: 0)
extra_params[:course_list_id] = new_course_list.id
end
end
@course.update_attributes!(course_params.merge(extra_params))
@ -1075,9 +1084,18 @@ class CoursesController < ApplicationController
def validate_course_name
tip_exception("课堂名称不能为空!") if params[:course][:name].blank?
tip_exception("课程名称不能为空!") if params[:course_list_name].blank?
tip_exception("课堂名称应以课程名称开头命名") unless params[:course][:name].index(params[:course_list_name]) &&
if params[:subject_id].blank?
tip_exception("课程名称不能为空!") if params[:course_list_name].blank?
tip_exception("课堂名称应以课程名称开头命名") unless params[:course][:name].index(params[:course_list_name]) &&
params[:course][:name].index(params[:course_list_name]) == 0
else
@subject = Subject.find_by!(id: params[:subject_id])
tip_exception("开始时间不能为空") if params[:start_date].blank?
tip_exception("结束时间不能为空") if params[:end_date].blank?
tip_exception("结束时间必须晚于开始时间") if params[:end_date] <= params[:start_date]
tip_exception("开始时间和结束时间不能与往期开课时间重叠") if @subject.max_course_end_date && params[:start_date] <= strf_date(@subject.max_course_end_date)
tip_exception("开放课堂必须包含公告栏和在线学习模块") unless params[:course_module_types].include?("announcement") && params[:course_module_types].include?("online_learning")
end
tip_exception("课堂所属单位不能为空!") if params[:school].blank?
tip_exception("请至少添加一个课堂模块") if params[:course_module_types].blank?
@school = School.find_by!(name: params[:school].strip)

@ -7,6 +7,9 @@ class Course < ApplicationRecord
belongs_to :school, class_name: 'School', foreign_key: :school_id #定义一个方法school该方法通过school_id来调用School表
belongs_to :course_list
# 所属实践课程
belongs_to :subject, optional: true
has_many :course_infos, dependent: :destroy
# 课堂左侧导航栏的模块
has_many :course_modules, dependent: :destroy
@ -176,7 +179,7 @@ class Course < ApplicationRecord
end
def all_course_module_types
%w[activity shixun_homework common_homework group_homework graduation exercise poll attachment board course_group]
%w[activity announcement online_learning shixun_homework common_homework group_homework graduation exercise poll attachment board course_group]
end
def get_course_module_by_type(type)
@ -334,6 +337,8 @@ class Course < ApplicationRecord
def get_name_by_type(type)
case type
when 'activity' then '动态'
when 'announcement' then '公告栏'
when 'online_learning' then '在线学习'
when 'shixun_homework' then '实训作业'
when 'common_homework' then '普通作业'
when 'group_homework' then '分组作业'
@ -350,15 +355,17 @@ class Course < ApplicationRecord
def get_position_by_type(type)
case type
when 'activity' then 1
when 'shixun_homework' then 2
when 'common_homework' then 3
when 'group_homework' then 4
when 'graduation' then 5
when 'exercise' then 6
when 'poll' then 7
when 'attachment' then 8
when 'board' then 9
when 'course_group' then 10
when 'announcement' then 2
when 'online_learning' then 3
when 'shixun_homework' then 4
when 'common_homework' then 5
when 'group_homework' then 6
when 'graduation' then 7
when 'exercise' then 8
when 'poll' then 9
when 'attachment' then 10
when 'board' then 11
when 'course_group' then 12
else 100
end
end

@ -18,6 +18,9 @@ class Subject < ApplicationRecord
has_many :tidings, as: :container, dependent: :destroy
has_many :stages, -> { order("stages.position ASC") }, dependent: :destroy
# 开放课堂
has_many :courses
validates :name, length: { maximum: 40 }
validates :description, length: { maximum: 5000 }
validates :learning_notes, length: { maximum: 500 }
@ -31,6 +34,11 @@ class Subject < ApplicationRecord
self.tidings << Tiding.new(user_id: self.user_id, trigger_user_id: self.user_id, belong_container_id: self.id, belong_container_type: 'Subject', tiding_type: "System", viewed: 0)
end
# 所有开课课堂的最大结束时间
def max_course_end_date
courses.pluck(:end_date).max
end
# 挑战过路径的成员数
def member_count
shixuns.pluck(:myshixuns_count).sum

@ -0,0 +1,8 @@
class AddNewColumnToCourse < ActiveRecord::Migration[5.2]
def change
add_column :courses, :start_date, :date
add_column :courses, :subject_id, :integer, default: 0
add_index :courses, :subject_id
end
end
Loading…
Cancel
Save