laboratory: course and competition data

dev_home
p31729568 5 years ago
parent bf117d2dad
commit 27d6c91a5b

@ -9,7 +9,7 @@ class Competitions::CompetitionsController < Competitions::BaseController
def index
# 已上架 或者 即将上架
competitions = Competition.where(status: true).or(Competition.where.not(published_at: nil))
competitions = current_laboratory.competitions.where(status: true).or(Competition.where.not(published_at: nil))
competitions =
case params[:category]

@ -61,12 +61,13 @@ class CoursesController < ApplicationController
@user = current_user
# 根据分类查询课堂(全部,我的,最新,最热)
@order = params[:order].present? ? params[:order] : "all"
@courses = current_laboratory.courses
if @order == "visits"
order_str = "courses.id = 1309 DESC, courses.visits DESC"
@courses = Course.where(is_delete: 0, is_hidden: 0)
@courses = @courses.where(is_delete: 0, is_hidden: 0)
else
order_str = "courses.id = 1309 DESC, courses.homepage_show DESC, courses.created_at desc"
@courses = Course.where(is_delete: 0, is_hidden: 0, is_end: 0)
@courses = @courses.where(is_delete: 0, is_hidden: 0, is_end: 0)
end
# 金课未开课的不显示在首页

@ -1,4 +1,5 @@
class Competition < ApplicationRecord
belongs_to :laboratory, optional: true
has_many :competition_modules, dependent: :destroy
has_many :unhidden_competition_modules, -> { where(hidden: false) }, class_name: 'CompetitionModule'
@ -32,6 +33,7 @@ class Competition < ApplicationRecord
has_many :competition_prizes, dependent: :destroy
has_many :competition_prize_users, dependent: :destroy
before_save :set_laboratory
after_create :create_competition_modules
def mode_type
@ -180,4 +182,11 @@ class Competition < ApplicationRecord
end
end
end
def set_laboratory
return unless new_record?
return if Laboratory.current.blank? || Laboratory.current.main_site?
self.laboratory = Laboratory.current
end
end

@ -7,6 +7,8 @@ class Course < ApplicationRecord
belongs_to :school, class_name: 'School', foreign_key: :school_id #定义一个方法school该方法通过school_id来调用School表
belongs_to :course_list, optional: true
belongs_to :laboratory, optional: true
# 所属实践课程
belongs_to :subject, optional: true
has_many :informs, as: :container, dependent: :destroy
@ -105,6 +107,7 @@ class Course < ApplicationRecord
validates :name, presence: true, length: { maximum: 60 }
before_save :set_laboratory
after_create :create_board_sync, :act_as_course_activity, :send_tiding
def course_member? user_id, role
@ -409,4 +412,11 @@ class Course < ApplicationRecord
else 100
end
end
def set_laboratory
return unless new_record? # 新记录才需要标记
return if Laboratory.current.blank? || Laboratory.current.main_site?
self.laboratory = Laboratory.current
end
end

@ -47,6 +47,14 @@ class Laboratory < ApplicationRecord
main_site? ? Subject.all : Subject.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: id })
end
def courses
main_site? ? Course.all : Course.where(laboratory_id: self.id)
end
def competitions
main_site? ? Competition.all : Competition.where(laboratory_id: self.id)
end
def shixun_repertoires
where_sql = ShixunTagRepertoire.where("shixun_tag_repertoires.tag_repertoire_id = tag_repertoires.id")

@ -0,0 +1,5 @@
class AddLaboratoryIdToCourses < ActiveRecord::Migration[5.2]
def change
add_reference :courses, :laboratory, null: true
end
end

@ -0,0 +1,5 @@
class AddLaboratoryIdToCompetitions < ActiveRecord::Migration[5.2]
def change
add_reference :competitions, :laboratory
end
end
Loading…
Cancel
Save