Browse Source

Add CDAO citations for jurisprudences

pull/9/head
Angel Aviel Domaoan 4 years ago committed by Angel Aviel Domaoan
parent
commit
fe9c1be680
  1. 4
      app/controllers/documents_controller.rb
  2. 3
      app/models/cdao/citation.rb
  3. 37
      app/models/cdao/jurisprudence.rb

4
app/controllers/documents_controller.rb

@ -15,6 +15,10 @@ class DocumentsController < ApplicationController
def show
@doctrines = @document.doctrines
where = { enabled: true, state: "published" }
@cited_in_documents = @document.class.citing_docs_of(document, where)
# @cross_ref_documents = @document.class.cited_docs_of(document, where)
end
def search

3
app/models/cdao/citation.rb

@ -0,0 +1,3 @@
class Cdao::Citation < Cdao::Base
self.table_name = "citations"
end

37
app/models/cdao/jurisprudence.rb

@ -10,6 +10,43 @@ class Cdao::Jurisprudence < Cdao::Base
alias_attribute :doc_date, :docdate
def cited_documents
Cdao::Citation.where(citing_doc_id: self.id, citing_doc_type: self.class.name.gsub("Cdao::", ""))
end
def citing_documents
Cdao::Citation.where(cited_doc_id: self.id, cited_doc_type: self.class.name.gsub("Cdao::", ""))
end
def self.citing_docs_of(doc, where = {})
citing_docs = []
c_arel = Cdao::Citation.arel_table
default_where = c_arel[:citing_doc_type].not_eq(nil).and(c_arel[:citing_doc_id].not_eq(nil))
doc.citing_documents.where(where).where(default_where).group_by(&:citing_doc_type).each do |klass_type, records|
next unless klass_type.match?(/Jurisprudence/)
klass = "Cdao::#{klass_type}".safe_constantize
attr = klass.column_names.map(&:to_sym) - [:content]
citing_docs.concat(klass.select(*attr).where(id: records.map(&:citing_doc_id)))
end
citing_docs
end
def self.cited_docs_of(doc, where = {})
cited_docs = []
c_arel = Cdao::Citation.arel_table
default_where = c_arel[:cited_doc_type].not_eq(nil).and(c_arel[:cited_doc_id].not_eq(nil))
doc.cited_documents.where(where).where(default_where).group_by(&:cited_doc_type).each do |klass_type, records|
next unless klass_type.match?(/Jurisprudence/)
klass = "Cdao::#{klass_type}".safe_constantize
attr = klass.column_names.map(&:to_sym) - [:content]
docs = klass.select(*attr).where(id: records.filter_map(&:cited_doc_id))
cited_docs.concat(docs)
end
cited_docs
end
def subjects
doctrines.map(&:subjects).flatten.uniq
end

Loading…
Cancel
Save