From 131d4e27ba94ad1cbd9593dbf93070ade0001f1c Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 20 Sep 2022 12:20:44 +0200 Subject: [PATCH] TableWithBranchSupport: provide setter --- .../Web/Table/TableWithBranchSupport.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/library/Director/Web/Table/TableWithBranchSupport.php b/library/Director/Web/Table/TableWithBranchSupport.php index 903bd85f..7c5b15cc 100644 --- a/library/Director/Web/Table/TableWithBranchSupport.php +++ b/library/Director/Web/Table/TableWithBranchSupport.php @@ -2,6 +2,7 @@ namespace Icinga\Module\Director\Web\Table; +use Icinga\Module\Director\Db\Branch\Branch; use Ramsey\Uuid\UuidInterface; trait TableWithBranchSupport @@ -10,6 +11,21 @@ trait TableWithBranchSupport /** @var UuidInterface|null */ protected $branchUuid; + /** + * Convenience method, only UUID is required + * + * @param Branch|null $branch + * @return $this + */ + public function setBranch(Branch $branch = null) + { + if ($branch && $branch->isBranch()) { + $this->setBranchUuid($branch->getUuid()); + } + + return $this; + } + public function setBranchUuid(UuidInterface $uuid = null) { $this->branchUuid = $uuid;