summaryrefslogtreecommitdiffstats
path: root/library/Director/Web/Controller/BranchHelper.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:17:47 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:17:47 +0000
commit5419d4428c86c488a43124f85e5407d7cbae6541 (patch)
tree772c4221a20fd7d1b3e7e67c6e21755a50e80fd7 /library/Director/Web/Controller/BranchHelper.php
parentAdding upstream version 1.10.2. (diff)
downloadicingaweb2-module-director-upstream.tar.xz
icingaweb2-module-director-upstream.zip
Adding upstream version 1.11.1.upstream/1.11.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Director/Web/Controller/BranchHelper.php')
-rw-r--r--library/Director/Web/Controller/BranchHelper.php40
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;
+ }
}