ILIAS  release_8 Revision v8.24
class.ilCtrlArrayClassPath.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5/* Copyright (c) 2021 Thibeau Fuhrer <thf@studer-raimann.ch> Extended GPL, see docs/LICENSE */
6
13{
18
27 {
29
30 $this->context = $context;
31
32 try {
33 $this->cid_path = $this->getCidPathByArray($target_classes);
34 } catch (ilCtrlException $exception) {
35 $this->exception = $exception;
36 }
37 }
38
50 private function getCidPathByArray(array $target_classes): string
51 {
52 // abort if the provided targets are empty.
53 if (empty($target_classes)) {
54 throw new ilCtrlException(__METHOD__ . " must be provided with a list of classes.");
55 }
56
57 // loop through each provided class in descending order
58 // and check if they are all related to one another and
59 // convert them to a cid path.
60 $cid_path = $previous_class = null;
61 foreach ($target_classes as $current_class) {
62 $current_cid = $this->structure->getClassCidByName($current_class);
63
64 // abort if the current class cannot be found.
65 if (null === $current_cid) {
66 throw new ilCtrlException("Class '$current_class' was not found in the control structure, try `composer du` to read artifacts.");
67 }
68
69 // abort if the current and previous classes are
70 // not related.
71 if (null !== $previous_class && !$this->isClassParentOf($previous_class, $current_class)) {
72 throw new ilCtrlException("Class '$current_class' is not a child of '$previous_class'.");
73 }
74
75 $cid_path = $this->appendCid($current_cid, $cid_path);
76 $previous_class = $current_class;
77 }
78
79 // if the first provided class is a baseclass the
80 // created cid path can be returned.
81 $first_array_class = $target_classes[array_key_first($target_classes)];
82 if ($this->structure->isBaseClass($first_array_class)) {
83 return $cid_path;
84 }
85
86 // check if the first command class is related to one
87 // of the current context.
88 $related_class_path = $this->getPathToRelatedClassInContext($this->context, $first_array_class);
89 if (null === $related_class_path) {
90 throw new ilCtrlException("Class '$first_array_class' is not a baseclass and the current context doesn't have one either.");
91 }
92
93 return $this->appendCid($cid_path, $related_class_path);
94 }
95}
Class 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 t...
ilCtrlStructureInterface $structure
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.
Class ilCtrlArrayClassPath.
__construct(ilCtrlStructureInterface $structure, ilCtrlContextInterface $context, array $target_classes)
ilCtrlArrayClassPath Constructor
getCidPathByArray(array $target_classes)
Generates a cid path from the given class array.
ilCtrlContextInterface $context
ilCtrl exceptions
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc