Sha256: 1feb64922030134dfdf2739a0e6131b62dfde7de6b9ef960924c80686bd2cb65

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

require 'fiona7/super_id_finder'
require 'fiona7/attribute_names_from_cms'

module Fiona7
  class LinkedIdFinder
    def initialize(fields=[], connection=::Fiona7::WriteObj.connection, instance_name=RailsConnector::CmsBaseModel.instance_name)
      @fields     = fields.map {|f|
        Fiona7::AttributeNamesFromCms.new(f).attributes
      }.flatten
      @instance   = instance_name
      @connection = connection
    end

    def find(klass, ids)
      mode               = klass == Fiona7::ReleasedObj ? :live : :preview
      forbidden          = Fiona7::ForbiddenObjClasses.new

      # first we find objects linking directly
      # NOTE: this may return widget objects
      linking_directly   = Fiona7::SuperIdFinder.new(
        forbidden.system_obj_classes, @fields, @connection, @instance
      ).find(
        mode, ids
      )

      # now we resolve widget objects
      linking_indirectly = Fiona7::SuperIdFinder.new(
        forbidden.all, ['X_widget_pool'], @connection, @instance
      ).find(
        mode, linking_directly
      )

      all_linking        = linking_directly + linking_indirectly

      # finally, this removes widget objects from the result
      # we also remove system classes, just to be extra sure
      klass.
        where(obj_id: all_linking).
        where.not(obj_class: forbidden.all).
        select(:obj_id).
        map(&:obj_id)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
infopark_fiona7-1.6.1.1.5 lib/fiona7/linked_id_finder.rb
infopark_fiona7-1.6.1.1.1 lib/fiona7/linked_id_finder.rb
infopark_fiona7-1.6.1.1.0 lib/fiona7/linked_id_finder.rb