From 3362ebe321a3fe4efee2a638fef194448abe536d Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 8 Jul 2016 18:22:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=BF=E4=B8=8B=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_common_controller.rb | 26 +++++++++++++------ app/controllers/users_controller.rb | 11 +++++++- app/helpers/application_helper.rb | 2 +- .../_programing_work_show.html.erb | 2 +- app/views/users/_course_homework.html.erb | 12 ++++++--- .../users/_user_homework_detail.html.erb | 11 +++++--- 6 files changed, 47 insertions(+), 17 deletions(-) diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 5e67f6f26..6724f42bb 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -27,6 +27,7 @@ class HomeworkCommonController < ApplicationController #@homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10) @homework_commons = @course.homework_commons.where("name like '%#{search}%' and publish_time <= '#{Date.today}'").order("created_at desc") end + #update_homework_time @homework_commons @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) @is_new = params[:is_new] @@ -409,8 +410,8 @@ class HomeworkCommonController < ApplicationController def update_homework_time homeworks unless homeworks.nil? homeworks.each do |h| - if h.homework_type == 3 - student_works = h.student_work_projects.where("is_leader = 1") + if h.homework_type == 3 && h.homework_detail_group.base_on_project == 1 + student_works = h.student_work_projects.where("is_leader = 1 && project_id != -1") time = h.updated_at unless student_works.nil? student_works.each do |s| @@ -418,7 +419,7 @@ class HomeworkCommonController < ApplicationController unless project.nil? && project.gpid.nil? project_time=project.updated_on project_time=ForgeActivity.where("project_id=?",project.id).last.updated_at if ForgeActivity.where("project_id=?",project.id).last - if format_time(time) < format_time(project_time) + if time.strftime('%Y-%m-%d %H:%M:%S') < project_time.strftime('%Y-%m-%d %H:%M:%S') time = project_time end begin @@ -428,21 +429,30 @@ class HomeworkCommonController < ApplicationController changesets = g.commits(project.gpid, :ref_name => default_branch) changesets_latest_coimmit = changesets[0] unless changesets[0].blank? - if format_time(time) < format_time(changesets_latest_coimmit.created_at) + if time.strftime('%Y-%m-%d %H:%M:%S') update homework project time") end end end end - puts h.updated_at - puts time s_time = time - if format_time(time) > format_time(h.updated_at) + if time.strftime('%Y-%m-%d %H:%M:%S') > h.updated_at.strftime('%Y-%m-%d %H:%M:%S') h.update_column('updated_at', s_time) + course_activity = CourseActivity.where("course_act_type=? and course_act_id =?", 'HomeworkCommon', h.id).first + if course_activity && (time.strftime('%Y-%m-%d %H:%M:%S') > course_activity.updated_at.strftime('%Y-%m-%d %H:%M:%S')) + course_activity.update_column('updated_at', s_time) + end + user_activity = UserActivity.where("act_type=? and act_id =?", 'HomeworkCommon', h.id).first + if user_activity && (time.strftime('%Y-%m-%d %H:%M:%S') > user_activity.updated_at.strftime('%Y-%m-%d %H:%M:%S')) + user_activity.update_column('updated_at', s_time) + end + org_activity = OrgActivity.where("org_act_type=? and org_act_id =?", 'HomeworkCommon', h.id).first + if org_activity && (time.strftime('%Y-%m-%d %H:%M:%S') > org_activity.updated_at.strftime('%Y-%m-%d %H:%M:%S')) + org_activity.update_column('updated_at', s_time) + end end end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 44344f1b5..5fe7efc51 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1048,9 +1048,18 @@ class UsersController < ApplicationController if homework.homework_type != 3 unless homework.course.nil? name = homework.name + name_str = name + "的作品提交" + str = "" homework.course.student.each do |student| - StudentWork.create(:name => "#{name}的作品提交", :homework_common_id => homework.id, :user_id => student.student_id) + 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 end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3cbafac9c..4ebb8eb80 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2681,8 +2681,8 @@ module ApplicationHelper #根据传入作业确定显示为编辑作品还是新建作品,或者显示作品数量 def user_for_homework_common homework,is_teacher + count = homework.student_works.has_committed.count if User.current.member_of_course?(homework.course) - count = homework.student_works.has_committed.count if is_teacher #老师显示作品数量 link_to "作品(#{count})", student_work_index_url_in_org(homework.id), :class => "c_blue" else #学生显示提交作品、修改作品等按钮 diff --git a/app/views/student_work/_programing_work_show.html.erb b/app/views/student_work/_programing_work_show.html.erb index c4df9e715..c111fbe48 100644 --- a/app/views/student_work/_programing_work_show.html.erb +++ b/app/views/student_work/_programing_work_show.html.erb @@ -26,7 +26,7 @@
  • 编程代码: -
    +
    diff --git a/app/views/users/_course_homework.html.erb b/app/views/users/_course_homework.html.erb index d6fa4eff7..783193e46 100644 --- a/app/views/users/_course_homework.html.erb +++ b/app/views/users/_course_homework.html.erb @@ -195,8 +195,13 @@ <% sort_projects = project_sort_update projects %>
    - <% first_pro = project_sort_first(projects).first %> - # <%=time_from_now first_pro.updated_at %><%= link_to User.find(first_pro.user_id).show_name, user_activities_path(first_pro.user_id), :class => "newsBlue ml5 mr5"%>更新了项目,最近更新: + <%# first_pro = sort_projects.first %> + <% first_pro = Project.find sort_projects.first.project_id %> + <% commit_time = first_pro.project_score.commit_time %> + <% one_time = first_pro.updated_on %> + <% one_forge_time=ForgeActivity.where("project_id=?",first_pro.id).last.updated_at if ForgeActivity.where("project_id=?",first_pro.id).last %> + <% one_time= one_time > one_forge_time ? one_time : one_forge_time %> + # <%=time_from_now !commit_time.nil? && format_time(commit_time) > format_time(one_time) ? commit_time : one_time %><%= link_to User.find(first_pro.user_id).show_name, user_activities_path(first_pro.user_id), :class => "newsBlue ml5 mr5"%>更新了项目,最近更新:
    <% sort_projects.each_with_index do |pro, i| %> @@ -219,7 +224,8 @@ <% end %> <% com_time = project.project_score.commit_time %> <% time=project.updated_on %> - <% time=ForgeActivity.where("project_id=?",project.id).last.updated_at if ForgeActivity.where("project_id=?",project.id).last %> + <% forge_time=ForgeActivity.where("project_id=?",project.id).last.updated_at if ForgeActivity.where("project_id=?",project.id).last %> + <% time= time > forge_time ? time : forge_time %>

    <%=(User.find project.user_id).show_name %>(组长)

    <%=time_from_now !com_time.nil? && format_time(com_time) > format_time(time) ? com_time : time %>  <%= project.project_score.changeset_num %>提交

    diff --git a/app/views/users/_user_homework_detail.html.erb b/app/views/users/_user_homework_detail.html.erb index 986371be3..4c8e17d5d 100644 --- a/app/views/users/_user_homework_detail.html.erb +++ b/app/views/users/_user_homework_detail.html.erb @@ -206,8 +206,12 @@ <% sort_projects = project_sort_update projects %>
    - <% first_pro = project_sort_first(projects).first %> - # <%=time_from_now first_pro.updated_at %><%= link_to User.find(first_pro.user_id).show_name, user_activities_path(first_pro.user_id), :class => "newsBlue ml5 mr5"%>更新了项目,最近更新: + <% first_pro = Project.find sort_projects.first.project_id %> + <% commit_time = first_pro.project_score.commit_time %> + <% one_time = first_pro.updated_on %> + <% one_forge_time=ForgeActivity.where("project_id=?",first_pro.id).last.updated_at if ForgeActivity.where("project_id=?",first_pro.id).last %> + <% one_time= one_time > one_forge_time ? one_time : one_forge_time %> + # <%=time_from_now !commit_time.nil? && format_time(commit_time) > format_time(one_time) ? commit_time : one_time %><%= link_to User.find(first_pro.user_id).show_name, user_activities_path(first_pro.user_id), :class => "newsBlue ml5 mr5"%>更新了项目,最近更新:
    <% sort_projects.each_with_index do |pro, i| %> @@ -230,7 +234,8 @@ <% end %> <% com_time = project.project_score.commit_time %> <% time=project.updated_on %> - <% time=ForgeActivity.where("project_id=?",project.id).last.updated_at if ForgeActivity.where("project_id=?",project.id).last %> + <% forge_time=ForgeActivity.where("project_id=?",project.id).last.updated_at if ForgeActivity.where("project_id=?",project.id).last %> + <% time= time > forge_time ? time : forge_time %>

    <%=(User.find project.user_id).show_name %>(组长)

    <%=time_from_now !com_time.nil? && format_time(com_time) > format_time(time) ? com_time : time %>  <%= project.project_score.changeset_num %>提交