eBooru/app/models/note_version.rb

35 lines
907 B
Ruby
Raw Permalink Normal View History

# frozen_string_literal: true
class NoteVersion < ApplicationRecord
user_status_counter :note_count, foreign_key: :updater_id
belongs_to_updater
scope :for_user, ->(user_id) {where("updater_id = ?", user_id)}
2013-01-10 17:45:52 -05:00
def self.search(params)
2018-01-13 13:01:30 -05:00
q = super
2013-03-19 08:10:10 -04:00
q = q.where_user(:updater_id, :updater, params)
2013-01-10 17:45:52 -05:00
if params[:post_id]
q = q.where(post_id: params[:post_id].split(",").map(&:to_i))
2013-01-10 17:45:52 -05:00
end
2013-03-19 08:10:10 -04:00
2013-01-11 17:13:55 -05:00
if params[:note_id]
q = q.where(note_id: params[:note_id].split(",").map(&:to_i))
2013-01-11 17:13:55 -05:00
end
2013-03-19 08:10:10 -04:00
q = q.attribute_matches(:is_active, params[:is_active])
q = q.attribute_matches(:body, params[:body_matches])
if params[:ip_addr].present?
q = q.where("updater_ip_addr <<= ?", params[:ip_addr])
end
2023-07-07 08:32:57 -04:00
q.apply_basic_order(params)
2013-01-10 17:45:52 -05:00
end
2013-03-19 08:10:10 -04:00
2015-04-15 11:29:15 -04:00
def previous
NoteVersion.where("note_id = ? and updated_at < ?", note_id, updated_at).order("updated_at desc").first
2015-04-15 11:29:15 -04:00
end
2010-02-24 15:40:55 -05:00
end