ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilCtrlArrayClassPath Class Reference

Class ilCtrlArrayClassPath. More...

+ Inheritance diagram for ilCtrlArrayClassPath:
+ Collaboration diagram for ilCtrlArrayClassPath:

Public Member Functions

 __construct (ilCtrlStructureInterface $structure, ilCtrlContextInterface $context, array $target_classes)
 ilCtrlArrayClassPath Constructor More...
 
- Public Member Functions inherited from ilCtrlAbstractPath
 __construct (ilCtrlStructureInterface $structure)
 ilCtrlAbstractPath Constructor More...
 
 getCidPath ()
 @inheritDoc More...
 
 getCurrentCid ()
 @inheritDoc More...
 
 getNextCid (string $current_class)
 @inheritDoc More...
 
 getCidPaths (int $order=SORT_DESC)
 @inheritDoc More...
 
 getCidArray (int $order=SORT_DESC)
 @inheritDoc More...
 
 getBaseClass ()
 @inheritDoc More...
 
 getException ()
 @inheritDoc More...
 
 getCidPath ()
 Returns the CID path for the target class of the current instance. More...
 
 getCurrentCid ()
 Returns the CID that must currently be processed. More...
 
 getNextCid (string $current_class)
 Returns the next CID that must be processed. More...
 
 getCidPaths (int $order=SORT_DESC)
 Returns all individual paths for each cid position for the given direction. More...
 
 getCidArray (int $order=SORT_DESC)
 Returns all cid's from the current path in the provided directory/order. More...
 
 getBaseClass ()
 Returns the baseclass of the current cid path. More...
 
 getException ()
 Returns the exception produced during the path-finding- process. More...
 

Private Member Functions

 getCidPathByArray (array $target_classes)
 Generates a cid path from the given class array. More...
 

Private Attributes

ilCtrlContextInterface $context
 

Additional Inherited Members

- Data Fields inherited from ilCtrlPathInterface
const CID_PATH_SEPARATOR = ':'
 
- Protected Member Functions inherited from ilCtrlAbstractPath
 getPathToRelatedClassInContext (ilCtrlContextInterface $context, string $target_class)
 Returns the path to a class within the given contexts current path that has a relation to the given target. More...
 
 isClassChildOf (string $child_class, string $parent_class)
 Returns whether the given target class is a child of the other given class. More...
 
 isClassParentOf (string $parent_class, string $child_class)
 Returns whether the given target class is a parent of the other given class. More...
 
 appendCid (string $cid, ?string $path=null)
 Helper function to add CIDs to a given path. More...
 
- Protected Attributes inherited from ilCtrlAbstractPath
ilCtrlStructureInterface $structure
 
ilCtrlException $exception = null
 
string $cid_path = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilCtrlArrayClassPath::__construct ( ilCtrlStructureInterface  $structure,
ilCtrlContextInterface  $context,
array  $target_classes 
)

ilCtrlArrayClassPath Constructor

Parameters
ilCtrlStructureInterface$structure
ilCtrlContextInterface$context
string[]$target_classes

Definition at line 40 of file class.ilCtrlArrayClassPath.php.

41 {
43
44 $this->context = $context;
45
46 try {
47 $this->cid_path = $this->getCidPathByArray($target_classes);
48 } catch (ilCtrlException $exception) {
49 $this->exception = $exception;
50 }
51 }
ilCtrlStructureInterface $structure
getCidPathByArray(array $target_classes)
Generates a cid path from the given class array.
ilCtrlContextInterface $context
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References $context, ilCtrlAbstractPath\$exception, ilCtrlAbstractPath\$structure, ILIAS\GlobalScreen\Provider\__construct(), and getCidPathByArray().

+ Here is the call graph for this function:

Member Function Documentation

◆ getCidPathByArray()

ilCtrlArrayClassPath::getCidPathByArray ( array  $target_classes)
private

Generates a cid path from the given class array.

If the given class array does not contain a valid path an according exception will be thrown.

Parameters
string[]$target_classes
Returns
string
Exceptions
ilCtrlExceptionif classes within the classes array are not related.

Definition at line 64 of file class.ilCtrlArrayClassPath.php.

64 : string
65 {
66 // abort if the provided targets are empty.
67 if (empty($target_classes)) {
68 throw new ilCtrlException(__METHOD__ . " must be provided with a list of classes.");
69 }
70
71 // loop through each provided class in descending order
72 // and check if they are all related to one another and
73 // convert them to a cid path.
74 $cid_path = $previous_class = null;
75 foreach ($target_classes as $current_class) {
76 $current_cid = $this->structure->getClassCidByName($current_class);
77
78 // abort if the current class cannot be found.
79 if (null === $current_cid) {
80 throw new ilCtrlException("Class '$current_class' was not found in the control structure, try `composer du` to read artifacts.");
81 }
82
83 // abort if the current and previous classes are
84 // not related.
85 if (null !== $previous_class && !$this->isClassParentOf($previous_class, $current_class)) {
86 throw new ilCtrlException("Class '$current_class' is not a child of '$previous_class'.");
87 }
88
89 $cid_path = $this->appendCid($current_cid, $cid_path);
90 $previous_class = $current_class;
91 }
92
93 // if the first provided class is a baseclass the
94 // created cid path can be returned.
95 $first_array_class = $target_classes[array_key_first($target_classes)];
96 if ($this->structure->isBaseClass($first_array_class)) {
97 return $cid_path;
98 }
99
100 // check if the first command class is related to one
101 // of the current context.
102 $related_class_path = $this->getPathToRelatedClassInContext($this->context, $first_array_class);
103 if (null === $related_class_path) {
104 throw new ilCtrlException("Class '$first_array_class' is not a baseclass and the current context doesn't have one either.");
105 }
106
107 return $this->appendCid($cid_path, $related_class_path);
108 }
getPathToRelatedClassInContext(ilCtrlContextInterface $context, string $target_class)
Returns the path to a class within the given contexts current path that has a relation to the given t...
appendCid(string $cid, ?string $path=null)
Helper function to add CIDs to a given path.
isClassParentOf(string $parent_class, string $child_class)
Returns whether the given target class is a parent of the other given class.

References ilCtrlAbstractPath\$cid_path, ilCtrlAbstractPath\appendCid(), ilCtrlAbstractPath\getPathToRelatedClassInContext(), and ilCtrlAbstractPath\isClassParentOf().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $context

ilCtrlContextInterface ilCtrlArrayClassPath::$context
private

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

Referenced by __construct().


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