getElementById() 공개 정적인 메소드

public static getElementById ( string $type, integer $id ) : Pimcore\Model\Element\ElementInterface
$type string
$id integer
리턴 Pimcore\Model\Element\ElementInterface
예제 #1
0
 public function setElements()
 {
     if (empty($this->elements)) {
         $this->elements = [];
         foreach ($this->elementIds as $elementId) {
             $el = Element\Service::getElementById($elementId["type"], $elementId["id"]);
             if ($el instanceof Element\ElementInterface) {
                 $this->elements[] = $el;
             }
         }
     }
     return $this;
 }
예제 #2
0
 /**
  * @param $cid
  * @param $ctype
  * @throws \Exception
  */
 public function getByElement($cid, $ctype)
 {
     $data = $this->db->fetchRow("SELECT * FROM edit_lock WHERE cid = ? AND ctype = ?", array($cid, $ctype));
     if (!$data["id"]) {
         throw new \Exception("Lock with cid " . $cid . " and ctype " . $ctype . " not found");
     }
     $this->assignVariablesToModel($data);
     // add elements path
     $element = Model\Element\Service::getElementById($ctype, $cid);
     if ($element) {
         $this->model->setCpath($element->getFullpath());
     }
 }
예제 #3
0
 /**
  * @static
  * @return mixed|\Zend_Config
  */
 public static function getWebsiteConfig()
 {
     if (\Zend_Registry::isRegistered("pimcore_config_website")) {
         $config = \Zend_Registry::get("pimcore_config_website");
     } else {
         $cacheKey = "website_config";
         $siteId = null;
         if (Model\Site::isSiteRequest()) {
             $siteId = Model\Site::getCurrentSite()->getId();
             $cacheKey = $cacheKey . "_site_" . $siteId;
         }
         if (!($config = Cache::load($cacheKey))) {
             $settingsArray = array();
             $cacheTags = array("website_config", "system", "config", "output");
             $list = new Model\WebsiteSetting\Listing();
             $list = $list->load();
             foreach ($list as $item) {
                 $key = $item->getName();
                 $itemSiteId = $item->getSiteId();
                 if ($itemSiteId != 0 && $itemSiteId != $siteId) {
                     continue;
                 }
                 $s = null;
                 switch ($item->getType()) {
                     case "document":
                     case "asset":
                     case "object":
                         $s = Model\Element\Service::getElementById($item->getType(), $item->getData());
                         break;
                     case "bool":
                         $s = (bool) $item->getData();
                         break;
                     case "text":
                         $s = (string) $item->getData();
                         break;
                 }
                 if ($s instanceof Model\Element\ElementInterface) {
                     $cacheTags = $s->getCacheTags($cacheTags);
                 }
                 if (isset($s)) {
                     $settingsArray[$key] = $s;
                 }
             }
             $config = new \Zend_Config($settingsArray, true);
             Cache::save($config, $cacheKey, $cacheTags, null, 998);
         }
         self::setWebsiteConfig($config);
     }
     return $config;
 }
예제 #4
0
 public function getRelationAttribute($attributeName)
 {
     $relationObjectArray = array();
     if ($this->relations[$attributeName]) {
         foreach ($this->relations[$attributeName] as $relation) {
             $relationObject = \Pimcore\Model\Element\Service::getElementById($relation['type'], $relation['id']);
             if ($relationObject) {
                 $relationObjectArray[] = $relationObject;
             }
         }
     }
     if (count($relationObjectArray) == 1) {
         return $relationObjectArray[0];
     } else {
         if (count($relationObjectArray) > 1) {
             return $relationObjectArray;
         } else {
             return null;
         }
     }
 }
예제 #5
0
 public function roleGetAction()
 {
     $role = User\Role::getById(intval($this->getParam("id")));
     // workspaces
     $types = ["asset", "document", "object"];
     foreach ($types as $type) {
         $workspaces = $role->{"getWorkspaces" . ucfirst($type)}();
         foreach ($workspaces as $workspace) {
             $el = Element\Service::getElementById($type, $workspace->getCid());
             if ($el) {
                 // direct injection => not nice but in this case ok ;-)
                 $workspace->path = $el->getRealFullPath();
             }
         }
     }
     // get available permissions
     $availableUserPermissionsList = new User\Permission\Definition\Listing();
     $availableUserPermissions = $availableUserPermissionsList->load();
     $availablePerspectives = \Pimcore\Config::getAvailablePerspectives(null);
     $this->_helper->json(["success" => true, "role" => $role, "permissions" => $role->generatePermissionList(), "classes" => $role->getClasses(), "docTypes" => $role->getDocTypes(), "availablePermissions" => $availableUserPermissions, "availablePerspectives" => $availablePerspectives]);
 }
예제 #6
0
파일: Href.php 프로젝트: sfie/pimcore
 /**
  * @param mixed $value
  * @param null $relatedObject
  * @param null $idMapper
  * @return mixed|void
  * @throws \Exception
  */
 public function getFromWebserviceImport($value, $relatedObject = null, $idMapper = null)
 {
     if (empty($value)) {
         return null;
     } else {
         $value = (array) $value;
         if (array_key_exists("id", $value) and array_key_exists("type", $value)) {
             $type = $value["type"];
             $id = $value["id"];
             if ($idMapper) {
                 $id = $idMapper->getMappedId($type, $id);
             }
             if ($id) {
                 $el = Element\Service::getElementById($type, $id);
             }
             if ($el instanceof Element\ElementInterface) {
                 return $el;
             } else {
                 if ($idMapper && $idMapper->ignoreMappingFailures()) {
                     $idMapper->recordMappingFailure("object", $relatedObject->getId(), $type, $value["id"]);
                 } else {
                     throw new \Exception("cannot get values from web service import - invalid href relation");
                 }
             }
         } else {
             throw new \Exception("cannot get values from web service import - invalid data");
         }
     }
 }
예제 #7
0
파일: Objects.php 프로젝트: pimcore/pimcore
 /** See marshal
  * @param mixed $value
  * @param Model\Object\AbstractObject $object
  * @param mixed $params
  * @return mixed
  */
 public function unmarshal($value, $object = null, $params = [])
 {
     if (is_array($value)) {
         $result = [];
         foreach ($value as $elementData) {
             $type = $elementData["type"];
             $id = $elementData["id"];
             $element = Element\Service::getElementById($type, $id);
             if ($element) {
                 $result[] = $element;
             }
         }
         return $result;
     }
 }
예제 #8
0
 public function unlockPropagateAction()
 {
     $success = false;
     $element = Element\Service::getElementById($this->getParam("type"), $this->getParam("id"));
     if ($element) {
         $element->unlockPropagate();
         $success = true;
     }
     $this->_helper->json(["success" => $success]);
 }
예제 #9
0
 /**
  * @see Object\ClassDefinition\Data::getDataFromResource
  * @param Object\Data\Hotspotimage $data
  * @return Asset
  */
 public function getDataFromResource($data)
 {
     if ($data[$this->getName() . "__image"] || $data[$this->getName() . "__hotspots"]) {
         $metaData = $data[$this->getName() . "__hotspots"];
         // check if the data is JSON (backward compatibility)
         $md = json_decode($metaData, true);
         if (!$md) {
             $md = Serialize::unserialize($metaData);
         } else {
             if (is_array($md) && count($md)) {
                 $md["hotspots"] = $md;
             }
         }
         $hotspots = empty($md["hotspots"]) ? null : $md["hotspots"];
         $marker = empty($md["marker"]) ? null : $md["marker"];
         $crop = empty($md["crop"]) ? null : $md["crop"];
         $rewritePath = function ($data) {
             if (!is_array($data)) {
                 return array();
             }
             foreach ($data as &$element) {
                 if (array_key_exists("data", $element) && is_array($element["data"]) && count($element["data"]) > 0) {
                     foreach ($element["data"] as &$metaData) {
                         if (in_array($metaData["type"], array("object", "asset", "document"))) {
                             $el = Element\Service::getElementById($metaData["type"], $metaData["value"]);
                             $metaData["value"] = $el;
                         }
                     }
                 }
             }
             return $data;
         };
         $hotspots = $rewritePath($hotspots);
         $marker = $rewritePath($marker);
         return new Object\Data\Hotspotimage($data[$this->getName() . "__image"], $hotspots, $marker, $crop);
     }
     return null;
 }
예제 #10
0
파일: Asset.php 프로젝트: Gerhard13/pimcore
 /**
  * @return array
  */
 public function getMetadata($name = null, $language = null)
 {
     $convert = function ($metaData) {
         if (in_array($metaData["type"], ["asset", "document", "object"]) && is_numeric($metaData["data"])) {
             return Element\Service::getElementById($metaData["type"], $metaData["data"]);
         }
         return $metaData["data"];
     };
     if ($name) {
         if ($language === null) {
             if (\Zend_Registry::isRegistered("Zend_Locale")) {
                 $language = (string) \Zend_Registry::get("Zend_Locale");
             }
         }
         $data = null;
         foreach ($this->metadata as $md) {
             if ($md["name"] == $name) {
                 if ($language == $md["language"]) {
                     return $convert($md);
                 }
                 if (empty($md["language"])) {
                     $data = $md;
                 }
             }
         }
         if ($data) {
             return $convert($data);
         }
         return null;
     }
     $metaData = $this->metadata;
     foreach ($metaData as &$md) {
         $md["data"] = $convert($md);
     }
     return $metaData;
 }
 /**
  * (PHP 5 &gt;= 5.0.0)<br/>
  * Offset to retrieve
  * @link http://php.net/manual/en/arrayaccess.offsetget.php
  * @param mixed $offset <p>
  * The offset to retrieve.
  * </p>
  * @return mixed Can return all value types.
  */
 public function offsetGet($offset)
 {
     if ($this->offsetExists($offset)) {
         if ($offset == "value" && in_array($this->type, ["object", "asset", "document"])) {
             return Model\Element\Service::getElementById($this->type, $this->value);
         } else {
             return $this->{$offset};
         }
     }
     return null;
 }
예제 #12
0
 /**
  * @param mixed $value
  * @param null $relatedObject
  * @param null $idMapper
  * @return mixed|void
  * @throws \Exception
  */
 public function getFromWebserviceImport($value, $relatedObject = null, $idMapper = null)
 {
     if (empty($value)) {
         return null;
     } elseif (is_array($value)) {
         $hrefs = array();
         foreach ($value as $href) {
             // cast is needed to make it work for both SOAP and REST
             $href = (array) $href;
             if (is_array($href) and array_key_exists("id", $href) and array_key_exists("type", $href)) {
                 $type = $href["type"];
                 $id = $href["id"];
                 if ($idMapper) {
                     $id = $idMapper->getMappedId($type, $id);
                 }
                 $e = null;
                 if ($id) {
                     $e = Element\Service::getElementById($type, $id);
                 }
                 if ($e instanceof Element\ElementInterface) {
                     $hrefs[] = $e;
                 } else {
                     if (!$idMapper || !$idMapper->ignoreMappingFailures()) {
                         throw new \Exception("cannot get values from web service import - unknown element of type [ " . $href["type"] . " ] with id [" . $href["id"] . "] is referenced");
                     } else {
                         $idMapper->recordMappingFailure("object", $relatedObject->getId(), $type, $href["id"]);
                     }
                 }
             }
         }
         return $hrefs;
     } else {
         throw new \Exception("cannot get values from web service import - invalid data");
     }
 }
예제 #13
0
파일: Href.php 프로젝트: pimcore/pimcore
 /** See marshal
  * @param mixed $value
  * @param Model\Object\AbstractObject $object
  * @param mixed $params
  * @return mixed
  */
 public function unmarshal($value, $object = null, $params = [])
 {
     if (is_array($value)) {
         $type = $value["type"];
         $id = $value["id"];
         return Element\Service::getElementById($type, $id);
     }
 }
예제 #14
0
 /**
  * Rewrites id from source to target, $idMapping contains
  * array(
  *  "document" => array(
  *      SOURCE_ID => TARGET_ID,
  *      SOURCE_ID => TARGET_ID
  *  ),
  *  "object" => array(...),
  *  "asset" => array(...)
  * )
  * @param mixed $data
  * @param array $idMapping
  * @return array
  */
 public function rewriteIdsService($data, $idMapping)
 {
     if (is_array($data)) {
         foreach ($data as &$element) {
             $id = $element->getId();
             $type = Element\Service::getElementType($element);
             if (array_key_exists($type, $idMapping) && array_key_exists($id, $idMapping[$type])) {
                 $element = Element\Service::getElementById($type, $idMapping[$type][$id]);
             }
         }
     }
     return $data;
 }
예제 #15
0
 /**
  * Checks if data is valid for current data field
  *
  * @param mixed $data
  * @param boolean $omitMandatoryCheck
  * @throws \Exception
  */
 public function checkValidity($data, $omitMandatoryCheck = false)
 {
     if (!$omitMandatoryCheck and $this->getMandatory() and empty($data)) {
         throw new \Exception("Empty mandatory field [ " . $this->getName() . " ]");
     }
     $dependencies = Text::getDependenciesOfWysiwygText($data);
     if (is_array($dependencies)) {
         foreach ($dependencies as $key => $value) {
             $el = Element\Service::getElementById($value['type'], $value['id']);
             if (!$el) {
                 throw new \Exception("invalid dependency in wysiwyg text");
             }
         }
     }
 }
 public function addAction()
 {
     $element = Element\Service::getElementById($this->getParam("type"), $this->getParam("id"));
     if ($element) {
         $type = Element\Service::getElementType($element);
         $listClass = "\\Pimcore\\Model\\" . ucfirst($type) . "\\Listing";
         $list = new $listClass();
         $list->setCondition(($type == "object" ? "o_" : "") . "path LIKE '" . $element->getFullPath() . "/%'");
         $children = $list->getTotalCount();
         if ($children <= 100) {
             Recyclebin\Item::create($element, $this->getUser());
         }
         $this->_helper->json(array("success" => true));
     } else {
         $this->_helper->json(array("success" => false));
     }
 }
예제 #17
0
 /**
  * @return void
  */
 public function findAction()
 {
     $user = $this->getUser();
     $query = $this->getParam("query");
     if ($query == "*") {
         $query = "";
     }
     $query = str_replace("%", "*", $query);
     $types = explode(",", $this->getParam("type"));
     $subtypes = explode(",", $this->getParam("subtype"));
     $classnames = explode(",", $this->getParam("class"));
     if ($this->getParam("type") == "object" && is_array($classnames) && empty($classnames[0])) {
         $subtypes = array("object", "variant", "folder");
     }
     $offset = intval($this->getParam("start"));
     $limit = intval($this->getParam("limit"));
     $offset = $offset ? $offset : 0;
     $limit = $limit ? $limit : 50;
     $searcherList = new Data\Listing();
     $conditionParts = array();
     $db = \Pimcore\Db::get();
     //exclude forbidden assets
     if (in_array("asset", $types)) {
         if (!$user->isAllowed("assets")) {
             $forbiddenConditions[] = " `type` != 'asset' ";
         } else {
             $forbiddenAssetPaths = Element\Service::findForbiddenPaths("asset", $user);
             if (count($forbiddenAssetPaths) > 0) {
                 for ($i = 0; $i < count($forbiddenAssetPaths); $i++) {
                     $forbiddenAssetPaths[$i] = " (maintype = 'asset' AND fullpath not like " . $db->quote($forbiddenAssetPaths[$i] . "%") . ")";
                 }
                 $forbiddenConditions[] = implode(" AND ", $forbiddenAssetPaths);
             }
         }
     }
     //exclude forbidden documents
     if (in_array("document", $types)) {
         if (!$user->isAllowed("documents")) {
             $forbiddenConditions[] = " `type` != 'document' ";
         } else {
             $forbiddenDocumentPaths = Element\Service::findForbiddenPaths("document", $user);
             if (count($forbiddenDocumentPaths) > 0) {
                 for ($i = 0; $i < count($forbiddenDocumentPaths); $i++) {
                     $forbiddenDocumentPaths[$i] = " (maintype = 'document' AND fullpath not like " . $db->quote($forbiddenDocumentPaths[$i] . "%") . ")";
                 }
                 $forbiddenConditions[] = implode(" AND ", $forbiddenDocumentPaths);
             }
         }
     }
     //exclude forbidden objects
     if (in_array("object", $types)) {
         if (!$user->isAllowed("objects")) {
             $forbiddenConditions[] = " `type` != 'object' ";
         } else {
             $forbiddenObjectPaths = Element\Service::findForbiddenPaths("object", $user);
             if (count($forbiddenObjectPaths) > 0) {
                 for ($i = 0; $i < count($forbiddenObjectPaths); $i++) {
                     $forbiddenObjectPaths[$i] = " (maintype = 'object' AND fullpath not like " . $db->quote($forbiddenObjectPaths[$i] . "%") . ")";
                 }
                 $forbiddenConditions[] = implode(" AND ", $forbiddenObjectPaths);
             }
         }
     }
     if ($forbiddenConditions) {
         $conditionParts[] = "(" . implode(" AND ", $forbiddenConditions) . ")";
     }
     if (!empty($query)) {
         $queryCondition = "( MATCH (`data`,`properties`) AGAINST (" . $db->quote($query) . " IN BOOLEAN MODE) )";
         // the following should be done with an exact-search now "ID", because the Element-ID is now in the fulltext index
         // if the query is numeric the user might want to search by id
         //if(is_numeric($query)) {
         //$queryCondition = "(" . $queryCondition . " OR id = " . $db->quote($query) ." )";
         //}
         $conditionParts[] = $queryCondition;
     }
     //For objects - handling of bricks
     $fields = array();
     $bricks = array();
     if ($this->getParam("fields")) {
         $fields = $this->getParam("fields");
         foreach ($fields as $f) {
             $parts = explode("~", $f);
             if (substr($f, 0, 1) == "~") {
                 //                    $type = $parts[1];
                 //                    $field = $parts[2];
                 //                    $keyid = $parts[3];
                 // key value, ignore for now
             } else {
                 if (count($parts) > 1) {
                     $bricks[$parts[0]] = $parts[0];
                 }
             }
         }
     }
     // filtering for objects
     if ($this->getParam("filter") && $this->getParam("class")) {
         $class = Object\ClassDefinition::getByName($this->getParam("class"));
         $conditionFilters = Object\Service::getFilterCondition($this->getParam("filter"), $class);
         $join = "";
         foreach ($bricks as $ob) {
             $join .= " LEFT JOIN object_brick_query_" . $ob . "_" . $class->getId();
             $join .= " `" . $ob . "`";
             $join .= " ON `" . $ob . "`.o_id = `object_" . $class->getId() . "`.o_id";
         }
         $conditionParts[] = "( id IN (SELECT `object_" . $class->getId() . "`.o_id FROM object_" . $class->getId() . $join . " WHERE " . $conditionFilters . ") )";
     }
     if (is_array($types) and !empty($types[0])) {
         foreach ($types as $type) {
             $conditionTypeParts[] = $db->quote($type);
         }
         if (in_array("folder", $subtypes)) {
             $conditionTypeParts[] = $db->quote('folder');
         }
         $conditionParts[] = "( maintype IN (" . implode(",", $conditionTypeParts) . ") )";
     }
     if (is_array($subtypes) and !empty($subtypes[0])) {
         foreach ($subtypes as $subtype) {
             $conditionSubtypeParts[] = $db->quote($subtype);
         }
         $conditionParts[] = "( type IN (" . implode(",", $conditionSubtypeParts) . ") )";
     }
     if (is_array($classnames) and !empty($classnames[0])) {
         if (in_array("folder", $subtypes)) {
             $classnames[] = "folder";
         }
         foreach ($classnames as $classname) {
             $conditionClassnameParts[] = $db->quote($classname);
         }
         $conditionParts[] = "( subtype IN (" . implode(",", $conditionClassnameParts) . ") )";
     }
     if (count($conditionParts) > 0) {
         $condition = implode(" AND ", $conditionParts);
         //echo $condition; die();
         $searcherList->setCondition($condition);
     }
     $searcherList->setOffset($offset);
     $searcherList->setLimit($limit);
     // do not sort per default, it is VERY SLOW
     //$searcherList->setOrder("desc");
     //$searcherList->setOrderKey("modificationdate");
     if ($this->getParam("sort")) {
         // we need a special mapping for classname as this is stored in subtype column
         $sortMapping = ["classname" => "subtype"];
         $sort = $this->getParam("sort");
         if (array_key_exists($this->getParam("sort"), $sortMapping)) {
             $sort = $sortMapping[$this->getParam("sort")];
         }
         $searcherList->setOrderKey($sort);
     }
     if ($this->getParam("dir")) {
         $searcherList->setOrder($this->getParam("dir"));
     }
     $hits = $searcherList->load();
     $elements = array();
     foreach ($hits as $hit) {
         $element = Element\Service::getElementById($hit->getId()->getType(), $hit->getId()->getId());
         if ($element->isAllowed("list")) {
             if ($element instanceof Object\AbstractObject) {
                 $data = Object\Service::gridObjectData($element, $fields);
             } else {
                 if ($element instanceof Document) {
                     $data = Document\Service::gridDocumentData($element);
                 } else {
                     if ($element instanceof Asset) {
                         $data = Asset\Service::gridAssetData($element);
                     }
                 }
             }
             $elements[] = $data;
         } else {
             //TODO: any message that view is blocked?
             //$data = Element\Service::gridElementData($element);
         }
     }
     // only get the real total-count when the limit parameter is given otherwise use the default limit
     if ($this->getParam("limit")) {
         $totalMatches = $searcherList->getTotalCount();
     } else {
         $totalMatches = count($elements);
     }
     $this->_helper->json(array("data" => $elements, "success" => true, "total" => $totalMatches));
     $this->removeViewRenderer();
 }
예제 #18
0
 /**
  *
  */
 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();
         }
     }
 }
예제 #19
0
 private function getWebsiteSettingForEditMode($item)
 {
     $resultItem = array("id" => $item->getId(), "name" => $item->getName(), "type" => $item->getType(), "data" => null, "siteId" => $item->getSiteId(), "creationDate" => $item->getCreationDate(), "modificationDate" => $item->getModificationDate());
     switch ($item->getType()) {
         case "document":
         case "asset":
         case "object":
             $element = Element\Service::getElementById($item->getType(), $item->getData());
             if ($element) {
                 $resultItem["data"] = $element->getFullPath();
             }
             break;
         default:
             $resultItem["data"] = $item->getData("data");
             break;
     }
     return $resultItem;
 }
예제 #20
0
 /**
  * @param $object
  * @param bool $disableMappingExceptions
  * @param null $idMapper
  * @throws \Exception
  */
 public function reverseMap($object, $disableMappingExceptions = false, $idMapper = null)
 {
     $keys = get_object_vars($this);
     foreach ($keys as $key => $value) {
         $method = "set" . $key;
         if (method_exists($object, $method)) {
             if ($object instanceof Element\ElementInterface && $key == "properties") {
                 $value = $this->mapProperties($value);
             }
             $object->{$method}($value);
         }
     }
     if ($object instanceof Element\ElementInterface) {
         // Classes do not have properties
         $object->setProperties(null);
     }
     if (is_array($this->properties)) {
         foreach ($this->properties as $propertyWs) {
             $propertyWs = (array) $propertyWs;
             $dat = $propertyWs["data"];
             $type = $propertyWs["type"];
             if (in_array($type, array("object", "document", "asset"))) {
                 $id = $propertyWs["data"];
                 $type = $propertyWs["type"];
                 $dat = null;
                 if ($idMapper) {
                     $id = $idMapper->getMappedId($type, $id);
                 }
                 if ($id) {
                     $dat = Element\Service::getElementById($type, $id);
                 }
                 if (is_numeric($propertyWs["data"]) and !$dat) {
                     if (!$idMapper || !$idMapper->ignoreMappingFailures()) {
                         throw new \Exception("cannot import property [ " . $type . " ] because it references unknown " . $propertyWs["data"]);
                     } else {
                         $idMapper->recordMappingFailure("object", $object->getId(), $type, $propertyWs["data"]);
                     }
                 }
             } elseif ($type == "date") {
                 $dat = new \Pimcore\Date(strtotime($propertyWs["data"]));
             } else {
                 $dat = $propertyWs["data"];
             }
             $object->setProperty($propertyWs["name"], $propertyWs["type"], $dat, $propertyWs["inherited"], $propertyWs["inheritable"]);
         }
     }
 }
예제 #21
0
파일: Renderlet.php 프로젝트: sfie/pimcore
 /**
  * @return bool
  */
 public function checkValidity()
 {
     $sane = true;
     if ($this->id) {
         $el = Element\Service::getElementById($this->type, $this->id);
         if (!$el instanceof Element\ElementInterface) {
             $sane = false;
             \Logger::notice("Detected insane relation, removing reference to non existent " . $this->type . " with id [" . $this->id . "]");
             $this->id = null;
             $this->type = null;
             $this->o = null;
             $this->subtype = null;
         }
     }
     return $sane;
 }
예제 #22
0
파일: Config.php 프로젝트: pimcore/pimcore
 /**
  * @static
  * @return mixed|\Zend_Config
  */
 public static function getWebsiteConfig()
 {
     if (\Zend_Registry::isRegistered("pimcore_config_website")) {
         $config = \Zend_Registry::get("pimcore_config_website");
     } else {
         $cacheKey = "website_config";
         $siteId = null;
         if (Model\Site::isSiteRequest()) {
             $siteId = Model\Site::getCurrentSite()->getId();
         } elseif (Tool::isFrontentRequestByAdmin()) {
             // this is necessary to set the correct settings in editmode/preview (using the main domain)
             $front = \Zend_Controller_Front::getInstance();
             $originDocument = $front->getRequest()->getParam("document");
             if ($originDocument) {
                 $site = Tool\Frontend::getSiteForDocument($originDocument);
                 if ($site) {
                     $siteId = $site->getId();
                 }
             }
         }
         if ($siteId) {
             $cacheKey = $cacheKey . "_site_" . $siteId;
         }
         if (!($config = Cache::load($cacheKey))) {
             $settingsArray = [];
             $cacheTags = ["website_config", "system", "config", "output"];
             $list = new Model\WebsiteSetting\Listing();
             $list = $list->load();
             foreach ($list as $item) {
                 $key = $item->getName();
                 $itemSiteId = $item->getSiteId();
                 if ($itemSiteId != 0 && $itemSiteId != $siteId) {
                     continue;
                 }
                 $s = null;
                 switch ($item->getType()) {
                     case "document":
                     case "asset":
                     case "object":
                         $s = Model\Element\Service::getElementById($item->getType(), $item->getData());
                         break;
                     case "bool":
                         $s = (bool) $item->getData();
                         break;
                     case "text":
                         $s = (string) $item->getData();
                         break;
                 }
                 if ($s instanceof Model\Element\ElementInterface) {
                     $cacheTags = $s->getCacheTags($cacheTags);
                 }
                 if (isset($s)) {
                     $settingsArray[$key] = $s;
                 }
             }
             $config = new \Zend_Config($settingsArray, true);
             Cache::save($config, $cacheKey, $cacheTags, null, 998);
         }
         self::setWebsiteConfig($config);
     }
     return $config;
 }
 /**
  * Rewrites id from source to target, $idMapping contains
  * array(
  *  "document" => array(
  *      SOURCE_ID => TARGET_ID,
  *      SOURCE_ID => TARGET_ID
  *  ),
  *  "object" => array(...),
  *  "asset" => array(...)
  * )
  * @param mixed $object
  * @param array $idMapping
  * @param array $params
  * @return Element\ElementInterface
  */
 public function rewriteIds($object, $idMapping, $params = array())
 {
     $data = $this->getDataFromObjectParam($object, $params);
     if (is_array($data)) {
         foreach ($data as &$metaObject) {
             $eo = $metaObject->getObject();
             if ($eo instanceof Element\ElementInterface) {
                 $id = $eo->getId();
                 $type = Element\Service::getElementType($eo);
                 if (array_key_exists($type, $idMapping) && array_key_exists($id, $idMapping[$type])) {
                     $newElement = Element\Service::getElementById($type, $idMapping[$type][$id]);
                     $metaObject->setObject($newElement);
                 }
             }
         }
     }
     return $data;
 }
예제 #24
0
 /**
  * @static
  * @param $text
  * @return array
  */
 public static function getElementsInWysiwyg($text)
 {
     $hash = "elements_wysiwyg_text_" . md5($text);
     if (\Zend_Registry::isRegistered($hash)) {
         return \Zend_Registry::get($hash);
     }
     $elements = array();
     $matches = self::getElementsTagsInWysiwyg($text);
     if (count($matches[2]) > 0) {
         for ($i = 0; $i < count($matches[2]); $i++) {
             preg_match("/[0-9]+/", $matches[2][$i], $idMatches);
             preg_match("/asset|object|document/", $matches[3][$i], $typeMatches);
             $id = $idMatches[0];
             $type = $typeMatches[0];
             $element = Element\Service::getElementById($type, $id);
             if ($id && $type && $element instanceof Element\ElementInterface) {
                 $elements[] = array("id" => $id, "type" => $type, "element" => $element);
             }
         }
     }
     \Zend_Registry::set($hash, $elements);
     return $elements;
 }
예제 #25
0
 /**
  *
  */
 public function getRequiredByDependenciesAction()
 {
     $id = $this->getParam("id");
     $type = $this->getParam("controller");
     $allowedTypes = ["asset", "document", "object"];
     if ($id && in_array($type, $allowedTypes)) {
         $element = Model\Element\Service::getElementById($type, $id);
         if ($element instanceof Model\Element\ElementInterface) {
             $dependencies = Model\Element\Service::getRequiredByDependenciesForFrontend($element->getDependencies());
             $this->_helper->json($dependencies);
         }
     }
     $this->_helper->json(false);
 }
예제 #26
0
 /**
  * @param $metadata
  * @return array
  */
 public static function expandMetadataForEditmode($metadata)
 {
     if (!is_array($metadata)) {
         return $metadata;
     }
     $result = [];
     foreach ($metadata as $item) {
         $type = $item["type"];
         switch ($type) {
             case "document":
             case "asset":
             case "object":
                 $element = $item["data"];
                 if (is_numeric($item["data"])) {
                     $element = Element\Service::getElementById($type, $item["data"]);
                 }
                 if ($element instanceof Element\ElementInterface) {
                     $item["data"] = $element->getRealFullPath();
                 } else {
                     $item["data"] = "";
                 }
                 break;
             default:
                 //nothing to do
         }
         //get the config from an predefined property-set (eg. select)
         $predefined = Model\Metadata\Predefined::getByName($item['name']);
         if ($predefined && $predefined->getType() == $item['type'] && $predefined->getConfig()) {
             $item['config'] = $predefined->getConfig();
         }
         $result[] = $item;
     }
     return $result;
 }
예제 #27
0
 /**
  *
  */
 public function expand()
 {
     switch ($this->type) {
         case "document":
         case "asset":
         case "object":
             if (is_numeric($this->data)) {
                 $element = Element\Service::getElementById($this->type, $this->data);
             }
             if ($element) {
                 $this->data = $element->getFullPath();
             } else {
                 $this->data = "";
             }
             break;
         default:
             //nothing to do
     }
 }
예제 #28
0
 /**
  * @param mixed $value
  * @param null $relatedObject
  * @param null $idMapper
  * @return mixed|void
  * @throws \Exception
  */
 public function getFromWebserviceImport($value, $relatedObject = null, $idMapper = null)
 {
     if ($value instanceof \stdclass) {
         $value = (array) $value;
     }
     if (empty($value)) {
         return null;
     } elseif (is_array($value) and !empty($value['text']) and !empty($value['direct'])) {
         $link = new Object\Data\Link();
         foreach ($value as $key => $value) {
             $method = "set" . ucfirst($key);
             if (method_exists($link, $method)) {
                 $link->{$method}($value);
             } else {
                 throw new \Exception("cannot get values from web service import - invalid data. Unknown Object\\Data\\Link setter [ " . $method . " ]");
             }
         }
         return $link;
     } elseif (is_array($value) and !empty($value['text']) and !empty($value['internalType']) and !empty($value['internal'])) {
         $id = $value['internal'];
         if ($idMapper) {
             $id = $idMapper->getMappedId($value['internalType'], $id);
         }
         $element = Element\Service::getElementById($value['internalType'], $id);
         if (!$element) {
             if ($idMapper && $idMapper->ignoreMappingFailures()) {
                 $idMapper->recordMappingFailure("object", $relatedObject->getId(), $value['internalType'], $value['internal']);
                 return null;
             } else {
                 throw new \Exception("cannot get values from web service import - referencing unknown internal element with type [ " . $value['internalType'] . " ] and id [ " . $value['internal'] . " ]");
             }
         }
         $link = new Object\Data\Link();
         foreach ($value as $key => $value) {
             $method = "set" . ucfirst($key);
             if (method_exists($link, $method)) {
                 $link->{$method}($value);
             } else {
                 throw new \Exception("cannot get values from web service import - invalid data. Unknown Object\\Data\\Link setter [ " . $method . " ]");
             }
         }
         return $link;
     } else {
         throw new \Exception("cannot get values from web service import - invalid data");
     }
 }
예제 #29
0
 /**
  * @see Document\Tag\TagInterface::setDataFromResource
  * @param mixed $data
  * @return void
  */
 public function setDataFromResource($data)
 {
     if (!empty($data)) {
         $data = \Pimcore\Tool\Serialize::unserialize($data);
     }
     $rewritePath = function ($data) {
         if (!is_array($data)) {
             return array();
         }
         foreach ($data as &$page) {
             foreach ($page as &$element) {
                 if (array_key_exists("data", $element) && is_array($element["data"]) && count($element["data"]) > 0) {
                     foreach ($element["data"] as &$metaData) {
                         if (in_array($metaData["type"], array("object", "asset", "document", "link"))) {
                             $elTtype = $metaData["type"];
                             if ($metaData["type"] == "link") {
                                 $elTtype = "document";
                             }
                             $el = Element\Service::getElementById($elTtype, $metaData["value"]);
                             if (!$el && $metaData["type"] == "link") {
                                 $metaData["value"] = $metaData["value"];
                             } else {
                                 $metaData["value"] = $el;
                             }
                         }
                     }
                 }
             }
         }
         return $data;
     };
     if (array_key_exists("hotspots", $data) && is_array($data["hotspots"]) && count($data["hotspots"]) > 0) {
         $data["hotspots"] = $rewritePath($data["hotspots"]);
     }
     $this->id = $data["id"];
     $this->hotspots = $data["hotspots"];
     $this->texts = $data["texts"];
     $this->chapters = $data["chapters"];
     return $this;
 }
예제 #30
0
파일: Video.php 프로젝트: pimcore/pimcore
 /** See marshal
  * @param mixed $value
  * @param Model\Object\AbstractObject $object
  * @param mixed $params
  * @return mixed
  */
 public function unmarshal($value, $object = null, $params = [])
 {
     if (is_array($value)) {
         $video = new Object\Data\Video();
         $video->setType($value["type"]);
         $video->setTitle($value["title"]);
         $video->setDescription($value["description"]);
         if ($value["poster"]) {
             $video->setPoster(Model\Element\Service::getElementById($value["poster"]["type"], $value["poster"]["id"]));
         }
         if ($value["data"]) {
             $video->setData(Model\Element\Service::getElementById($value["data"]["type"], $value["data"]["id"]));
         }
         return $video;
     }
 }