ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 38 of file class.ilCtrlStructureMapper.php.

39 {
40 $this->ctrl_structure = $ctrl_structure;
41 $this->mapStructure();
42 }
mapStructure()
Maps the current structures references.

References $ctrl_structure, and mapStructure().

+ 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 64 of file class.ilCtrlStructureMapper.php.

64 : void
65 {
66 if (!empty($this->ctrl_structure[$class_name][$key_ref_from])) {
67 foreach ($this->ctrl_structure[$class_name][$key_ref_from] as $index => $reference) {
68 $is_reference_available = isset($this->ctrl_structure[$reference]);
69 $is_reference_valid = $this->isStructureEntryValid($reference);
70
71 // the vise-versa mapping must only be processed if the
72 // reference is available and a valid structure entry.
73 if ($is_reference_available && $is_reference_valid) {
74 // create reference list if not yet initialized.
75 if (!isset($this->ctrl_structure[$reference][$key_ref_to])) {
76 $this->ctrl_structure[$reference][$key_ref_to] = [];
77 }
78
79 // only add vise-versa mapping if it doesn't already exist.
80 if (!in_array($class_name, $this->ctrl_structure[$reference][$key_ref_to], true)) {
81 $this->ctrl_structure[$reference][$key_ref_to][] = $class_name;
82 }
83 }
84
85 // if the referenced class does not exist within the current
86 // structure, the reference is removed from the reference list.
87 if (!$is_reference_available || !$is_reference_valid) {
88 $this->removeReference($this->ctrl_structure[$class_name][$key_ref_from], $index);
89 }
90 }
91 }
92 }
isStructureEntryValid($index)
Helper function that returns whether an entry in the current structure is valid or not.
removeReference(array &$reference_list, $index)
Removes an entry within the given reference list for the given index and re-indexes the reference lis...

References isStructureEntryValid(), and removeReference().

Referenced by mapStructure().

+ 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 50 of file class.ilCtrlStructureMapper.php.

50 : array
51 {
53 }

References $ctrl_structure.

◆ 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 144 of file class.ilCtrlStructureMapper.php.

144 : bool
145 {
146 // structure entry is not a classname.
147 if (!is_string($index)) {
148 return false;
149 }
150
151 // index is not contained in the structure.
152 if (!isset($this->ctrl_structure[$index])) {
153 return false;
154 }
155
156 // structure value is not an array
157 if (!is_array($this->ctrl_structure[$index])) {
158 return false;
159 }
160
161 return true;
162 }

Referenced by addViseVersaMappingByClass(), and mapStructure().

+ Here is the caller graph for this function:

◆ mapStructure()

ilCtrlStructureMapper::mapStructure ( )
private

Maps the current structures references.

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

97 : void
98 {
99 if (!empty($this->ctrl_structure)) {
100 foreach ($this->ctrl_structure as $class_name => $data) {
101 if ($this->isStructureEntryValid($class_name)) {
103 $class_name,
106 );
107
109 $class_name,
112 );
113 } else {
114 // remove/unset invalid structure entries.
115 unset($this->ctrl_structure[$class_name]);
116 }
117 }
118 }
119 }
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...

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

Referenced by __construct().

+ 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 128 of file class.ilCtrlStructureMapper.php.

128 : void
129 {
130 // remove the reference of the current index.
131 unset($reference_list[$index]);
132
133 // re-index the reference list.
134 $reference_list = array_values($reference_list);
135 }

Referenced by addViseVersaMappingByClass().

+ Here is the caller graph for this function:

Field Documentation

◆ $ctrl_structure

array ilCtrlStructureMapper::$ctrl_structure
private

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

Referenced by __construct(), and getStructure().


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