class PIM::Services::ItemService::ItemHierarchy

Public Instance Methods

get_child_relation_values(parent, child) click to toggle source

Returns a copy(!) of the relation values for the specified parent-child relation. Returns nil if no such relation exists or the reference values are empty.

# File services.rb, line 2850
def get_child_relation_values parent, child

  parent = parent.to_s
  child = child.to_s
  return nil if self.relation_values.nil?

  parent_relation_values = self.relation_values[parent]
  return nil if parent_relation_values.nil? or parent_relation_values.empty?

  child_relation_values = parent_relation_values[child]
  return nil if child_relation_values.nil? or child_relation_values.empty?

  return child_relation_values.dup
end
get_children(parent) click to toggle source

Returns a copy(!) of all children attached to the parent. Returns nil if no children are linked.

# File services.rb, line 2803
def get_children parent

  return nil if self.hierarchy.nil?

  parent = parent.to_s
  children = self.hierarchy[parent]
  return nil if children.nil? or children.empty?

  return children.to_a
end
get_descendants(parent, include_self: false) click to toggle source

Returns a Set of all descendant children for the specified parent. Set will include the parent itself, if ‘include_self’ is set to true. Returns nil if parent does not exist in hierarchy.

# File services.rb, line 2818
def get_descendants parent, include_self: false

  parent = parent.to_s
  return nil if self.hierarchy.nil? or not self.hierarchy.include?(parent)

  descendants = Set.new
  descendants << parent if include_self

  _add_descendants self.hierarchy, self.hierarchy[parent], descendants: descendants

  return descendants
end