Ejemplo n.º 1
0
 /**
  * @param Document|Asset|Object_Abstract $element
  * @return array
  */
 public static function getDependencyForFrontend($element)
 {
     if ($element instanceof Document) {
         return array("id" => $element->getId(), "path" => $element->getFullPath(), "type" => "document", "subtype" => $element->getType());
     } else {
         if ($element instanceof Asset) {
             return array("id" => $element->getId(), "path" => $element->getFullPath(), "type" => "asset", "subtype" => $element->getType());
         } else {
             if ($element instanceof Object_Abstract) {
                 return array("id" => $element->getId(), "path" => $element->getFullPath(), "type" => "object", "subtype" => $element->geto_Type());
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @param Asset $asset
  * @return array|string
  */
 protected function getTreeNodeConfig($asset)
 {
     $tmpAsset = array("id" => $asset->getId(), "text" => $asset->getFilename(), "type" => $asset->getType(), "path" => $asset->getFullPath(), "basePath" => $asset->getPath(), "locked" => $asset->isLocked(), "lockOwner" => $asset->getLocked() ? true : false, "elementType" => "asset", "permissions" => array("remove" => $asset->isAllowed("delete"), "settings" => $asset->isAllowed("settings"), "rename" => $asset->isAllowed("rename"), "publish" => $asset->isAllowed("publish"), "view" => $asset->isAllowed("view")));
     // set type specific settings
     if ($asset->getType() == "folder") {
         $tmpAsset["leaf"] = false;
         $tmpAsset["expanded"] = $asset->hasNoChilds();
         $tmpAsset["iconCls"] = "pimcore_icon_folder";
         $tmpAsset["permissions"]["create"] = $asset->isAllowed("create");
     } else {
         $tmpAsset["leaf"] = true;
         $tmpAsset["iconCls"] = "pimcore_icon_" . Pimcore_File::getFileExtension($asset->getFilename());
     }
     $tmpAsset["qtipCfg"] = array("title" => "ID: " . $asset->getId());
     if ($asset->getType() == "image") {
         try {
             $tmpAsset["qtipCfg"] = array("title" => "ID: " . $asset->getId(), "text" => '<img src="/admin/asset/get-image-thumbnail/id/' . $asset->getId() . '/width/130/aspectratio/true" width="130" />', "width" => 140);
             // this is for backward-compatibilty, to calculate the dimensions if they are not there
             if (!$asset->getCustomSetting("imageDimensionsCalculated")) {
                 $asset->save();
             }
             if ($asset->getCustomSetting("imageWidth") && $asset->getCustomSetting("imageHeight")) {
                 $tmpAsset["imageWidth"] = $asset->getCustomSetting("imageWidth");
                 $tmpAsset["imageHeight"] = $asset->getCustomSetting("imageHeight");
             }
         } catch (Exception $e) {
             Logger::debug("Cannot get dimensions of image, seems to be broken.");
         }
     } else {
         if ($asset->getType() == "video") {
             try {
                 if (Pimcore_Video::isAvailable()) {
                     $tmpAsset["qtipCfg"] = array("title" => "ID: " . $asset->getId(), "text" => '<img src="/admin/asset/get-video-thumbnail/id/' . $asset->getId() . '/width/130/aspectratio/true" width="130" />', "width" => 140);
                 }
             } catch (Exception $e) {
                 Logger::debug("Cannot get dimensions of video, seems to be broken.");
             }
         }
     }
     $tmpAsset["cls"] = "";
     if ($asset->isLocked()) {
         $tmpAsset["cls"] .= "pimcore_treenode_locked ";
     }
     if ($asset->getLocked()) {
         $tmpAsset["cls"] .= "pimcore_treenode_lockOwner ";
     }
     return $tmpAsset;
 }
Ejemplo n.º 3
0
 /**
  * Static helper to get an asset by the passed id (returned is not the concrete asset like Asset_Folder!)
  *
  * @param integer $id
  * @return Asset
  */
 public static function getById($id)
 {
     $id = intval($id);
     if ($id < 1) {
         return null;
     }
     $cacheKey = "asset_" . $id;
     try {
         $asset = Zend_Registry::get($cacheKey);
         if (!$asset) {
             throw new Exception("Asset in registry is null");
         }
     } catch (Exception $e) {
         try {
             if (!($asset = Pimcore_Model_Cache::load($cacheKey))) {
                 $asset = new Asset();
                 $asset->getResource()->getById($id);
                 $typeClass = "Asset_" . ucfirst($asset->getType());
                 $typeClass = Pimcore_Tool::getModelClassMapping($typeClass);
                 if (class_exists($typeClass)) {
                     $asset = new $typeClass();
                     Zend_Registry::set($cacheKey, $asset);
                     $asset->getResource()->getById($id);
                     Pimcore_Model_Cache::save($asset, $cacheKey);
                 }
             } else {
                 Zend_Registry::set($cacheKey, $asset);
             }
         } catch (Exception $e) {
             Logger::warning($e);
             return null;
         }
     }
     if (!$asset) {
         return null;
     }
     return $asset;
 }
Ejemplo n.º 4
0
 /**
  * @see Object_Class_Data::getDataForEditmode
  * @param Asset|Document|Object_Abstract $data
  * @param null|Object_Abstract $object
  * @return array
  */
 public function getDataForEditmode($data, $object = null)
 {
     if ($data) {
         $r = array("id" => $data->getId(), "path" => $data->getFullPath());
         if ($data instanceof Document) {
             $r["subtype"] = $data->getType();
             $r["type"] = "document";
         } else {
             if ($data instanceof Asset) {
                 $r["subtype"] = $data->getType();
                 $r["type"] = "asset";
             } else {
                 if ($data instanceof Object_Abstract) {
                     $r["subtype"] = $data->getO_Type();
                     $r["type"] = "object";
                 }
             }
         }
         return $r;
     }
     return;
 }
Ejemplo n.º 5
0
 /**
  *
  * Checks if an asset is an allowed relation
  * @param Asset $asset
  * @return boolean
  */
 protected function allowAssetRelation($asset)
 {
     $allowedAssetTypes = $this->getAssetTypes();
     $allowed = true;
     if (!$this->getAssetsAllowed()) {
         $allowed = false;
     } else {
         if ($this->getAssetsAllowed() and is_array($allowedAssetTypes) and count($allowedAssetTypes) > 0) {
             //check for allowed asset types
             foreach ($allowedAssetTypes as $t) {
                 if (is_array($t) && array_key_exists("assetTypes", $t)) {
                     $t = $t["assetTypes"];
                 }
                 if ($t && is_string($t)) {
                     $allowedTypes[] = $t;
                 }
             }
             if (!in_array($asset->getType(), $allowedTypes)) {
                 $allowed = false;
             }
         } else {
             //don't check if no allowed asset types set
         }
     }
     \Logger::debug("checked object relation to target asset [" . $asset->getId() . "] in field [" . $this->getName() . "], allowed:" . $allowed);
     return $allowed;
 }