diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 0566d3d98..9da4b90b9 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -20,15 +20,16 @@ class HomeworkCommonController < ApplicationController @page = params[:page] ? params[:page].to_i + 1 : 0 @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) if @is_teacher - @homeworks = @course.homework_commons.order("updated_at desc").limit(10).offset(@page * 10) + #@homeworks = @course.homework_commons.order("created_at desc").limit(10).offset(@page * 10) @homework_commons = @course.homework_commons.order("created_at desc") else - @homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("updated_at desc").limit(10).offset(@page * 10) + #@homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10) @homework_commons = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at desc") end @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) @is_new = params[:is_new] + @homeworks = paginateHelper @homework_commons,10 #设置at已读 @homeworks.each do |homework| homework.journals_for_messages.each do |j| diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 229aceb1c..7d970c762 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3248,3 +3248,14 @@ def strip_html(text,len=0,endss="...") end return ss end + +def get_hw_index(hw,is_teacher) + if is_teacher + homeworks = hw.course.homework_commons.order("created_at asc") + else + homeworks = hw.course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at asc") + end + hw_ids = homeworks.map{|hw| hw.id} if !homeworks.empty? + index = hw_ids.index(hw.id) + return index +end diff --git a/app/views/homework_common/index.html.erb b/app/views/homework_common/index.html.erb index e34cf0736..29cff8933 100644 --- a/app/views/homework_common/index.html.erb +++ b/app/views/homework_common/index.html.erb @@ -73,6 +73,12 @@ <% end%> <%= render :partial => 'users/user_homework_list', :locals => {:homework_commons => @homeworks,:page => 0,:is_in_course => 1,:course_id => @course.id} %> +