129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'app/models/subscription_client_notice.rb', line 129
def self.list(notice_type: nil, notice_subject_type: nil, notice_subject_id: nil, title: nil, include_all: false, visible: false, page: nil, page_limit: 30)
query = SubscriptionClientNotice.all
query = query.where("hidden_at IS NULL") if visible && !include_all
query = query.where("dismissed_at IS NULL") unless include_all
query = query.where("expired_at IS NULL") unless include_all
query = query.where("notice_subject_type = ?", notice_subject_type.to_s) if notice_subject_type
query = query.where("notice_subject_id = ?", notice_subject_id.to_i) if notice_subject_id
if notice_type
type_query_str = notice_type.is_a?(Array) ? "notice_type IN (?)" : "notice_type = ?"
query = query.where(type_query_str, notice_type)
end
query = query.where("title = ?", title) if title
query = query.limit(page_limit).offset(page.to_i * page_limit) unless page.nil?
query.order("expired_at DESC, updated_at DESC, dismissed_at DESC, created_at DESC")
end
|