@ -284,7 +284,7 @@ class CoursesController < ApplicationController
@is_admin = @user_course_identity < Course :: PROFESSOR
@is_admin = @user_course_identity < Course :: PROFESSOR
@applications = CourseMessage . unhandled_join_course_requests_by_course ( @course )
@applications = @is_admin ? CourseMessage . unhandled_join_course_requests_by_course ( @course ) : CourseMessage . none
page = params [ :page ] || 1
page = params [ :page ] || 1
limit = params [ :limit ] || 20
limit = params [ :limit ] || 20
@ -548,6 +548,7 @@ class CoursesController < ApplicationController
course_teacher = CourseMember . find_by ( user_id : current_user . id , role : % i [ CREATOR PROFESSOR ASSISTANT_PROFESSOR ] , course_id : @course . id )
course_teacher = CourseMember . find_by ( user_id : current_user . id , role : % i [ CREATOR PROFESSOR ASSISTANT_PROFESSOR ] , course_id : @course . id )
course_student . destroy!
course_student . destroy!
course_teacher . update_attributes ( is_active : 1 ) if course_teacher . present? && ! course_teacher . is_active
course_teacher . update_attributes ( is_active : 1 ) if course_teacher . present? && ! course_teacher . is_active
CourseDeleteStudentDeleteWorksJob . perform_later ( @course . id , [ current_user . id ] )
normal_status ( 0 , " 退出成功 " )
normal_status ( 0 , " 退出成功 " )
end
end
@ -684,11 +685,16 @@ class CoursesController < ApplicationController
ActiveRecord :: Base . transaction do
ActiveRecord :: Base . transaction do
begin
begin
students = params [ :students ]
students = params [ :students ]
student_ids = [ ]
students . each do | student |
students . each do | student |
course_member = CourseMember . find_by! ( id : student [ :course_member_id ] . to_i , course_id : @course . id )
course_member = CourseMember . find_by ( id : student [ :course_member_id ] . to_i , course_id : @course . id )
course_member . destroy!
if course_member . present?
student_ids << course_member . user_id
course_member . destroy!
end
end
end
CourseDeleteStudentDeleteWorksJob . perform_later ( @course . id , student_ids ) if student_ids . present?
normal_status ( 0 , " 操作成功 " )
normal_status ( 0 , " 操作成功 " )
rescue = > e
rescue = > e
uid_logger ( e . message )
uid_logger ( e . message )
@ -711,7 +717,7 @@ class CoursesController < ApplicationController
student_ids = [ ]
student_ids = [ ]
user_ids . each do | user_id |
user_ids . each do | user_id |
existing_course_member = CourseMember . find_by ( user_id : user_id . to_i , course_id : @course . id )
existing_course_member = @course . course_members . find_by ( user_id : user_id . to_i )
new_student = CourseMember . new ( user_id : user_id . to_i , course_id : @course . id , course_group_id : course_group_id , role : 4 )
new_student = CourseMember . new ( user_id : user_id . to_i , course_id : @course . id , course_group_id : course_group_id , role : 4 )
if existing_course_member . present?
if existing_course_member . present?
@ -720,6 +726,7 @@ class CoursesController < ApplicationController
else
else
new_student . is_active = 0 if existing_course_member . is_active
new_student . is_active = 0 if existing_course_member . is_active
new_student . save!
new_student . save!
student_ids << user_id
end
end
else
else
new_student . save!
new_student . save!
@ -727,6 +734,7 @@ class CoursesController < ApplicationController
end
end
end
end
CourseAddStudentCreateWorksJob . perform_later ( @course . id , student_ids ) if student_ids . present?
TeacherInviteJoinCourseNotifyJob . perform_later ( current_user . id , @course . id , 10 , student_ids ) if student_ids . present?
TeacherInviteJoinCourseNotifyJob . perform_later ( current_user . id , @course . id , 10 , student_ids ) if student_ids . present?
normal_status ( 0 , " 添加成功 " )
normal_status ( 0 , " 添加成功 " )
rescue = > e
rescue = > e
@ -868,6 +876,7 @@ class CoursesController < ApplicationController
new_student . course_group_id = course_group . id if course_group . present?
new_student . course_group_id = course_group . id if course_group . present?
new_student . save!
new_student . save!
CourseAddStudentCreateWorksJob . perform_later ( course . id , [ current_user . id ] )
StudentJoinCourseNotifyJob . perform_later ( current_user . id , course . id )
StudentJoinCourseNotifyJob . perform_later ( current_user . id , course . id )
end
end
end
end
@ -980,9 +989,12 @@ class CoursesController < ApplicationController
@c_tasks = @course . graduation_tasks . task_published . order ( " graduation_tasks.publish_time asc, graduation_tasks.created_at asc " )
@c_tasks = @course . graduation_tasks . task_published . order ( " graduation_tasks.publish_time asc, graduation_tasks.created_at asc " )
if @user_course_identity > Course :: ASSISTANT_PROFESSOR
if @user_course_identity > Course :: ASSISTANT_PROFESSOR
tip_exception ( 403 , " 无权限操作 " )
tip_exception ( 403 , " 无权限操作 " )
elsif @all_members . size == 0
normal_status ( - 1 , " 课堂暂时没有学生 " )
else
else
member_to_xlsx ( @course , @all_members , @c_homeworks , @c_exercises , @c_tasks )
member_to_xlsx ( @course , @all_members , @c_homeworks , @c_exercises , @c_tasks )
filename = current_user . real_name + " _ " + @course . name + " _全部成绩 " + Time . now . strftime ( '%Y%m%d_%H%M%S' )
filename_ = " #{ current_user . real_name } _ #{ @course . name } _全部成绩 "
filename = Base64 . urlsafe_encode64 ( filename_ )
render xlsx : " #{ format_sheet_name filename . strip . first ( 30 ) } " , template : " courses/export_member_scores_excel.xlsx.axlsx " ,
render xlsx : " #{ format_sheet_name filename . strip . first ( 30 ) } " , template : " courses/export_member_scores_excel.xlsx.axlsx " ,
locals : { course_info : @course_info , activity_level : @user_activity_level ,
locals : { course_info : @course_info , activity_level : @user_activity_level ,
course_scores : @course_user_scores , shixun_works : @shixun_work_arrays ,
course_scores : @course_user_scores , shixun_works : @shixun_work_arrays ,
@ -991,7 +1003,7 @@ class CoursesController < ApplicationController
end
end
rescue Exception = > e
rescue Exception = > 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
@ -1061,19 +1073,23 @@ class CoursesController < ApplicationController
AND homework_commons . course_id = #{@course.id}
AND homework_commons . course_id = #{@course.id}
AND student_works . user_id = cm . user_id
AND student_works . user_id = cm . user_id
) AS score ,
) AS score ,
( SELECT SUM ( gw . work_score ) FROM graduation_works gw , graduation_tasks gt WHERE gw . graduation_task_id = gt . id
AND gt . course_id = #{@course.id} AND gw.user_id = cm.user_id) AS graduation_score,
( SELECT SUM ( exercise_users . score ) FROM exercise_users , exercises WHERE exercise_users . exercise_id = exercises . id
AND exercises . course_id = #{@course.id} AND exercise_users.user_id = cm.user_id) AS ex_score,
( SELECT max ( student_id ) FROM user_extensions WHERE user_extensions . user_id = cm . user_id ) AS student_id ,
( SELECT max ( student_id ) FROM user_extensions WHERE user_extensions . user_id = cm . user_id ) AS student_id ,
( SELECT max ( message_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS message_num,
( SELECT count ( messages . id ) FROM messages join boards on messages . board_id = boards . id WHERE boards . course_id = #{@course.id}
( SELECT max ( message_reply_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS message_reply_num,
AND messages . author_id = cm . user_id and messages . parent_id is null ) AS message_num ,
( SELECT max ( resource_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS resource_num,
( SELECT count ( messages . id ) FROM messages join boards on messages . board_id = boards . id WHERE boards . course_id = #{@course.id}
( SELECT max ( homework_journal_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS homework_journal_num,
AND messages . author_id = cm . user_id and messages . parent_id is not null ) AS message_reply_num ,
( SELECT COUNT ( gw . id ) FROM graduation_works AS gw , graduation_tasks AS gt WHERE gw . graduation_task_id = gt . id AND gt . course_id = #{@course.id} AND gw.work_status != 0 AND gw.user_id = cm.user_id) AS graduation_num,
( SELECT count ( attachments . id ) FROM attachments WHERE container_id = #{@course.id} and container_type = "Course"
( SELECT COUNT ( ss . id ) FROM student_works AS ss , homework_commons AS hc WHERE ss . homework_common_id = hc . id AND hc . course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = cm.user_id) AS homework_num,
AND attachments . author_id = cm . user_id ) AS resource_num ,
( SELECT COUNT ( eu . id ) FROM exercise_users AS eu , exercises WHERE eu . exercise_id = exercises . id AND exercises . course_id = #{@course.id} AND eu.commit_status = 1 AND eu.user_id = cm.user_id) AS exercise_num,
( SELECT count ( jfm . id ) FROM journals_for_messages AS jfm , homework_commons hs WHERE jfm . jour_id = hs . id AND
( SELECT COUNT ( pu . id ) FROM poll_users AS pu , polls WHERE pu . poll_id = polls . id AND polls . course_id = #{@course.id} AND pu.commit_status = 1 AND pu.user_id = cm.user_id) AS poll_num
jfm . user_id = cm . user_id and jfm . jour_type = " HomeworkCommon " and hs . course_id = #{@course.id}) AS homework_journal_num,
( SELECT COUNT ( gw . id ) FROM graduation_works AS gw , graduation_tasks AS gt WHERE gw . graduation_task_id = gt . id AND
gt . course_id = #{@course.id} AND gw.work_status != 0 AND gw.user_id = cm.user_id) AS graduation_num,
( SELECT COUNT ( ss . id ) FROM student_works AS ss , homework_commons AS hc WHERE ss . homework_common_id = hc . id AND
hc . course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = cm.user_id) AS homework_num,
( SELECT COUNT ( eu . id ) FROM exercise_users AS eu , exercises WHERE eu . exercise_id = exercises . id AND exercises . course_id = #{@course.id}
AND eu . commit_status = 1 AND eu . user_id = cm . user_id ) AS exercise_num ,
( SELECT COUNT ( pu . id ) FROM poll_users AS pu , polls WHERE pu . poll_id = polls . id AND polls . course_id = #{@course.id}
AND pu . commit_status = 1 AND pu . user_id = cm . user_id ) AS poll_num
FROM course_members cm }
FROM course_members cm }
if search . present? && group_id . present?
if search . present? && group_id . present?
sql_select += %Q{ join users on cm.user_id = users.id
sql_select += %Q{ join users on cm.user_id = users.id
@ -1082,7 +1098,7 @@ class CoursesController < ApplicationController
( concat ( users . lastname , users . firstname ) like '%#{search}%' or ue . student_id like '%#{search}%' ) ORDER BY score desc }
( concat ( users . lastname , users . firstname ) like '%#{search}%' or ue . student_id like '%#{search}%' ) ORDER BY score desc }
elsif search . present?
elsif search . present?
ql_select += %Q{ join users on cm.user_id = users.id
s ql_select += %Q{ join users on cm.user_id = users.id
joins user_extensions ue on ue . user_id = users . id
joins user_extensions ue on ue . user_id = users . id
WHERE cm . role = 4 and
WHERE cm . role = 4 and
( concat ( users . lastname , users . firstname ) like '%#{search}%' or ue . student_id like '%#{search}%' ) ORDER BY score desc }
( concat ( users . lastname , users . firstname ) like '%#{search}%' or ue . student_id like '%#{search}%' ) ORDER BY score desc }
@ -1105,7 +1121,7 @@ class CoursesController < ApplicationController
common_titles = common_homeworks . pluck ( :name ) + [ " 总得分 " ]
common_titles = common_homeworks . pluck ( :name ) + [ " 总得分 " ]
common_homeworks = common_homeworks . includes ( :score_student_works )
common_homeworks = common_homeworks . includes ( :score_student_works )
group_homeworks = homeworks . search_homework_type ( 3 ) . includes ( :score_student_works ) #全部分组作业
group_homeworks = homeworks . search_homework_type ( 3 ) #全部分组作业
group_titles = group_homeworks . pluck ( :name ) + [ " 总得分 " ]
group_titles = group_homeworks . pluck ( :name ) + [ " 总得分 " ]
group_homeworks = group_homeworks . includes ( :score_student_works )
group_homeworks = group_homeworks . includes ( :score_student_works )
@ -1164,7 +1180,7 @@ class CoursesController < ApplicationController
user_login = user . login
user_login = user . login
user_name = user . real_name
user_name = user . real_name
user_mail = user . mail
user_mail = user . mail
user_stu_id = u ser . student_id . present? ? ( u ser . student_id . to_s + " \t " ) : " -- "
user_stu_id = u . student_id . present? ? ( u . student_id . to_s + " \t " ) : " -- "
user_course_group = u . course_group_name
user_course_group = u . course_group_name
user_info_array = [ user_login , user_name , user_mail , user_stu_id , user_course_group ] #用户的信息集合
user_info_array = [ user_login , user_name , user_mail , user_stu_id , user_course_group ] #用户的信息集合
user_work_scores = [ ]
user_work_scores = [ ]
@ -1183,7 +1199,7 @@ class CoursesController < ApplicationController
c_poll_num = user_poll_num * 7
c_poll_num = user_poll_num * 7
c_file_num = user_file_num * 5
c_file_num = user_file_num * 5
c_message_num = user_messages_num * 2
c_message_num = user_messages_num * 2
c_reply_num = user_reply_num * 2
c_reply_num = user_reply_num
user_activity_levels = c_works_num + c_exercise_num + c_poll_num + c_file_num + c_message_num + c_reply_num + user_work_reply_num
user_activity_levels = c_works_num + c_exercise_num + c_poll_num + c_file_num + c_message_num + c_reply_num + user_work_reply_num
user_ac_level = {
user_ac_level = {
u_1 : user_name ,
u_1 : user_name ,