|
|
|
@ -26,18 +26,22 @@ class CoursesController < ApplicationController
|
|
|
|
|
:base_info, :get_historical_courses, :create_group_by_importing_file,
|
|
|
|
|
:attahcment_category_list,:export_member_scores_excel, :duplicate_course,
|
|
|
|
|
:switch_to_teacher, :switch_to_assistant, :switch_to_student, :exit_course,
|
|
|
|
|
:informs, :update_informs, :join_excellent_course, :online_learning]
|
|
|
|
|
:informs, :update_informs, :join_excellent_course, :online_learning,
|
|
|
|
|
:update_task_position, :tasks_list]
|
|
|
|
|
before_action :teacher_allowed, only: [:update, :destroy, :settings, :search_teacher_candidate,
|
|
|
|
|
:transfer_to_course_group, :delete_from_course,
|
|
|
|
|
:search_users, :add_students_by_search, :get_historical_courses, :add_teacher_popup, :add_teacher]
|
|
|
|
|
before_action :admin_allowed, only: [:set_invite_code_halt, :set_public_or_private, :change_course_admin,
|
|
|
|
|
:set_course_group, :create_group_by_importing_file, :update_informs]
|
|
|
|
|
:set_course_group, :create_group_by_importing_file, :update_informs,
|
|
|
|
|
:update_task_position, :tasks_list]
|
|
|
|
|
before_action :teacher_or_admin_allowed, only: [:graduation_group_list, :create_graduation_group, :join_graduation_group,
|
|
|
|
|
:change_course_teacher, :export_member_scores_excel, :course_group_list,
|
|
|
|
|
:teacher_application_review, :apply_teachers, :delete_course_teacher]
|
|
|
|
|
before_action :validate_course_name, only: [:create, :update]
|
|
|
|
|
before_action :find_board, only: :board_list
|
|
|
|
|
before_action :validate_page_size, only: :mine
|
|
|
|
|
before_action :course_tasks, only: [:tasks_list, :update_task_position]
|
|
|
|
|
before_action :find_container, only: [:update_task_position]
|
|
|
|
|
|
|
|
|
|
if RUBY_PLATFORM =~ /linux/
|
|
|
|
|
require 'simple_xlsx_reader'
|
|
|
|
@ -100,7 +104,12 @@ class CoursesController < ApplicationController
|
|
|
|
|
# GET /courses/new
|
|
|
|
|
def new
|
|
|
|
|
@course = Course.new
|
|
|
|
|
normal_status("成功")
|
|
|
|
|
unless params[:subject_id].blank?
|
|
|
|
|
subject = Subject.find_by(id: params[:subject_id], excellent: 1)
|
|
|
|
|
render :json => {status: 0, course_name: "#{subject&.name}第#{subject&.courses&.count.to_i + 1}期"}
|
|
|
|
|
else
|
|
|
|
|
normal_status("成功")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Get /courses/:id/settings
|
|
|
|
@ -906,15 +915,17 @@ class CoursesController < ApplicationController
|
|
|
|
|
# 邀请码验证
|
|
|
|
|
return normal_status(-1, "邀请码不能为空") if params[:invite_code].blank?
|
|
|
|
|
invite_code = params[:invite_code]
|
|
|
|
|
course = Course.find_by(invite_code: invite_code, is_delete: 0, invite_code_halt: 0, is_end: 0)
|
|
|
|
|
course = Course.find_by(invite_code: invite_code, is_delete: 0, invite_code_halt: 0)
|
|
|
|
|
course_group = CourseGroup.find_by(invite_code: invite_code)
|
|
|
|
|
if course.blank?
|
|
|
|
|
return normal_status(-1, "邀请码无效") if course_group.blank?
|
|
|
|
|
|
|
|
|
|
course = Course.find_by(id: course_group.course_id, is_delete: 0, invite_code_halt: 0, is_end: 0)
|
|
|
|
|
course = Course.find_by(id: course_group.course_id, is_delete: 0, invite_code_halt: 0)
|
|
|
|
|
return normal_status(-1, "邀请码无效") if course.blank?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return normal_status(-1, "课堂已结束,无法加入") if course.is_end
|
|
|
|
|
|
|
|
|
|
# 实名认证和职业认证的身份判断
|
|
|
|
|
return normal_status(-1, "该课堂要求成员完成实名和职业认证") if course.authentication &&
|
|
|
|
|
course.professional_certification && (!current_user.authentication || !current_user.professional_certification)
|
|
|
|
@ -1115,6 +1126,44 @@ class CoursesController < ApplicationController
|
|
|
|
|
render_ok(count: count, courses: courses.select(:id, :name).as_json)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def tasks_list
|
|
|
|
|
case params[:container_type]
|
|
|
|
|
when 'shixun_homework'
|
|
|
|
|
@tasks = @course.practice_homeworks
|
|
|
|
|
when 'common_homework'
|
|
|
|
|
@tasks = @course.normal_homeworks
|
|
|
|
|
when 'group_homework'
|
|
|
|
|
@tasks = @course.group_homeworks
|
|
|
|
|
when 'exercise'
|
|
|
|
|
@tasks = @course.exercises
|
|
|
|
|
when 'poll'
|
|
|
|
|
@tasks = @course.polls
|
|
|
|
|
when 'graduation_topic'
|
|
|
|
|
@tasks = @course.graduation_topics
|
|
|
|
|
when 'graduation_task'
|
|
|
|
|
@tasks = @course.graduation_tasks
|
|
|
|
|
when 'attachment'
|
|
|
|
|
@tasks = @course.attachments
|
|
|
|
|
else
|
|
|
|
|
tip_exception("请指定任务类型")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update_task_position
|
|
|
|
|
tip_exception("缺少position参数") if params[:position].blank?
|
|
|
|
|
unless params[:position].to_i == @task.position
|
|
|
|
|
if params[:position].to_i < @task.position
|
|
|
|
|
@tasks.where("position < #{@task.position} and position >= ?", params[:position]).update_all("position = position + 1")
|
|
|
|
|
else
|
|
|
|
|
@tasks.where("position > #{@task.position} and position <= ?", params[:position]).update_all("position = position - 1")
|
|
|
|
|
end
|
|
|
|
|
@task.update_attributes(position: params[:position])
|
|
|
|
|
normal_status(0, "移动成功")
|
|
|
|
|
else
|
|
|
|
|
normal_status(-1, "位置没有变化")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
|
|
@ -1175,6 +1224,48 @@ class CoursesController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def course_tasks
|
|
|
|
|
case params[:container_type]
|
|
|
|
|
when 'shixun_homework'
|
|
|
|
|
@tasks = @course.practice_homeworks
|
|
|
|
|
when 'common_homework'
|
|
|
|
|
@tasks = @course.normal_homeworks
|
|
|
|
|
when 'group_homework'
|
|
|
|
|
@tasks = @course.group_homeworks
|
|
|
|
|
when 'exercise'
|
|
|
|
|
@tasks = @course.exercises
|
|
|
|
|
when 'poll'
|
|
|
|
|
@tasks = @course.polls
|
|
|
|
|
when 'graduation_topic'
|
|
|
|
|
@tasks = @course.graduation_topics
|
|
|
|
|
when 'graduation_task'
|
|
|
|
|
@tasks = @course.graduation_tasks
|
|
|
|
|
when 'attachment'
|
|
|
|
|
@tasks = @course.attachments
|
|
|
|
|
else
|
|
|
|
|
tip_exception("请指定任务类型")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def find_container
|
|
|
|
|
case params[:container_type]
|
|
|
|
|
when 'shixun_homework', 'common_homework', 'group_homework'
|
|
|
|
|
@task = HomeworkCommon.find_by(id: params[:container_id])
|
|
|
|
|
when 'exercise'
|
|
|
|
|
@task = Exercise.find_by(id: params[:container_id])
|
|
|
|
|
when 'poll'
|
|
|
|
|
@task = Poll.find_by(id: params[:container_id])
|
|
|
|
|
when 'graduation_topic'
|
|
|
|
|
@task = GraduationTopic.find_by(id: params[:container_id])
|
|
|
|
|
when 'graduation_task'
|
|
|
|
|
@task = GraduationTask.find_by(id: params[:container_id])
|
|
|
|
|
when 'attachment'
|
|
|
|
|
@task = Attachment.find_by(id: params[:container_id])
|
|
|
|
|
else
|
|
|
|
|
tip_exception("container_type参数有误")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def student_act_score group_id, search
|
|
|
|
|
sql_select = %Q{SELECT cm.*,(
|
|
|
|
|
SELECT SUM(student_works.work_score)
|
|
|
|
|