Sha256: c87a74b06856586e813ce04beb5e2e803f9d2cc8607fe591314b8e7f917a263c

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 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

  # Set Add Permissions here
  def self.can_add_highlights?(highlightable, user)
    return true # e.g. highlightable.can_highlight?(user)
  end

  # Set remove permissions here
  def can_remove_highlight?(user)
    return (self.user == user)
  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

2 entries across 2 versions & 1 rubygems

Version Path
acts_as_content_highlightable-0.2.1 lib/generators/acts_as_content_highlightable/templates/active_record_content_highlight_model.rb
acts_as_content_highlightable-0.2.0 lib/generators/acts_as_content_highlightable/templates/active_record_content_highlight_model.rb