|
|
|
|
@ -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 |
|
|
|
|
|