ILIAS  release_8 Revision v8.24
class.ilCtrlSingleClassPath.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
26{
31
40 {
42
43 $this->context = $context;
44
45 try {
46 $this->cid_path = $this->getCidPathByClass($target_class);
47 } catch (ilCtrlException $exception) {
48 $this->exception = $exception;
49 }
50 }
51
64 private function getCidPathByClass(string $target_class): string
65 {
66 $target_cid = $this->structure->getClassCidByName($target_class);
67
68 // abort if the target class is unknown.
69 if (null === $target_cid) {
70 throw new ilCtrlException("Class '$target_class' was not found in the control structure, try `composer du` to read artifacts.");
71 }
72
73 // if the target class is already the current command
74 // class of this context, nothing has to be changed.
75 if ($target_cid === $this->context->getPath()->getCurrentCid()) {
76 return $this->context->getPath()->getCidPath();
77 }
78
79 // check if the target is related to a class within
80 // the current context's path.
81 $related_class_path = $this->getPathToRelatedClassInContext($this->context, $target_class);
82 if (null !== $related_class_path) {
83 return $this->appendCid($target_cid, $related_class_path);
84 }
85
86 // fix https://mantis.ilias.de/view.php?id=33094:
87 // prioritise baseclasses less than relationships,
88 // therefore test at last if the target class is a
89 // baseclass.
90 if ($this->structure->isBaseClass($target_class)) {
91 return $target_cid;
92 }
93
94 throw new ilCtrlException("ilCtrl cannot find a path for '$target_class' that reaches '{$this->context->getBaseClass()}'");
95 }
96}
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.
ilCtrl exceptions
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilCtrlContextInterface $context
getCidPathByClass(string $target_class)
Returns a cid path that reaches from the current context's baseclass to the given class.
__construct(ilCtrlStructureInterface $structure, ilCtrlContextInterface $context, string $target_class)
ilCtrlSingleClassPath Constructor
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc