From bc9df6de2f7b3ef06a36c020b341ae24d802c551 Mon Sep 17 00:00:00 2001 From: Matthias Steffens Date: Fri, 11 Feb 2022 11:33:20 +0100 Subject: [PATCH] #220 Adds function CollectionRole->addRootCollection() (WIP) --- library/Opus/Model2/CollectionRole.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/library/Opus/Model2/CollectionRole.php b/library/Opus/Model2/CollectionRole.php index a66873b5..c3fa0198 100644 --- a/library/Opus/Model2/CollectionRole.php +++ b/library/Opus/Model2/CollectionRole.php @@ -40,6 +40,7 @@ * * TODO add database property hide_empty_collections * TODO add more functions from Opus\CollectionRole + * TODO implement isNewRecord()? */ class CollectionRole extends AbstractModel { @@ -446,6 +447,28 @@ public static function fetchByName($name = null) return self::getRepository()->fetchByName($name); } + /** + * Adds the given Collection node (or a new Collection node if none is given) as the root collection of + * this CollectionRole instance. + * + * @param Collection|null $root (Optional) The Collection node that shall be added as the root collection + * of this instance. + * @return Collection The root collection of this instance. + */ + public function addRootCollection($root = null) + { + // TODO DOCTRINE: ensure that this function has the same effect as Opus\CollectionRole->addRootCollection() + + if ($root === null) { + $root = new Collection(); + $root->setRole($this); + } + + $this->setRootCollection($root); + + return $root; + } + /** * Returns the relevant properties of the class. *