Class: Content
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Content
- Includes:
- Housekeeping, Shared::Attributions, Shared::Citations, Shared::Confidences, Shared::DataAttributes, Shared::Depictions, Shared::HasPapertrail, Shared::IsData
- Defined in:
- app/models/content.rb
Overview
Content is text related blocks, at present it only pertains to Otus. It requires both a Topic and an Otu. Future extensions may be added to use the model for Projects, etc. via STI.
Instance Attribute Summary collapse
-
#otu_id ⇒ Integer
When OtuContent::Text the id of the Otu the content pertains to.
-
#project_id ⇒ Integer
the project ID.
-
#revision_id ⇒ Integer
Stubbed placeholder for Revision (sensus taxonomy) model.
-
#text ⇒ String
The written content.
-
#topic_id ⇒ Integer
When OtuContent::Text the id of the Topic the content pertains to.
Class Method Summary collapse
- .find_for_autocomplete(params) ⇒ Object
-
.for_page_layout(otu_page_layout_id) ⇒ Object
OTU_PAGE_LAYOUTS V OTU_PAGE_LAYOUT_SECTIONS ^ .otu_page_layout_id v .topic_id V TOPICS V CONTENTS v otu_id ^ .topic_id ^ OTU.
Instance Method Summary collapse
-
#publish ⇒ Object
TODO: this will have to be updated in subclasses.
-
#published? ⇒ Boolean
True if this content has been published.
- #unpublish ⇒ Object
Methods included from Shared::IsData
#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar
Methods included from Shared::DataAttributes
#import_attributes, #internal_attributes, #keyword_value_hash, #reject_data_attributes
Methods included from Shared::Attributions
#attributed?, #reject_attribution
Methods included from Shared::Citations
#cited?, #mark_citations_for_destruction, #nomenclature_date, #origin_citation_source_id, #reject_citations, #requires_citation?, #sources_by_topic_id
Methods included from Shared::Confidences
Methods included from Shared::Depictions
#has_depictions?, #image_array=, #reject_depictions, #reject_images
Methods included from Housekeeping
#has_polymorphic_relationship?
Methods inherited from ApplicationRecord
Instance Attribute Details
#otu_id ⇒ Integer
When OtuContent::Text the id of the Otu the content pertains to. At present required.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/content.rb', line 25 class Content < ApplicationRecord include Housekeeping include Shared::Depictions include Shared::Confidences include Shared::Citations include Shared::Attributions include Shared::HasPapertrail include Shared::DataAttributes # TODO: reconsider, why is this here? Should be removed, use case is currently cross reference to an identifier, if required use Identifier include Shared::IsData ignore_whitespace_on(:text) belongs_to :otu, inverse_of: :contents belongs_to :topic, inverse_of: :contents has_one :public_content belongs_to :language validates_uniqueness_of :topic_id, scope: [:otu_id] validates_presence_of :text, :topic_id, :otu_id # scope :for_otu_page_layout, -> (otu_page_layout_id) { # where('otu_page_layout_id = ?', otu_page_layout.od) # } # @return [Boolean] # true if this content has been published def published? self.public_content end # TODO: this will have to be updated in subclasses. def publish to_publish = { topic: self.topic, text: self.text, otu: self.otu } self.public_content.delete if self.public_content self.public_content = PublicContent.new(to_publish) self.save end def unpublish self.public_content.destroy end # OTU_PAGE_LAYOUTS # V # OTU_PAGE_LAYOUT_SECTIONS ^ .otu_page_layout_id v .topic_id # V # TOPICS # V # CONTENTS v otu_id ^ .topic_id # ^ # OTU # # Given an otu_page_layout id. find all the topics # For this otu_page_layout, find the topics (ControlledVocabularyTerm.of_type(:topic)) def self.for_page_layout(otu_page_layout_id) where('topic_id in (?)', OtuPageLayout.where(id: otu_page_layout_id).first.topics.pluck(:id)) end def self.find_for_autocomplete(params) where('text ILIKE ? OR text ILIKE ?', "#{params[:term]}%", "%#{params[:term]}%") end end |
#project_id ⇒ Integer
the project ID
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/content.rb', line 25 class Content < ApplicationRecord include Housekeeping include Shared::Depictions include Shared::Confidences include Shared::Citations include Shared::Attributions include Shared::HasPapertrail include Shared::DataAttributes # TODO: reconsider, why is this here? Should be removed, use case is currently cross reference to an identifier, if required use Identifier include Shared::IsData ignore_whitespace_on(:text) belongs_to :otu, inverse_of: :contents belongs_to :topic, inverse_of: :contents has_one :public_content belongs_to :language validates_uniqueness_of :topic_id, scope: [:otu_id] validates_presence_of :text, :topic_id, :otu_id # scope :for_otu_page_layout, -> (otu_page_layout_id) { # where('otu_page_layout_id = ?', otu_page_layout.od) # } # @return [Boolean] # true if this content has been published def published? self.public_content end # TODO: this will have to be updated in subclasses. def publish to_publish = { topic: self.topic, text: self.text, otu: self.otu } self.public_content.delete if self.public_content self.public_content = PublicContent.new(to_publish) self.save end def unpublish self.public_content.destroy end # OTU_PAGE_LAYOUTS # V # OTU_PAGE_LAYOUT_SECTIONS ^ .otu_page_layout_id v .topic_id # V # TOPICS # V # CONTENTS v otu_id ^ .topic_id # ^ # OTU # # Given an otu_page_layout id. find all the topics # For this otu_page_layout, find the topics (ControlledVocabularyTerm.of_type(:topic)) def self.for_page_layout(otu_page_layout_id) where('topic_id in (?)', OtuPageLayout.where(id: otu_page_layout_id).first.topics.pluck(:id)) end def self.find_for_autocomplete(params) where('text ILIKE ? OR text ILIKE ?', "#{params[:term]}%", "%#{params[:term]}%") end end |
#revision_id ⇒ Integer
Stubbed placeholder for Revision (sensus taxonomy) model. NOT PRESENTLY USED.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/content.rb', line 25 class Content < ApplicationRecord include Housekeeping include Shared::Depictions include Shared::Confidences include Shared::Citations include Shared::Attributions include Shared::HasPapertrail include Shared::DataAttributes # TODO: reconsider, why is this here? Should be removed, use case is currently cross reference to an identifier, if required use Identifier include Shared::IsData ignore_whitespace_on(:text) belongs_to :otu, inverse_of: :contents belongs_to :topic, inverse_of: :contents has_one :public_content belongs_to :language validates_uniqueness_of :topic_id, scope: [:otu_id] validates_presence_of :text, :topic_id, :otu_id # scope :for_otu_page_layout, -> (otu_page_layout_id) { # where('otu_page_layout_id = ?', otu_page_layout.od) # } # @return [Boolean] # true if this content has been published def published? self.public_content end # TODO: this will have to be updated in subclasses. def publish to_publish = { topic: self.topic, text: self.text, otu: self.otu } self.public_content.delete if self.public_content self.public_content = PublicContent.new(to_publish) self.save end def unpublish self.public_content.destroy end # OTU_PAGE_LAYOUTS # V # OTU_PAGE_LAYOUT_SECTIONS ^ .otu_page_layout_id v .topic_id # V # TOPICS # V # CONTENTS v otu_id ^ .topic_id # ^ # OTU # # Given an otu_page_layout id. find all the topics # For this otu_page_layout, find the topics (ControlledVocabularyTerm.of_type(:topic)) def self.for_page_layout(otu_page_layout_id) where('topic_id in (?)', OtuPageLayout.where(id: otu_page_layout_id).first.topics.pluck(:id)) end def self.find_for_autocomplete(params) where('text ILIKE ? OR text ILIKE ?', "#{params[:term]}%", "%#{params[:term]}%") end end |
#text ⇒ String
The written content.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/content.rb', line 25 class Content < ApplicationRecord include Housekeeping include Shared::Depictions include Shared::Confidences include Shared::Citations include Shared::Attributions include Shared::HasPapertrail include Shared::DataAttributes # TODO: reconsider, why is this here? Should be removed, use case is currently cross reference to an identifier, if required use Identifier include Shared::IsData ignore_whitespace_on(:text) belongs_to :otu, inverse_of: :contents belongs_to :topic, inverse_of: :contents has_one :public_content belongs_to :language validates_uniqueness_of :topic_id, scope: [:otu_id] validates_presence_of :text, :topic_id, :otu_id # scope :for_otu_page_layout, -> (otu_page_layout_id) { # where('otu_page_layout_id = ?', otu_page_layout.od) # } # @return [Boolean] # true if this content has been published def published? self.public_content end # TODO: this will have to be updated in subclasses. def publish to_publish = { topic: self.topic, text: self.text, otu: self.otu } self.public_content.delete if self.public_content self.public_content = PublicContent.new(to_publish) self.save end def unpublish self.public_content.destroy end # OTU_PAGE_LAYOUTS # V # OTU_PAGE_LAYOUT_SECTIONS ^ .otu_page_layout_id v .topic_id # V # TOPICS # V # CONTENTS v otu_id ^ .topic_id # ^ # OTU # # Given an otu_page_layout id. find all the topics # For this otu_page_layout, find the topics (ControlledVocabularyTerm.of_type(:topic)) def self.for_page_layout(otu_page_layout_id) where('topic_id in (?)', OtuPageLayout.where(id: otu_page_layout_id).first.topics.pluck(:id)) end def self.find_for_autocomplete(params) where('text ILIKE ? OR text ILIKE ?', "#{params[:term]}%", "%#{params[:term]}%") end end |
#topic_id ⇒ Integer
When OtuContent::Text the id of the Topic the content pertains to. At present required.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/content.rb', line 25 class Content < ApplicationRecord include Housekeeping include Shared::Depictions include Shared::Confidences include Shared::Citations include Shared::Attributions include Shared::HasPapertrail include Shared::DataAttributes # TODO: reconsider, why is this here? Should be removed, use case is currently cross reference to an identifier, if required use Identifier include Shared::IsData ignore_whitespace_on(:text) belongs_to :otu, inverse_of: :contents belongs_to :topic, inverse_of: :contents has_one :public_content belongs_to :language validates_uniqueness_of :topic_id, scope: [:otu_id] validates_presence_of :text, :topic_id, :otu_id # scope :for_otu_page_layout, -> (otu_page_layout_id) { # where('otu_page_layout_id = ?', otu_page_layout.od) # } # @return [Boolean] # true if this content has been published def published? self.public_content end # TODO: this will have to be updated in subclasses. def publish to_publish = { topic: self.topic, text: self.text, otu: self.otu } self.public_content.delete if self.public_content self.public_content = PublicContent.new(to_publish) self.save end def unpublish self.public_content.destroy end # OTU_PAGE_LAYOUTS # V # OTU_PAGE_LAYOUT_SECTIONS ^ .otu_page_layout_id v .topic_id # V # TOPICS # V # CONTENTS v otu_id ^ .topic_id # ^ # OTU # # Given an otu_page_layout id. find all the topics # For this otu_page_layout, find the topics (ControlledVocabularyTerm.of_type(:topic)) def self.for_page_layout(otu_page_layout_id) where('topic_id in (?)', OtuPageLayout.where(id: otu_page_layout_id).first.topics.pluck(:id)) end def self.find_for_autocomplete(params) where('text ILIKE ? OR text ILIKE ?', "#{params[:term]}%", "%#{params[:term]}%") end end |
Class Method Details
.find_for_autocomplete(params) ⇒ Object
88 89 90 |
# File 'app/models/content.rb', line 88 def self.find_for_autocomplete(params) where('text ILIKE ? OR text ILIKE ?', "#{params[:term]}%", "%#{params[:term]}%") end |
.for_page_layout(otu_page_layout_id) ⇒ Object
OTU_PAGE_LAYOUTS
V
OTU_PAGE_LAYOUT_SECTIONS ^ .otu_page_layout_id v .topic_id
V
TOPICS
V
CONTENTS v otu_id ^ .topic_id
^
OTU
Given an otu_page_layout id. find all the topics For this otu_page_layout, find the topics (ControlledVocabularyTerm.of_type(:topic))
84 85 86 |
# File 'app/models/content.rb', line 84 def self.for_page_layout(otu_page_layout_id) where('topic_id in (?)', OtuPageLayout.where(id: otu_page_layout_id).first.topics.pluck(:id)) end |
Instance Method Details
#publish ⇒ Object
TODO: this will have to be updated in subclasses.
55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/content.rb', line 55 def publish to_publish = { topic: self.topic, text: self.text, otu: self.otu } self.public_content.delete if self.public_content self.public_content = PublicContent.new(to_publish) self.save end |
#published? ⇒ Boolean
Returns true if this content has been published.
50 51 52 |
# File 'app/models/content.rb', line 50 def published? self.public_content end |
#unpublish ⇒ Object
67 68 69 |
# File 'app/models/content.rb', line 67 def unpublish self.public_content.destroy end |