实训作业的排序

dev_hs
cxt 6 years ago
parent 10deb78404
commit de5ff94bea

@ -37,8 +37,6 @@ class HomeworkCommonsController < ApplicationController
@category = @main_category.course_second_categories.find_by(id: params[:category])
tip_exception("子目录id有误") if !@category.present?
@homework_commons = @homework_commons.where(course_second_category_id: params[:category])
elsif @homework_type == 4
@homework_commons = @homework_commons
end
@all_count = @homework_commons.size

@ -32,7 +32,12 @@ class Course < ApplicationRecord
has_many :teacher_course_members, -> { teachers_and_admin }, class_name: 'CourseMember'
has_many :teacher_users, through: :teacher_course_members, source: :user
has_many :course_messages, dependent: :destroy
has_many :homework_commons, dependent: :destroy
has_many :normal_homeworks, -> { normals }, class_name: 'HomeworkCommon'
has_many :group_homeworks, -> { groups }, class_name: 'HomeworkCommon'
has_many :practice_homeworks, -> { practices }, class_name: 'HomeworkCommon'
has_many :homework_group_settings
has_many :graduation_works, dependent: :destroy

@ -48,6 +48,9 @@ class HomeworkCommon < ApplicationRecord
scope :search_homework_type, lambda {|num| where(homework_type:num)}
scope :unified_setting, -> {where("unified_setting = ? ", 1)}
scope :normals, -> {where(homework_type: %i[normal])}
scope :groups, -> {where(homework_type: %i[group])}
scope :practices, -> {where(homework_type: %i[practice])}
# 是否显示参考答案
def view_answer identity, user_id

@ -0,0 +1,13 @@
class MigrateCourseTaskPosition < ActiveRecord::Migration[5.2]
def change
add_column :homework_commons, :position, :integer, :default => 0
Course.find_each do |course|
puts course.id
course.practice_homeworks.order("IF(ISNULL(homework_commons.publish_time),0,1), homework_commons.publish_time DESC,
homework_commons.created_at DESC").reverse.each_with_index do |homework, index|
homework.update_columns(position: index + 1)
end
end
end
end
Loading…
Cancel
Save