@ -12,7 +12,7 @@ class CoursesController < ApplicationController
end
end
before_action :require_login , except : [ :index , :show , :students , :teachers , :board_list , :mine , :all_course_groups ,
before_action :require_login , except : [ :index , :show , :students , :teachers , :board_list , :mine , :all_course_groups ,
:left_banner , :top_banner ]
:left_banner , :top_banner , :informs , :online_learning ]
before_action :check_account , only : [ :new , :create , :apply_to_join_course , :join_excellent_course ]
before_action :check_account , only : [ :new , :create , :apply_to_join_course , :join_excellent_course ]
before_action :check_auth , except : [ :index , :show , :students , :teachers , :board_list , :mine , :all_course_groups ,
before_action :check_auth , except : [ :index , :show , :students , :teachers , :board_list , :mine , :all_course_groups ,
:left_banner , :top_banner , :apply_to_join_course , :exit_course ]
:left_banner , :top_banner , :apply_to_join_course , :exit_course ]
@ -26,18 +26,21 @@ class CoursesController < ApplicationController
:base_info , :get_historical_courses , :create_group_by_importing_file ,
:base_info , :get_historical_courses , :create_group_by_importing_file ,
:attahcment_category_list , :export_member_scores_excel , :duplicate_course ,
:attahcment_category_list , :export_member_scores_excel , :duplicate_course ,
:switch_to_teacher , :switch_to_assistant , :switch_to_student , :exit_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 ,
before_action :teacher_allowed , only : [ :update , :destroy , :settings , :search_teacher_candidate ,
:transfer_to_course_group , :delete_from_course ,
:transfer_to_course_group , :delete_from_course ,
:search_users , :add_students_by_search , :get_historical_courses , :add_teacher_popup , :add_teacher ]
: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 ,
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 ,
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 ,
:change_course_teacher , :export_member_scores_excel , :course_group_list ,
:teacher_application_review , :apply_teachers , :delete_course_teacher ]
:teacher_application_review , :apply_teachers , :delete_course_teacher ]
before_action :validate_course_name , only : [ :create , :update ]
before_action :validate_course_name , only : [ :create , :update ]
before_action :find_board , only : :board_list
before_action :find_board , only : :board_list
before_action :validate_page_size , only : :mine
before_action :validate_page_size , only : :mine
before_action :course_tasks , only : [ :tasks_list , :update_task_position ]
if RUBY_PLATFORM =~ / linux /
if RUBY_PLATFORM =~ / linux /
require 'simple_xlsx_reader'
require 'simple_xlsx_reader'
@ -58,6 +61,9 @@ class CoursesController < ApplicationController
@courses = Course . where ( is_delete : 0 , is_hidden : 0 , is_end : 0 )
@courses = Course . where ( is_delete : 0 , is_hidden : 0 , is_end : 0 )
end
end
# 金课未开课的不显示在首页
@courses = @courses . where ( " start_date is null or start_date <= ' #{ Date . today } ' " )
# 根据搜索关键字进一步筛选
# 根据搜索关键字进一步筛选
if params [ :search ] . present?
if params [ :search ] . present?
# REDO:Extension
# REDO:Extension
@ -100,7 +106,12 @@ class CoursesController < ApplicationController
# GET /courses/new
# GET /courses/new
def new
def new
@course = Course . 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
end
# Get /courses/:id/settings
# Get /courses/:id/settings
@ -152,7 +163,7 @@ class CoursesController < ApplicationController
end
end
rescue = > e
rescue = > e
uid_logger_error ( e . message )
uid_logger_error ( e . message )
tip_exception ( " 课堂创建失败! " )
tip_exception ( e . message )
raise ActiveRecord :: Rollback
raise ActiveRecord :: Rollback
end
end
end
end
@ -685,12 +696,12 @@ class CoursesController < ApplicationController
if order == 1
if order == 1
# REDO:Extension
# REDO:Extension
@students = @students . includes ( user : :user_extension ) . order ( " user_extensions.student_id " )
@students = @students . includes ( user : :user_extension ) . order ( " user_extensions.student_id , course_members.id " )
elsif order == 2
elsif order == 2
@students = @students . includes ( :course_group ) . order ( " course_groups.position " )
@students = @students . includes ( :course_group ) . order ( " course_groups.position , course_members.id " )
else
else
# REDO:Extension
# REDO:Extension
@students = @students . includes ( user : :user_extension ) . order ( " user_extensions.student_id " )
@students = @students . includes ( user : :user_extension ) . order ( " user_extensions.student_id , course_members.id " )
end
end
if course_group_id . present?
if course_group_id . present?
@ -918,10 +929,10 @@ class CoursesController < ApplicationController
return normal_status ( - 1 , " 课堂已结束,无法加入 " ) if course . is_end
return normal_status ( - 1 , " 课堂已结束,无法加入 " ) if course . is_end
# 实名认证和职业认证的身份判断
# 实名认证和职业认证的身份判断
return normal_status ( - 1 , " 该课堂要求成员完成实名和职业认证 " ) if course . authentication &&
return normal_status ( - 2 , " 该课堂要求成员完成实名和职业认证 " ) if course . authentication &&
course . professional_certification && ( ! current_user . authentication || ! current_user . professional_certification )
course . professional_certification && ( ! current_user . authentication && ! current_user . professional_certification )
return normal_status ( - 1 , " 该课堂要求成员完成实名认证 " ) if course . authentication && ! current_user . authentication
return normal_status ( - 2 , " 该课堂要求成员完成实名认证 " ) if course . authentication && ! current_user . authentication
return normal_status ( - 1 , " 该课堂要求成员完成职业认证 " ) if course . professional_certification && ! current_user . professional_certification
return normal_status ( - 2 , " 该课堂要求成员完成职业认证 " ) if course . professional_certification && ! current_user . professional_certification
# 身份验证
# 身份验证
if params [ :professor ] . blank? && params [ :assistant_professor ] . blank? && params [ :student ] . blank?
if params [ :professor ] . blank? && params [ :assistant_professor ] . blank? && params [ :student ] . blank?
@ -1117,6 +1128,47 @@ class CoursesController < ApplicationController
render_ok ( count : count , courses : courses . select ( :id , :name ) . as_json )
render_ok ( count : count , courses : courses . select ( :id , :name ) . as_json )
end
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
Rails . logger . info ( " # # # # # # # task_ids_length #{ params [ :task_ids ] . uniq . length } # # # # # # # # # task_count: #{ @tasks . count } " )
tip_exception ( " task_ids参数有误 " ) if params [ :task_ids ] . blank? || params [ :task_ids ] . uniq . length != @tasks . count
ActiveRecord :: Base . transaction do
begin
@tasks . each do | task |
position = params [ :task_ids ] . reverse . index ( task . id ) . to_i + 1
task . update_attributes! ( position : position )
end
normal_status ( 0 , " 移动成功 " )
rescue Exception = > e
uid_logger ( e . message )
tip_exception ( e . message )
raise ActiveRecord :: Rollback
end
end
end
private
private
# Use callbacks to share common setup or constraints between actions.
# Use callbacks to share common setup or constraints between actions.
@ -1177,6 +1229,48 @@ class CoursesController < ApplicationController
end
end
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
def student_act_score group_id , search
sql_select = %Q{ SELECT cm.*,(
sql_select = %Q{ SELECT cm.*,(
SELECT SUM ( student_works . work_score )
SELECT SUM ( student_works . work_score )