Class: Fiona7::SuperIdFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/fiona7/super_id_finder.rb

Instance Method Summary collapse

Constructor Details

#initialize(forbidden_obj_classes = [], fields = [], connection = ::Fiona7::WriteObj.connection, instance_name = RailsConnector::CmsBaseModel.instance_name) ⇒ SuperIdFinder

Returns a new instance of SuperIdFinder.



3
4
5
6
7
8
# File 'lib/fiona7/super_id_finder.rb', line 3

def initialize(forbidden_obj_classes=[], fields=[], connection=::Fiona7::WriteObj.connection, instance_name=RailsConnector::CmsBaseModel.instance_name)
  @instance_name = instance_name
  @forbidden     = forbidden_obj_classes
  @fields        = fields
  @conn          = connection
end

Instance Method Details

#find(type = :preview, obj_ids) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/fiona7/super_id_finder.rb', line 10

def find(type=:preview, obj_ids)
  case type
  when :preview
    preview(obj_ids)
  when :live
    live(obj_ids)
  else
    raise ArgumentError, "Uknown type #{type.inspect} expected :preview or :live"
  end
end

#live(obj_ids) ⇒ Object



26
27
28
29
# File 'lib/fiona7/super_id_finder.rb', line 26

def live(obj_ids)
  query = "SELECT #{objects_table}.object_id FROM #{links_table} INNER JOIN #{objects_table} ON #{links_table}.content_id = #{objects_table}.released_cont_id WHERE #{links_table}.sub_object_id IN #{obj_ids_array(obj_ids)} #{self.obj_class_condition} #{self.field_condition}"
  ids = self.sql_query(query).to_a.flatten
end

#preview(obj_ids) ⇒ Object



21
22
23
24
# File 'lib/fiona7/super_id_finder.rb', line 21

def preview(obj_ids)
  query = "SELECT #{objects_table}.object_id FROM #{links_table} INNER JOIN #{objects_table} ON #{links_table}.content_id = #{objects_table}.edited_content_id WHERE #{links_table}.sub_object_id IN #{obj_ids_array(obj_ids)} #{self.obj_class_condition} UNION SELECT #{objects_table}.object_id FROM #{links_table} INNER JOIN #{objects_table} ON #{links_table}.content_id = #{objects_table}.committed_cont_id WHERE #{links_table}.sub_object_id IN #{obj_ids_array(obj_ids)} #{self.obj_class_condition} UNION SELECT #{objects_table}.object_id FROM #{links_table} INNER JOIN #{objects_table} ON #{links_table}.content_id = #{objects_table}.released_cont_id WHERE #{links_table}.sub_object_id IN  #{obj_ids_array(obj_ids)} AND #{objects_table}.committed_cont_id IS NULL AND #{objects_table}.edited_content_id IS NULL #{self.obj_class_condition} #{self.field_condition}"
  ids = self.sql_query(query).to_a.flatten
end