ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilCtrlStructureMapper Class Reference

Class ilCtrlStructureMapper. More...

+ Collaboration diagram for ilCtrlStructureMapper:

Public Member Functions

 __construct (array $ctrl_structure)
 ilCtrlStructureMapper Constructor More...
 
 getStructure ()
 Returns the current structure with mapped vise-versa references of each parent-child relation. More...
 

Private Member Functions

 addViseVersaMappingByClass (string $class_name, string $key_ref_from, string $key_ref_to)
 If a class has referenced another one as child or parent, this method adds a vise-versa mapping if it doesn't already exist. More...
 
 mapStructure ()
 Maps the current structures references. More...
 
 removeReference (array &$reference_list, $index)
 Removes an entry within the given reference list for the given index and re-indexes the reference list afterwards. More...
 
 isStructureEntryValid ($index)
 Helper function that returns whether an entry in the current structure is valid or not. More...
 

Private Attributes

array $ctrl_structure
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilCtrlStructureMapper::__construct ( array  $ctrl_structure)

ilCtrlStructureMapper Constructor

Parameters
array<string,mixed>$ctrl_structure

Definition at line 24 of file class.ilCtrlStructureMapper.php.

References $ctrl_structure, and mapStructure().

25  {
26  $this->ctrl_structure = $ctrl_structure;
27  $this->mapStructure();
28  }
mapStructure()
Maps the current structures references.
+ Here is the call graph for this function:

Member Function Documentation

◆ addViseVersaMappingByClass()

ilCtrlStructureMapper::addViseVersaMappingByClass ( string  $class_name,
string  $key_ref_from,
string  $key_ref_to 
)
private

If a class has referenced another one as child or parent, this method adds a vise-versa mapping if it doesn't already exist.

Parameters
string$class_name
string$key_ref_from
string$key_ref_to

Definition at line 50 of file class.ilCtrlStructureMapper.php.

References $index, isStructureEntryValid(), and removeReference().

Referenced by mapStructure().

50  : void
51  {
52  if (!empty($this->ctrl_structure[$class_name][$key_ref_from])) {
53  foreach ($this->ctrl_structure[$class_name][$key_ref_from] as $index => $reference) {
54  $is_reference_available = isset($this->ctrl_structure[$reference]);
55  $is_reference_valid = $this->isStructureEntryValid($reference);
56 
57  // the vise-versa mapping must only be processed if the
58  // reference is available and a valid structure entry.
59  if ($is_reference_available && $is_reference_valid) {
60  // create reference list if not yet initialized.
61  if (!isset($this->ctrl_structure[$reference][$key_ref_to])) {
62  $this->ctrl_structure[$reference][$key_ref_to] = [];
63  }
64 
65  // only add vise-versa mapping if it doesn't already exist.
66  if (!in_array($class_name, $this->ctrl_structure[$reference][$key_ref_to], true)) {
67  $this->ctrl_structure[$reference][$key_ref_to][] = $class_name;
68  }
69  }
70 
71  // if the referenced class does not exist within the current
72  // structure, the reference is removed from the reference list.
73  if (!$is_reference_available || !$is_reference_valid) {
74  $this->removeReference($this->ctrl_structure[$class_name][$key_ref_from], $index);
75  }
76  }
77  }
78  }
$index
Definition: metadata.php:145
removeReference(array &$reference_list, $index)
Removes an entry within the given reference list for the given index and re-indexes the reference lis...
isStructureEntryValid($index)
Helper function that returns whether an entry in the current structure is valid or not...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getStructure()

ilCtrlStructureMapper::getStructure ( )

Returns the current structure with mapped vise-versa references of each parent-child relation.

Returns
array<string, mixed>

Definition at line 36 of file class.ilCtrlStructureMapper.php.

References $ctrl_structure.

36  : array
37  {
38  return $this->ctrl_structure;
39  }

◆ isStructureEntryValid()

ilCtrlStructureMapper::isStructureEntryValid (   $index)
private

Helper function that returns whether an entry in the current structure is valid or not.

Parameters
string | int$index
Returns
bool

Definition at line 130 of file class.ilCtrlStructureMapper.php.

References $index.

Referenced by addViseVersaMappingByClass(), and mapStructure().

130  : bool
131  {
132  // structure entry is not a classname.
133  if (!is_string($index)) {
134  return false;
135  }
136 
137  // index is not contained in the structure.
138  if (!isset($this->ctrl_structure[$index])) {
139  return false;
140  }
141 
142  // structure value is not an array
143  if (!is_array($this->ctrl_structure[$index])) {
144  return false;
145  }
146 
147  return true;
148  }
$index
Definition: metadata.php:145
+ Here is the caller graph for this function:

◆ mapStructure()

ilCtrlStructureMapper::mapStructure ( )
private

Maps the current structures references.

Definition at line 83 of file class.ilCtrlStructureMapper.php.

References $data, addViseVersaMappingByClass(), isStructureEntryValid(), ilCtrlStructureInterface\KEY_CLASS_CHILDREN, and ilCtrlStructureInterface\KEY_CLASS_PARENTS.

Referenced by __construct().

83  : void
84  {
85  if (!empty($this->ctrl_structure)) {
86  foreach ($this->ctrl_structure as $class_name => $data) {
87  if ($this->isStructureEntryValid($class_name)) {
89  $class_name,
92  );
93 
95  $class_name,
98  );
99  } else {
100  // remove/unset invalid structure entries.
101  unset($this->ctrl_structure[$class_name]);
102  }
103  }
104  }
105  }
isStructureEntryValid($index)
Helper function that returns whether an entry in the current structure is valid or not...
addViseVersaMappingByClass(string $class_name, string $key_ref_from, string $key_ref_to)
If a class has referenced another one as child or parent, this method adds a vise-versa mapping if it...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeReference()

ilCtrlStructureMapper::removeReference ( array &  $reference_list,
  $index 
)
private

Removes an entry within the given reference list for the given index and re-indexes the reference list afterwards.

Parameters
array$reference_list
string | int$index

Definition at line 114 of file class.ilCtrlStructureMapper.php.

References $index.

Referenced by addViseVersaMappingByClass().

114  : void
115  {
116  // remove the reference of the current index.
117  unset($reference_list[$index]);
118 
119  // re-index the reference list.
120  $reference_list = array_values($reference_list);
121  }
$index
Definition: metadata.php:145
+ Here is the caller graph for this function:

Field Documentation

◆ $ctrl_structure

array ilCtrlStructureMapper::$ctrl_structure
private

Definition at line 17 of file class.ilCtrlStructureMapper.php.

Referenced by __construct(), and getStructure().


The documentation for this class was generated from the following file: