当前位置: 首页>>代码示例>>PHP>>正文


PHP Model\Asset类代码示例

本文整理汇总了PHP中Pimcore\Model\Asset的典型用法代码示例。如果您正苦于以下问题:PHP Asset类的具体用法?PHP Asset怎么用?PHP Asset使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Asset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: load

 /**
  * Loads a list of entries for the specicifies parameters, returns an array of Search\Backend\Data
  *
  * @return array
  */
 public function load()
 {
     $entries = array();
     $data = $this->db->fetchAll("SELECT * FROM search_backend_data" . $this->getCondition() . $this->getGroupBy() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
     foreach ($data as $entryData) {
         if ($entryData['maintype'] == 'document') {
             $element = Document::getById($entryData['id']);
         } else {
             if ($entryData['maintype'] == 'asset') {
                 $element = Asset::getById($entryData['id']);
             } else {
                 if ($entryData['maintype'] == 'object') {
                     $element = Object::getById($entryData['id']);
                 } else {
                     \Logger::err("unknown maintype ");
                 }
             }
         }
         if ($element) {
             $entry = new Search\Backend\Data();
             $entry->setId(new Search\Backend\Data\Id($element));
             $entry->setFullPath($entryData['fullpath']);
             $entry->setType($entryData['type']);
             $entry->setSubtype($entryData['subtype']);
             $entry->setUserOwner($entryData['userowner']);
             $entry->setUserModification($entryData['usermodification']);
             $entry->setCreationDate($entryData['creationdate']);
             $entry->setModificationDate($entryData['modificationdate']);
             $entry->setPublished($entryData['published'] === 0 ? false : true);
             $entries[] = $entry;
         }
     }
     $this->model->setEntries($entries);
     return $entries;
 }
开发者ID:sfie,项目名称:pimcore,代码行数:40,代码来源:Dao.php

示例2: setValuesToDocument

 protected function setValuesToDocument(Document\Link $link)
 {
     // data
     if ($this->getParam("data")) {
         $data = \Zend_Json::decode($this->getParam("data"));
         if (!empty($data["path"])) {
             if ($document = Document::getByPath($data["path"])) {
                 $data["linktype"] = "internal";
                 $data["internalType"] = "document";
                 $data["internal"] = $document->getId();
             } elseif ($asset = Asset::getByPath($data["path"])) {
                 $data["linktype"] = "internal";
                 $data["internalType"] = "asset";
                 $data["internal"] = $asset->getId();
             } else {
                 $data["linktype"] = "direct";
                 $data["direct"] = $data["path"];
             }
         } else {
             // clear content of link
             $data["linktype"] = "internal";
             $data["direct"] = "";
             $data["internalType"] = null;
             $data["internal"] = null;
         }
         unset($data["path"]);
         $link->setValues($data);
     }
     $this->addPropertiesToDocument($link);
 }
开发者ID:solverat,项目名称:pimcore,代码行数:30,代码来源:LinkController.php

示例3: getAssetTypesAction

 public function getAssetTypesAction()
 {
     $assetTypes = Asset::getTypes();
     $typeItems = [];
     foreach ($assetTypes as $assetType) {
         $typeItems[] = ["text" => $assetType];
     }
     $this->_helper->json($typeItems);
 }
开发者ID:pimcore,项目名称:pimcore,代码行数:9,代码来源:ClassController.php

示例4: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // get all thumbnails
     $dir = Asset\Image\Thumbnail\Config::getWorkingDir();
     $thumbnails = array();
     $files = scandir($dir);
     foreach ($files as $file) {
         if (strpos($file, ".xml")) {
             $thumbnails[] = str_replace(".xml", "", $file);
         }
     }
     $allowedThumbs = array();
     if ($input->getOption("thumbnails")) {
         $allowedThumbs = explode(",", $input->getOption("thumbnails"));
     }
     // get only images
     $conditions = array("type = 'image'");
     if ($input->getOption("parent")) {
         $parent = Asset::getById($input->getOption("parent"));
         if ($parent instanceof Asset\Folder) {
             $conditions[] = "path LIKE '" . $parent->getFullPath() . "/%'";
         } else {
             $this->writeError($input->getOption("parent") . " is not a valid asset folder ID!");
             exit;
         }
     }
     $list = new Asset\Listing();
     $list->setCondition(implode(" AND ", $conditions));
     $total = $list->getTotalCount();
     $perLoop = 10;
     for ($i = 0; $i < ceil($total / $perLoop); $i++) {
         $list->setLimit($perLoop);
         $list->setOffset($i * $perLoop);
         $images = $list->load();
         foreach ($images as $image) {
             foreach ($thumbnails as $thumbnail) {
                 if (empty($allowedThumbs) && !$input->getOption("system") || in_array($thumbnail, $allowedThumbs)) {
                     if ($input->getOption("force")) {
                         $image->clearThumbnail($thumbnail);
                     }
                     $this->output->writeln("generating thumbnail for image: " . $image->getFullpath() . " | " . $image->getId() . " | Thumbnail: " . $thumbnail . " : " . formatBytes(memory_get_usage()));
                     $this->output->writeln("generated thumbnail: " . $image->getThumbnail($thumbnail));
                 }
             }
             if ($input->getOption("system")) {
                 $thumbnail = Asset\Image\Thumbnail\Config::getPreviewConfig();
                 if ($input->getOption("force")) {
                     $image->clearThumbnail($thumbnail->getName());
                 }
                 $this->output->writeln("generating thumbnail for image: " . $image->getFullpath() . " | " . $image->getId() . " | Thumbnail: System Preview (tree) : " . formatBytes(memory_get_usage()));
                 $this->output->writeln("generated thumbnail: " . $image->getThumbnail($thumbnail));
             }
         }
         \Pimcore::collectGarbage();
     }
 }
开发者ID:siite,项目名称:choose-sa-cloud,代码行数:56,代码来源:ThumbnailsImageCommand.php

示例5: thumbnailAction

 public function thumbnailAction()
 {
     $a = Asset::getById(22);
     $a->clearThumbnails(true);
     $t = $a->getThumbnail("content");
     header("Content-Type: image/jpeg");
     while (@ob_end_flush()) {
     }
     flush();
     readfile($t->getFileSystemPath());
     exit;
 }
开发者ID:ChristophWurst,项目名称:pimcore,代码行数:12,代码来源:TestController.php

示例6: load

 /**
  * Get the assets from database
  *
  * @return array
  */
 public function load()
 {
     $assets = array();
     $assetsData = $this->db->fetchAll("SELECT id,type FROM assets" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
     foreach ($assetsData as $assetData) {
         if ($assetData["type"]) {
             if ($asset = Model\Asset::getById($assetData["id"])) {
                 $assets[] = $asset;
             }
         }
     }
     $this->model->setAssets($assets);
     return $assets;
 }
开发者ID:emanuel-london,项目名称:pimcore,代码行数:19,代码来源:Dao.php

示例7: load

 /**
  * Get the assets from database
  *
  * @return array
  */
 public function load()
 {
     $assets = [];
     $select = (string) $this->getQuery(['id', "type"]);
     $assetsData = $this->db->fetchAll($select, $this->model->getConditionVariables());
     foreach ($assetsData as $assetData) {
         if ($assetData["type"]) {
             if ($asset = Model\Asset::getById($assetData["id"])) {
                 $assets[] = $asset;
             }
         }
     }
     $this->model->setAssets($assets);
     return $assets;
 }
开发者ID:solverat,项目名称:pimcore,代码行数:20,代码来源:Dao.php

示例8: getById

 /**
  * @param $id
  * @throws \Exception
  */
 public function getById($id)
 {
     $data = $this->db->fetchRow("SELECT * FROM notes WHERE id = ?", $id);
     if (!$data["id"]) {
         throw new \Exception("Note item with id " . $id . " not found");
     }
     $this->assignVariablesToModel($data);
     // get key-value data
     $keyValues = $this->db->fetchAll("SELECT * FROM notes_data WHERE id = ?", $id);
     $preparedData = array();
     foreach ($keyValues as $keyValue) {
         $data = $keyValue["data"];
         $type = $keyValue["type"];
         $name = $keyValue["name"];
         if ($type == "document") {
             if ($data) {
                 $data = Document::getById($data);
             }
         } else {
             if ($type == "asset") {
                 if ($data) {
                     $data = Asset::getById($data);
                 }
             } else {
                 if ($type == "object") {
                     if ($data) {
                         $data = Object\AbstractObject::getById($data);
                     }
                 } else {
                     if ($type == "date") {
                         if ($data > 0) {
                             $data = new \Zend_Date($data);
                         }
                     } else {
                         if ($type == "bool") {
                             $data = (bool) $data;
                         }
                     }
                 }
             }
         }
         $preparedData[$name] = array("data" => $data, "type" => $type);
     }
     $this->model->setData($preparedData);
 }
开发者ID:ChristophWurst,项目名称:pimcore,代码行数:49,代码来源:Dao.php

示例9: move

 /**
  * Moves a file/directory
  *
  * @param string $sourcePath
  * @param string $destinationPath
  * @return void
  */
 public function move($sourcePath, $destinationPath)
 {
     $nameParts = explode("/", $sourcePath);
     $nameParts[count($nameParts) - 1] = File::getValidFilename($nameParts[count($nameParts) - 1]);
     $sourcePath = implode("/", $nameParts);
     $nameParts = explode("/", $destinationPath);
     $nameParts[count($nameParts) - 1] = File::getValidFilename($nameParts[count($nameParts) - 1]);
     $destinationPath = implode("/", $nameParts);
     try {
         if (dirname($sourcePath) == dirname($destinationPath)) {
             $asset = null;
             if ($asset = Asset::getByPath("/" . $destinationPath)) {
                 // If we got here, this means the destination exists, and needs to be overwritten
                 $sourceAsset = Asset::getByPath("/" . $sourcePath);
                 $asset->setData($sourceAsset->getData());
                 $sourceAsset->delete();
             }
             // see: Asset\WebDAV\File::delete() why this is necessary
             $log = Asset\WebDAV\Service::getDeleteLog();
             if (!$asset && array_key_exists("/" . $destinationPath, $log)) {
                 $asset = \Pimcore\Tool\Serialize::unserialize($log["/" . $destinationPath]["data"]);
                 if ($asset) {
                     $sourceAsset = Asset::getByPath("/" . $sourcePath);
                     $asset->setData($sourceAsset->getData());
                     $sourceAsset->delete();
                 }
             }
             if (!$asset) {
                 $asset = Asset::getByPath("/" . $sourcePath);
             }
             $asset->setFilename(basename($destinationPath));
         } else {
             $asset = Asset::getByPath("/" . $sourcePath);
             $parent = Asset::getByPath("/" . dirname($destinationPath));
             $asset->setPath($parent->getFullPath() . "/");
             $asset->setParentId($parent->getId());
         }
         $user = \Pimcore\Tool\Admin::getCurrentUser();
         $asset->setUserModification($user->getId());
         $asset->save();
     } catch (\Exception $e) {
         \Logger::error($e);
     }
 }
开发者ID:cannonerd,项目名称:pimcore,代码行数:51,代码来源:Tree.php

示例10: update

 /**
  * @return void
  */
 protected function update()
 {
     // only do this if the file exists and contains data
     if ($this->getDataChanged() || !$this->getCustomSetting("imageDimensionsCalculated")) {
         try {
             // save the current data into a tmp file to calculate the dimensions, otherwise updates wouldn't be updated
             // because the file is written in parent::update();
             $tmpFile = $this->getTemporaryFile();
             $dimensions = $this->getDimensions($tmpFile, true);
             unlink($tmpFile);
             if ($dimensions && $dimensions["width"]) {
                 $this->setCustomSetting("imageWidth", $dimensions["width"]);
                 $this->setCustomSetting("imageHeight", $dimensions["height"]);
             }
         } catch (\Exception $e) {
             Logger::error("Problem getting the dimensions of the image with ID " . $this->getId());
         }
         // this is to be downward compatible so that the controller can check if the dimensions are already calculated
         // and also to just do the calculation once, because the calculation can fail, an then the controller tries to
         // calculate the dimensions on every request an also will create a version, ...
         $this->setCustomSetting("imageDimensionsCalculated", true);
     }
     parent::update();
     $this->clearThumbnails();
     // now directly create "system" thumbnails (eg. for the tree, ...)
     if ($this->getDataChanged()) {
         try {
             $path = $this->getThumbnail(Image\Thumbnail\Config::getPreviewConfig())->getFileSystemPath();
             // set the modification time of the thumbnail to the same time from the asset
             // so that the thumbnail check doesn't fail in Asset\Image\Thumbnail\Processor::process();
             // we need the @ in front of touch because of some stream wrapper (eg. s3) which don't support touch()
             @touch($path, $this->getModificationDate());
         } catch (\Exception $e) {
             Logger::error("Problem while creating system-thumbnails for image " . $this->getRealFullPath());
             Logger::error($e);
         }
     }
 }
开发者ID:pimcore,项目名称:pimcore,代码行数:41,代码来源:Image.php

示例11: rewriteIds

 /**
  * @param $object
  * @param $idMapping
  * @param array $params
  * @return mixed
  */
 public function rewriteIds($object, $idMapping, $params = array())
 {
     $data = $this->getDataFromObjectParam($object, $params);
     if ($data && $data->getData() instanceof Asset) {
         if (array_key_exists("asset", $idMapping) and array_key_exists($data->getData()->getId(), $idMapping["asset"])) {
             $data->setData(Asset::getById($idMapping["asset"][$data->getData()->getId()]));
         }
     }
     if ($data && $data->getPoster() instanceof Asset) {
         if (array_key_exists("asset", $idMapping) and array_key_exists($data->getPoster()->getId(), $idMapping["asset"])) {
             $data->setPoster(Asset::getById($idMapping["asset"][$data->getPoster()->getId()]));
         }
     }
     return $data;
 }
开发者ID:emanuel-london,项目名称:pimcore,代码行数:21,代码来源:Video.php

示例12: typePathAction

 public function typePathAction()
 {
     $id = $this->getParam("id");
     $type = $this->getParam("type");
     $data = [];
     if ($type == "asset") {
         $element = Asset::getById($id);
     } elseif ($type == "document") {
         $element = Document::getById($id);
         $data["index"] = $element->getIndex();
     } else {
         $element = Object::getById($id);
     }
     $typePath = Element\Service::getTypePath($element);
     $data["success"] = true;
     $data["idPath"] = Element\Service::getIdPath($element);
     $data["typePath"] = $typePath;
     $data["fullpath"] = $element->getRealFullPath();
     $this->_helper->json($data);
 }
开发者ID:pimcore,项目名称:pimcore,代码行数:20,代码来源:ElementController.php

示例13: getImageThumbnail

 /**
  * @param $config
  * @return string
  */
 public function getImageThumbnail($config)
 {
     if ($this->poster && ($poster = Asset::getById($this->poster))) {
         return $poster->getThumbnail($config);
     }
     if ($this->getVideoAsset()) {
         return $this->getVideoAsset()->getImageThumbnail($config);
     }
     return "";
 }
开发者ID:pawansgi92,项目名称:pimcore2,代码行数:14,代码来源:Video.php

示例14: getFromCsvImport

 /**
  * @param $importValue
  * @return mixed|null|Asset|Document|Element\ElementInterface
  */
 public function getFromCsvImport($importValue)
 {
     $value = null;
     $values = explode(":", $importValue);
     if (count($values) == 2) {
         $type = $values[0];
         $path = $values[1];
         $value = Element\Service::getElementByPath($type, $path);
     } else {
         //fallback for old export files
         if ($el = Asset::getByPath($importValue)) {
             $value = $el;
         } else {
             if ($el = Document::getByPath($importValue)) {
                 $value = $el;
             } else {
                 if ($el = Object::getByPath($importValue)) {
                     $value = $el;
                 }
             }
         }
     }
     return $value;
 }
开发者ID:sfie,项目名称:pimcore,代码行数:28,代码来源:Href.php

示例15: generate

 /**
  *
  */
 public function generate()
 {
     $errorImage = PIMCORE_PATH . '/static6/img/filetype-not-supported.png';
     $deferred = false;
     $generated = false;
     if (!$this->asset) {
         $this->filesystemPath = $errorImage;
     } elseif (!$this->filesystemPath) {
         $cs = $this->asset->getCustomSetting("image_thumbnail_time");
         $im = $this->asset->getCustomSetting("image_thumbnail_asset");
         if ($im || $this->imageAsset) {
             if ($this->imageAsset) {
                 $im = $this->imageAsset;
             } else {
                 $im = Model\Asset::getById($im);
             }
             if ($im instanceof Image) {
                 $imageThumbnail = $im->getThumbnail($this->getConfig());
                 $this->filesystemPath = $imageThumbnail->getFileSystemPath();
             }
         }
         if (!$this->filesystemPath) {
             $timeOffset = $this->timeOffset;
             if (!$this->timeOffset && $cs) {
                 $timeOffset = $cs;
             }
             // fallback
             if (!$timeOffset) {
                 $timeOffset = ceil($this->asset->getDuration() / 3);
             }
             $converter = \Pimcore\Video::getInstance();
             $converter->load($this->asset->getFileSystemPath());
             $path = PIMCORE_TEMPORARY_DIRECTORY . "/video-image-cache/video_" . $this->asset->getId() . "__thumbnail_" . $timeOffset . ".png";
             if (!is_dir(dirname($path))) {
                 File::mkdir(dirname($path));
             }
             if (!is_file($path)) {
                 $lockKey = "video_image_thumbnail_" . $this->asset->getId() . "_" . $timeOffset;
                 Model\Tool\Lock::acquire($lockKey);
                 // after we got the lock, check again if the image exists in the meantime - if not - generate it
                 if (!is_file($path)) {
                     $converter->saveImage($path, $timeOffset);
                     $generated = true;
                 }
                 Model\Tool\Lock::release($lockKey);
             }
             if ($this->getConfig()) {
                 $this->getConfig()->setFilenameSuffix("time-" . $timeOffset);
                 try {
                     $path = Image\Thumbnail\Processor::process($this->asset, $this->getConfig(), $path, $deferred, true, $generated);
                 } catch (\Exception $e) {
                     Logger::error("Couldn't create image-thumbnail of video " . $this->asset->getRealFullPath());
                     Logger::error($e);
                     $path = $errorImage;
                 }
             }
             $this->filesystemPath = $path;
         }
         \Pimcore::getEventManager()->trigger("asset.video.image-thumbnail", $this, ["deferred" => $deferred, "generated" => $generated]);
     }
 }
开发者ID:pimcore,项目名称:pimcore,代码行数:64,代码来源:ImageThumbnail.php


注:本文中的Pimcore\Model\Asset类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。