ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ilCtrlStructureMapper Class Reference
+ 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...
 
 removeInvalidReferences (array $invalid_indices, string $class_name, string $key_ref_from)
 
 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 36 of file class.ilCtrlStructureMapper.php.

37 {
38 $this->ctrl_structure = $ctrl_structure;
39 $this->mapStructure();
40 }
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 62 of file class.ilCtrlStructureMapper.php.

62 : void
63 {
64 if (!empty($this->ctrl_structure[$class_name][$key_ref_from])) {
65 $invalid_indices = [];
66
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 $invalid_indices[] = $index;
89 }
90 }
91
92 $this->removeInvalidReferences($invalid_indices, $class_name, $key_ref_from);
93 }
94 }
removeInvalidReferences(array $invalid_indices, string $class_name, string $key_ref_from)
isStructureEntryValid($index)
Helper function that returns whether an entry in the current structure is valid or not.

References isStructureEntryValid(), and removeInvalidReferences().

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

48 : array
49 {
51 }

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

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

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

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

◆ removeInvalidReferences()

ilCtrlStructureMapper::removeInvalidReferences ( array  $invalid_indices,
string  $class_name,
string  $key_ref_from 
)
private
Parameters
list<int>$invalid_indices

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

126 : void
127 {
128 foreach ($invalid_indices as $index) {
129 unset($this->ctrl_structure[$class_name][$key_ref_from][$index]);
130 }
131
132 // Re-index the array once after all removals
133 if (!empty($invalid_indices)) {
134 $this->ctrl_structure[$class_name][$key_ref_from] = array_values(
135 $this->ctrl_structure[$class_name][$key_ref_from]
136 );
137 }
138 }

Referenced by addViseVersaMappingByClass().

+ Here is the caller graph for this function:

Field Documentation

◆ $ctrl_structure

array ilCtrlStructureMapper::$ctrl_structure
private

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

Referenced by __construct(), and getStructure().


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