diff options
Diffstat (limited to 'library/Director/Web/Controller/BranchHelper.php')
-rw-r--r-- | library/Director/Web/Controller/BranchHelper.php | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/library/Director/Web/Controller/BranchHelper.php b/library/Director/Web/Controller/BranchHelper.php index ac2a480..89aa6c1 100644 --- a/library/Director/Web/Controller/BranchHelper.php +++ b/library/Director/Web/Controller/BranchHelper.php @@ -3,12 +3,13 @@ namespace Icinga\Module\Director\Web\Controller; use Icinga\Module\Director\Data\Db\DbObjectStore; -use Icinga\Module\Director\Data\Db\DbObjectTypeRegistry; use Icinga\Module\Director\Db\Branch\Branch; use Icinga\Module\Director\Db\Branch\BranchStore; use Icinga\Module\Director\Db\Branch\BranchSupport; +use Icinga\Module\Director\Db\Branch\PreferredBranchSupport; use Icinga\Module\Director\Objects\IcingaObject; use Icinga\Module\Director\Web\Widget\NotInBranchedHint; +use Ramsey\Uuid\UuidInterface; trait BranchHelper { @@ -18,15 +19,21 @@ trait BranchHelper /** @var BranchStore */ protected $branchStore; + /** @var ?bool */ + protected $hasPreferredBranch = null; + /** - * @return false|\Ramsey\Uuid\UuidInterface + * @return ?UuidInterface */ - protected function getBranchUuid() + protected function getBranchUuid(): ?UuidInterface { return $this->getBranch()->getUuid(); } - protected function getBranch() + /** + * @return Branch + */ + protected function getBranch(): Branch { if ($this->branch === null) { /** @var ActionController $this */ @@ -39,7 +46,7 @@ trait BranchHelper /** * @return BranchStore */ - protected function getBranchStore() + protected function getBranchStore(): BranchStore { if ($this->branchStore === null) { $this->branchStore = new BranchStore($this->db()); @@ -48,12 +55,15 @@ trait BranchHelper return $this->branchStore; } - protected function hasBranch() + /** + * @return bool + */ + protected function hasBranch(): bool { return $this->getBranchUuid() !== null; } - protected function enableStaticObjectLoader($table) + protected function enableStaticObjectLoader($table): void { if (BranchSupport::existsForTableName($table)) { IcingaObject::setDbObjectStore(new DbObjectStore($this->db(), $this->getBranch())); @@ -64,7 +74,7 @@ trait BranchHelper * @param string $subject * @return bool */ - protected function showNotInBranch($subject) + protected function showNotInBranch($subject): bool { if ($this->getBranch()->isBranch()) { $this->content()->add(new NotInBranchedHint($subject, $this->getBranch(), $this->Auth())); @@ -73,4 +83,18 @@ trait BranchHelper return false; } + + protected function hasPreferredBranch(): bool + { + if ($this->hasPreferredBranch === null) { + $implementation = Branch::optionalHook(); + if ($implementation instanceof PreferredBranchSupport) { + $this->hasPreferredBranch = $implementation->hasPreferredBranch($this->Auth()); + } else { + $this->hasPreferredBranch = false; + } + } + + return $this->hasPreferredBranch; + } } |