FIX 删除与课程相关的无用代码文件

This commit is contained in:
Jasder
2020-03-09 15:06:15 +08:00
parent 6d12a0f532
commit a9cdf966f8
5 changed files with 0 additions and 1828 deletions

View File

@@ -1,45 +0,0 @@
class CourseMessage < ApplicationRecord
enum status: { UNHANDLED: 0, PASSED: 1, REJECTED: 2 }
belongs_to :course
belongs_to :user
has_one :course_act, class_name: 'CourseActivity', as: :course_act, dependent: :destroy
scope :find_by_course, ->(course) { where(course_id: course.id) }
scope :join_course_requests, -> { where(course_message_type: "JoinCourseRequest") }
scope :unhandled, -> { where(status: :UNHANDLED) }
scope :unhandled_join_course_requests_by_course, ->(course) { find_by_course(course).join_course_requests.unhandled }
after_create :act_as_course_activity
def pass!
update!(status: :PASSED)
send_deal_tiding(1)
end
def application_user
User.find_by(id: course_message_id)
end
def reject!
update!(status: :REJECTED)
send_deal_tiding(2)
end
private
#课程动态公共表记录
def act_as_course_activity
self.course_act << CourseActivity.new(user_id: course_message_id, course_id: course_id)
end
def send_deal_tiding deal_status
# 发送申请处理结果消息
Tiding.create!(
user_id: course_message_id, trigger_user_id: 0, container_id: course_id, container_type: 'DealCourse',
belong_container: course, extra: content.to_i == 2 ? '9' : '7', tiding_type: 'System', status: deal_status
)
# 将申请消息置为已处理
Tiding.where(trigger_user_id: course_message_id, container_id: course_id, container_type: 'JoinCourse', status: 0).update_all(status: 1)
end
end

View File

@@ -1,102 +0,0 @@
class Message < ApplicationRecord
attr_accessor :total_replies_count
belongs_to :board, counter_cache: true
belongs_to :author, class_name: "User", foreign_key: 'author_id'
belongs_to :parent, class_name: "Message", foreign_key: "parent_id", counter_cache: :replies_count, optional: true
belongs_to :root, class_name: 'Message', foreign_key: :root_id, counter_cache: :descendants_count, optional: true
has_one :message_detail, dependent: :destroy
accepts_nested_attributes_for :message_detail, update_only: true
has_many :children, -> { order(updated_on: :desc ) }, class_name: "Message", foreign_key: "parent_id", dependent: :destroy
has_many :praise_treads, as: :praise_tread_object, dependent: :destroy
has_many :tidings, as: :container, dependent: :destroy
has_many :attachments, as: :container, dependent: :destroy
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy # 课程动态
has_many :descendants, class_name: 'Message', foreign_key: :root_id, dependent: :destroy
scope :root_nodes, -> { where("parent_id IS NULL") } #判断该信息是帖子还是回复。null为发布的帖子
scope :reply_nodes, -> { where("parent_id IS NOT NULL") }
scope :visible, -> { where(is_hidden: false) }
scope :by_user, ->(user) { visible if user.nil? || !user.admin? }
scope :preload_messages, -> { includes(:author, :message_detail) }
scope :short, -> { select(:id, :subject, :created_on, :replies_count, :visits, :sticky, :praises_count) }
scope :ordered, -> (opts={}) { reorder("created_on #{opts[:sort] == 1 ? 'asc': 'desc'}") }
scope :by_ids, lambda { |ids| where(id: ids) unless ids.blank? }
scope :find_by_boards, ->(ids) {where(board_id: ids)}
scope :by_keywords, lambda { |keywords|
where("subject LIKE ?", "%#{keywords.split(" ").join('|')}%") unless keywords.blank?
}
#转发表
# has_many :forwards, as: :from, dependent: :destroy
validates :subject, length: { maximum: 255, too_long: "不能超过255个字符" }
def update_content(content)
message_detail.update_attributes(content: content)
end
# 主贴的名称
def main_subject
Rails.logger.info("##########parent: #{parent&.subject}")
parent.present? ? parent.subject : subject
end
def copy_attachments_to_new_message(new_message, user)
attachments.each do |attach|
new_message.attachments << Attachment.new(attach.attributes.except("id").merge(
quotes: 0,
downloads: 0,
author_id: user.id,
created_on: Time.now
))
end
end
def self.bulk_move_to_other_board(message_ids, to_board_id)
to_board = Board.find(to_board_id)
messages = Message.where(id: message_ids, parent_id: nil).select(:id, :board_id).to_a
return if messages.blank?
from_board = Board.find(messages.first.board_id)
root_ids = messages.map(&:id)
children_ids = Message.where(parent_id: root_ids).pluck(:id)
second_children_ids = Message.where(parent_id: children_ids).pluck(:id)
ids = root_ids.concat(children_ids).concat(second_children_ids).uniq
ActiveRecord::Base.transaction do
Message.where(id: ids, board_id: from_board.id).update_all(board_id: to_board.id)
to_board.increment!(:messages_count, ids.size)
from_board.increment!(:messages_count, - ids.size)
end
end
# 包含二级回复的总点赞数
def total_praises_count
praises_count + descendants.sum(:praises_count)
end
# 包含二级回复数的总回复数
def total_replies_count
descendants_count
end
def has_replies
children.exists?
end
#
def by_user_with_visible(user)
user.nil? || !user.admin? ? children.visible.limit(5) : children.limit(5)
end
def update_visits
update_attributes(:visits => visits + 1)
end
end