/** * Get a list of the sibling documents * * @param bool $unpublished * @return array */ public function getSiblings($unpublished = false) { if ($this->siblings === null) { $list = new Document\Listing(); $list->setUnpublished($unpublished); // string conversion because parentId could be 0 $list->addConditionParam("parentId = ?", (string) $this->getParentId()); $list->addConditionParam("id != ?", $this->getId()); $list->setOrderKey("index"); $list->setOrder("asc"); $this->siblings = $list->load(); } return $this->siblings; }
public static function getUniqueKey($item, $nr = 0) { $list = new Listing(); $list->setUnpublished(true); $key = Element\Service::getValidKey($item->getKey(), "document"); if (!$key) { throw new \Exception("No item key set."); } if ($nr) { $key = $key . '_' . $nr; } $parent = $item->getParent(); if (!$parent) { throw new \Exception("You have to set a parent document to determine a unique Key"); } if (!$item->getId()) { $list->setCondition('parentId = ? AND `key` = ? ', [$parent->getId(), $key]); } else { $list->setCondition('parentId = ? AND `key` = ? AND id != ? ', [$parent->getId(), $key, $item->getId()]); } $check = $list->loadIdList(); if (!empty($check)) { $nr++; $key = self::getUniqueKey($item, $nr); } return $key; }