public function extractRelations($element, $apiElementKeys, $recursive, $includeRelations) { $foundRelations = []; if ($includeRelations) { $dependency = $element->getDependencies(); if ($dependency) { foreach ($dependency->getRequires() as $r) { if ($e = Element\Service::getDependedElement($r)) { if ($element->getId() != $e->getId() and !in_array(Element\Service::getElementType($e) . "_" . $e->getId(), $apiElementKeys)) { $foundRelations[Element\Service::getElementType($e) . "_" . $e->getId()] = ["elementType" => Element\Service::getType($e), "element" => $e->getId(), "recursive" => false]; } } } } } $childs = $element->getChilds(); if ($recursive and $childs) { foreach ($childs as $child) { if (!in_array(Element\Service::getType($child) . "_" . $child->getId(), $apiElementKeys)) { $foundRelations[Element\Service::getType($child) . "_" . $child->getId()] = ["elementType" => Element\Service::getType($child), "element" => $child->getId(), "recursive" => $recursive]; } } } return $foundRelations; }
/** * @param $webResource */ public function __construct($webResource) { $this->id = $webResource->getId(); if ($webResource instanceof Element\ElementInterface) { $this->type = Element\Service::getType($webResource); } else { $this->type = "unknown"; } }
/** * converts data to be exposed via webservices * @param string $object * @return mixed */ public function getForWebserviceExport($object) { $data = $this->getDataFromObjectParam($object); if ($data instanceof Element\ElementInterface) { return array("type" => Element\Service::getType($data), "subtype" => $data->getType(), "id" => $data->getId()); } else { return null; } }
/** * @param ElementInterface $element * @return $this */ public function setElement(ElementInterface $element) { $this->setCid($element->getId()); $this->setCtype(Service::getType($element)); return $this; }
/** Encode value for packing it into a single column. * @param mixed $value * @param Model\Object\AbstractObject $object * @param mixed $params * @return mixed */ public function marshal($value, $object = null, $params = []) { if (is_array($value)) { $result = []; foreach ($value as $element) { $type = Element\Service::getType($element); $id = $element->getId(); $result[] = ["type" => $type, "id" => $id]; } return $result; } return null; }
/** * get correct type of object as string * @param mixed $data * @return void */ public function getObjectType($object = null) { $this->load(); if (!$object) { $object = $this->o; } if ($object instanceof Element\ElementInterface) { return Element\Service::getType($object); } else { return false; } }
/** Encode value for packing it into a single column. * @param mixed $value * @param Model\Object\AbstractObject $object * @param mixed $params * @return mixed */ public function marshal($value, $object = null, $params = []) { if ($value instanceof Object\Data\Video) { $result = []; $result["type"] = $value->getType(); if ($value->getTitle()) { $result["title"] = $value->getTitle(); } if ($value->getDescription()) { $result["description"] = $value->getDescription(); } $poster = $value->getPoster(); if ($poster) { $result["poster"] = ["type" => Model\Element\Service::getType($poster), "id" => $poster->getId()]; } $data = $value->getData(); if ($data && $value->getType() == "asset") { $result["data"] = ["type" => Model\Element\Service::getType($data), "id" => $data->getId()]; } else { $result["data"] = $data; } return $result; } return null; }
/** * */ public function unlockPropagate() { $type = Service::getType($this); $ids = $this->getDao()->unlockPropagate(); // invalidate cache items foreach ($ids as $id) { $element = Service::getElementById($type, $id); if ($element) { $element->clearDependentCache(); } } }
/** * converts data to be exposed via webservices * @param string $object * @return mixed */ public function getForWebserviceExport($object) { $data = $this->getDataFromObjectParam($object); if (is_array($data)) { $items = array(); foreach ($data as $eo) { if ($eo instanceof Element\ElementInterface) { $items[] = array("type" => Element\Service::getType($eo), "subtype" => $eo->getType(), "id" => $eo->getId()); } } return $items; } else { return null; } }
/** Encode value for packing it into a single column. * @param mixed $value * @param Model\Object\AbstractObject $object * @param mixed $params * @return mixed */ public function marshal($value, $object = null, $params = []) { if ($value) { $type = Element\Service::getType($value); $id = $value->getId(); return ["type" => $type, "id" => $id]; } }
/** * @throws \Exception * @param $rootElement * @param $apiKey * @param $path * @param $apiElement * @param bool $overwrite * @param $elementCounter * @return Element\ElementInterface */ public function create($rootElement, $apiKey, $path, $apiElement, $overwrite, $elementCounter) { //correct relative path if (strpos($path, "/") !== 0) { $path = $rootElement->getFullPath() . "/" . $path; } $type = $apiElement->type; if ($apiElement instanceof Webservice\Data\Asset) { $className = "\\Pimcore\\Model\\Asset\\" . ucfirst($type); $parentClassName = "\\Pimcore\\Model\\Asset"; $maintype = "asset"; $fullPath = $path . $apiElement->filename; } else { if ($apiElement instanceof Webservice\Data\Object) { $maintype = "object"; if ($type == "object") { $className = "\\Pimcore\\Model\\Object\\" . ucfirst($apiElement->className); if (!Tool::classExists($className)) { throw new \Exception("Unknown class [ " . $className . " ]"); } } else { $className = "\\Pimcore\\Model\\Object\\" . ucfirst($type); } $parentClassName = "\\Pimcore\\Model\\Object"; $fullPath = $path . $apiElement->key; } else { if ($apiElement instanceof Webservice\Data\Document) { $maintype = "document"; $className = "\\Pimcore\\Model\\Document\\" . ucfirst($type); $parentClassName = "\\Pimcore\\Model\\Document"; $fullPath = $path . $apiElement->key; } else { throw new \Exception("Unknown import element"); } } } $existingElement = $className::getByPath($fullPath); if ($overwrite && $existingElement) { $apiElement->parentId = $existingElement->getParentId(); return $existingElement; } $element = new $className(); $element->setId(null); $element->setCreationDate(time()); if ($element instanceof Asset) { $element->setFilename($apiElement->filename); $element->setData(base64_decode($apiElement->data)); } else { if ($element instanceof Object\Concrete) { $element->setKey($apiElement->key); $element->setClassName($apiElement->className); $class = Object\ClassDefinition::getByName($apiElement->className); if (!$class instanceof Object\ClassDefinition) { throw new \Exception("Unknown object class [ " . $apiElement->className . " ] "); } $element->setClassId($class->getId()); } else { $element->setKey($apiElement->key); } } $this->setModificationParams($element, true); $key = $element->getKey(); if (empty($key) and $apiElement->id == 1) { if ($element instanceof Asset) { $element->setFilename("home_" . uniqid()); } else { $element->setKey("home_" . uniqid()); } } else { if (empty($key)) { throw new \Exception("Cannot create element without key "); } } $parent = $parentClassName::getByPath($path); if (Element\Service::getType($rootElement) == $maintype and $parent) { $element->setParentId($parent->getId()); $apiElement->parentId = $parent->getId(); $existingElement = $parentClassName::getByPath($parent->getFullPath() . "/" . $element->getKey()); if ($existingElement) { //set dummy key to avoid duplicate paths if ($element instanceof Asset) { $element->setFilename(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getFilename()); } else { $element->setKey(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getKey()); } } } else { if (Element\Service::getType($rootElement) != $maintype) { //this is a related element - try to import it to it's original path or set the parent to home folder $potentialParent = $parentClassName::getByPath($path); //set dummy key to avoid duplicate paths if ($element instanceof Asset) { $element->setFilename(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getFilename()); } else { $element->setKey(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getKey()); } if ($potentialParent) { $element->setParentId($potentialParent->getId()); //set actual id and path for second run $apiElements[$apiKey]["path"] = $potentialParent->getFullPath(); $apiElement->parentId = $potentialParent->getId(); } else { $element->setParentId(1); //set actual id and path for second run $apiElements[$apiKey]["path"] = "/"; $apiElement->parentId = 1; } } else { $element->setParentId($rootElement->getId()); //set actual id and path for second run $apiElements[$apiKey]["path"] = $rootElement->getFullPath(); $apiElement->parentId = $rootElement->getId(); //set dummy key to avoid duplicate paths if ($element instanceof Asset) { $element->setFilename(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getFilename()); } else { $element->setKey(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getKey()); } } } //if element exists, make temp key permanent by setting it in apiElement if ($parentClassName::getByPath($fullPath)) { if ($element instanceof Asset) { $apiElement->filename = $element->getFilename(); } else { $apiElement->key = $element->getKey(); } } $element->save(); //todo save type and id for later rollback $this->importInfo[Element\Service::getType($element) . "_" . $element->getId()] = array("id" => $element->getId(), "type" => Element\Service::getType($element), "fullpath" => $element->getFullPath()); return $element; }
/** Encode value for packing it into a single column. * @param mixed $value * @param Model\Object\AbstractObject $object * @param mixed $params * @return mixed */ public function marshal($value, $object = null, $params = []) { if ($value instanceof Object\Data\Hotspotimage) { $result = []; $result["hotspots"] = $value->getHotspots(); $result["marker"] = $value->getMarker(); $result["crop"] = $value->getCrop(); $image = $value->getImage(); if ($image) { $type = Element\Service::getType($image); $id = $image->getId(); $result["image"] = ["type" => $type, "id" => $id]; } return $result; } return null; }
/** Encode value for packing it into a single column. * @param mixed $value * @param Model\Object\AbstractObject $object * @param mixed $params * @return mixed */ public function marshal($value, $object = null, $params = []) { if (is_array($value)) { $result = []; /** @var $elementMetadata Object\Data\ElementMetadata */ foreach ($value as $elementMetadata) { $element = $elementMetadata->getElement(); $type = Element\Service::getType($element); $id = $element->getId(); $result[] = ["element" => ["type" => $type, "id" => $id], "fieldname" => $elementMetadata->getFieldname(), "columns" => $elementMetadata->getColumns(), "data" => $elementMetadata->data]; } return $result; } return null; }
/** * @param Object\AbstractObject $object * @return array|mixed|null */ public function getForWebserviceExport($object) { $data = $this->getDataFromObjectParam($object); if (is_array($data)) { $items = array(); foreach ($data as $metaObject) { $eo = $metaObject->getElement(); if ($eo instanceof Element\ElementInterface) { $item = array(); $item["type"] = Element\Service::getType($eo); $item["id"] = $eo->getId(); foreach ($this->getColumns() as $c) { $getter = "get" . ucfirst($c['key']); $item[$c['key']] = $metaObject->{$getter}(); } $items[] = $item; } } return $items; } else { return null; } }