Sha256: 9da49de56acae5a492ed1368f075df880663091f74b8cf49d9888f414336105e

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

class ContentHighlight < ActiveRecord::Base
  belongs_to :highlightable, :polymorphic => true
  belongs_to :user

  validates_presence_of :user_id, :highlightable_id, :highlightable_type, :highlightable_column, :content
  validates_presence_of :container_node_identifier, :container_node_identifier_key, :container_node_type, :startnode_offset, :endnode_offset
  validates_inclusion_of :selection_backward, :in => [true, false]

  validates_uniqueness_of :container_node_identifier, :scope => [:container_node_type, :startnode_offset, :endnode_offset, :highlightable, :user_id]

  # This method shall be used to choose the highlights the user can see
  def self.highlights_to_show(highlightable, user, options={})
    # request = options[:request]
    highlightable.content_highlights
  end

  # This method is used to show details on the poptips with permissions to remove highlights
  def self.enrich_highlights(user)
    ContentHighlight.joins(:user)
        .select("content_highlights.id as identifier,
                CONCAT('Highlight by ', users.id) as description,
                ARRAY[CASE user_id WHEN #{user.id} THEN 'me' ELSE 'others' END] as life_time_class_ends,
                CASE user_id WHEN #{user.id} THEN true ELSE false END as can_cancel,
                content,
                selection_backward as backward,
                startnode_offset as start_offset,
                endnode_offset as end_offset,
                container_node_identifier as common_ancestor_identifier,
                container_node_type as common_ancestor_node_type")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acts_as_content_highlightable-0.1.0 lib/generators/acts_as_content_highlightable/templates/active_record_content_highlight_model.rb