Browse Source

Exclude documents only to be found in premium libraries

pull/23/head
Angel Aviel Domaoan 4 years ago committed by Angel Aviel Domaoan
parent
commit
27a1cd6f7f
  1. 2
      app/controllers/api/documents_controller.rb
  2. 2
      app/controllers/concerns/jurisprudence_search.rb
  3. 12
      app/models/cdao/document.rb
  4. 5
      app/models/cdao/document_library.rb
  5. 12
      app/models/cdao/jurisprudence.rb
  6. 4
      app/models/cdao/library.rb

2
app/controllers/api/documents_controller.rb

@ -33,6 +33,8 @@ module Api
with(:citation_finders_names).any_of(search_params[:citation_finder]) if search_params[:citation_finder].present?
with(:is_only_in_premium_libraries, false)
order_by :doc_date, :desc
order_by :year, :desc

2
app/controllers/concerns/jurisprudence_search.rb

@ -17,6 +17,8 @@ module JurisprudenceSearch
without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present?
with(:is_only_in_premium_libraries, false)
order_by :doc_date, :desc
order_by :year, :desc

12
app/models/cdao/document.rb

@ -12,6 +12,14 @@ class Cdao::Document < Cdao::Base
(reference_number.presence || "").gsub(/<!--\d+-->/, "")
end
def libraries
Cdao::DocumentLibrary.where(library_product_type: doc_type, library_product_id: doc_id).map(&:library)
end
def is_only_in_premium_libraries?
libraries.all?(&:premium?)
end
def to_builder(ability = nil)
Jbuilder.new do |doc|
doc.(self, *%i[id title short_title])
@ -65,6 +73,10 @@ class Cdao::Document < Cdao::Base
year.present? && year > 0 ? year : (doc_date.try :year)
end
boolean :is_only_in_premium_libraries do
is_only_in_premium_libraries?
end
string :citation_finders_names, multiple: true
end
end

5
app/models/cdao/document_library.rb

@ -0,0 +1,5 @@
class Cdao::DocumentLibrary < Cdao::Base
self.table_name = "document_product_titles"
belongs_to :library, class_name: "Cdao::Library", foreign_key: :producttitle_id, optional: false
end

12
app/models/cdao/jurisprudence.rb

@ -12,6 +12,14 @@ class Cdao::Jurisprudence < Cdao::Base
alias_attribute :doc_date, :docdate
def libraries
Cdao::DocumentLibrary.where(library_product_type: self.class.name.gsub("Cdao::", ""), library_product_id: id).map(&:library)
end
def is_only_in_premium_libraries?
libraries.all?(&:premium?)
end
def cited_documents
Cdao::Citation.where(citing_doc_id: self.id, citing_doc_type: self.class.name.gsub("Cdao::", ""))
end
@ -147,6 +155,10 @@ class Cdao::Jurisprudence < Cdao::Base
boolean :edited
boolean :is_only_in_premium_libraries do
is_only_in_premium_libraries?
end
join(:phil_rep, :target => Annotation, :type => :string, :join => { :from => :document_id, :to => :id })
end
end

4
app/models/cdao/library.rb

@ -2,4 +2,8 @@ class Cdao::Library < Cdao::Base
default_scope { where(id: Cdao::Library.find_by(key: "JurisprudenceEncyclopedia").try(:id)) }
self.table_name = "producttitles"
def premium?
name.match?(/Encyclopedia/)
end
end

Loading…
Cancel
Save