From b8dc444cc78e6dcde5b5d3befffa873062f650e7 Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 23 Aug 2016 10:17:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=99=AE=E9=80=9A=E4=BD=9C=E4=B8=9A=E5=92=8C?= =?UTF-8?q?=E7=BC=96=E7=A8=8B=E4=BD=9C=E4=B8=9A=E5=9C=A8=E9=A2=98=E5=BA=93?= =?UTF-8?q?=E5=8F=91=E9=80=81=E5=90=8E=EF=BC=8C=E7=BC=96=E8=BE=91=E5=B9=B6?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E5=8F=91=E5=B8=83=EF=BC=8C=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=88=9B=E5=BB=BA=E4=BD=9C=E5=93=81=E5=88=97?= =?UTF-8?q?=E8=A1=A8=20=E5=A4=8D=E5=88=B6=E7=8F=AD=E7=BA=A7=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E9=87=8C=EF=BC=8C=E5=8B=BE=E9=80=89=E2=80=9C=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E2=80=9D=EF=BC=8C=E5=90=8C=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对应方法:在作业的发布时间点(不用考虑作业是通过何种途径生成的),除了发布作业外,应该为该作业自动创建完整的作品列表(分组作业除外) --- app/controllers/homework_common_controller.rb | 6 ++++++ app/controllers/users_controller.rb | 19 ++----------------- app/helpers/application_helper.rb | 17 +++++++++++++++++ lib/tasks/homework_publishtime.rake | 16 ++++++++++++++++ 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 2f50c8105..6704f7401 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -94,8 +94,10 @@ class HomeworkCommonController < ApplicationController end end + status = false if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0 homework_detail_manual.comment_status = 1 + status = true end eval_start = homework_detail_manual.evaluation_start if eval_start.nil? || (eval_start <= @homework.end_time && homework_detail_manual.comment_status <= 1) @@ -145,6 +147,10 @@ class HomeworkCommonController < ApplicationController @homework_detail_programing.save if @homework_detail_programing @homework_detail_group.save if @homework_detail_group + if @homework.homework_type != 3 && homework_detail_manual.comment_status == 1 && status + create_works_list @homework + end + if params[:is_manage] == "1" redirect_to manage_or_receive_homeworks_user_path(User.current.id) elsif params[:is_manage] == "2" diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e929153ad..eb7ee4c03 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1115,23 +1115,8 @@ class UsersController < ApplicationController homework_detail_programing.save if homework_detail_programing homework_detail_group.save if homework_detail_group - if homework.homework_type != 3 - students = homework.course.student - if !homework.course.nil? && !students.empty? - name = homework.name - name_str = name + "的作品提交" - str = "" - students.each do |student| - if str != "" - str += "," - end - str += "('#{name_str}',#{homework.id},#{student.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}')" - end - #('#{name}的作品提交',#{homework.id},#{student.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}') - sql = "insert into student_works (name, homework_common_id,user_id, created_at, updated_at) values" + str - #StudentWork.create(:name => "#{name}的作品提交", :homework_common_id => homework.id, :user_id => student.student_id) - ActiveRecord::Base.connection.execute sql - end + if homework.homework_type != 3 && homework_detail_manual.comment_status == 1 + create_works_list homework end if params[:quotes] && !params[:quotes].blank? diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index da66f249b..304194e6e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3436,3 +3436,20 @@ def course_syllabus_option user = User.current end type end + +def create_works_list homework + students = homework.course.student + if !homework.course.nil? && !students.empty? + name = homework.name + name_str = name + "的作品提交" + str = "" + students.each do |student| + if str != "" + str += "," + end + str += "('#{name_str}',#{homework.id},#{student.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}')" + end + sql = "insert into student_works (name, homework_common_id,user_id, created_at, updated_at) values" + str + ActiveRecord::Base.connection.execute sql + end +end diff --git a/lib/tasks/homework_publishtime.rake b/lib/tasks/homework_publishtime.rake index 5eaeb37cb..2f999384c 100644 --- a/lib/tasks/homework_publishtime.rake +++ b/lib/tasks/homework_publishtime.rake @@ -8,6 +8,22 @@ namespace :homework_publishtime do homework_detail_manual = homework.homework_detail_manual if homework_detail_manual.comment_status == 0 homework_detail_manual.update_column('comment_status', 1) + if homework.homework_type != 3 + students = homework.course.student + if !homework.course.nil? && !students.empty? + name = homework.name + name_str = name + "的作品提交" + str = "" + students.each do |student| + if str != "" + str += "," + end + str += "('#{name_str}',#{homework.id},#{student.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}')" + end + sql = "insert into student_works (name, homework_common_id,user_id, created_at, updated_at) values" + str + ActiveRecord::Base.connection.execute sql + end + end course = homework.course course.members.each do |m| homework.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => nil)