|
|
|
@ -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') <changesets_latest_coimmit.created_at.strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
|
time = changesets_latest_coimmit.created_at
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
rescue
|
|
|
|
|
logger.error("############## ==> 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
|
|
|
|
|