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


PHP Asset::getById方法代码示例

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


在下文中一共展示了Asset::getById方法的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: preDispatch

 public function preDispatch()
 {
     parent::preDispatch();
     if ($this->getParam('ctype') === 'document') {
         $this->element = Document::getById((int) $this->getParam('cid', 0));
     } elseif ($this->getParam('ctype') === 'asset') {
         $this->element = Asset::getById((int) $this->getParam('cid', 0));
     } elseif ($this->getParam('ctype') === 'object') {
         $this->element = ConcreteObject::getById((int) $this->getParam('cid', 0));
     }
     if (!$this->element) {
         throw new \Exception('Cannot load element' . $this->getParam('cid') . ' of type \'' . $this->getParam('ctype') . '\'');
     }
     //get the latest available version of the element -
     //$this->element = $this->getLatestVersion($this->element);
     $this->element->setUserModification($this->getUser()->getId());
 }
开发者ID:solverat,项目名称:pimcore,代码行数:17,代码来源:WorkflowController.php

示例7: 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

示例8: updatePathFromInternal

 protected function updatePathFromInternal()
 {
     if ($this->data['internal']) {
         if ($this->data['internalType'] == 'document') {
             if ($doc = Document::getById($this->data['internalId'])) {
                 if (!Document::doHideUnpublished() || $doc->isPublished()) {
                     $path = $doc->getFullPath();
                     $this->data['path'] = \Toolbox\Tools\GlobalLink::parse($path);
                 }
             }
         } else {
             if ($this->data['internalType'] == 'asset') {
                 if ($asset = Asset::getById($this->data['internalId'])) {
                     $this->data['path'] = $asset->getFullPath();
                 }
             }
         }
     }
 }
开发者ID:dachcom-digital,项目名称:pimcore-toolbox,代码行数:19,代码来源:Globallink.php

示例9: assetAction

 /** end point for asset related data.
  * - get asset by id
  *      GET http://[YOUR-DOMAIN]/webservice/rest/asset/id/1281?apikey=[API-KEY]
  *      returns json-encoded asset data.
  * - delete asset by id
  *      DELETE http://[YOUR-DOMAIN]/webservice/rest/asset/id/1281?apikey=[API-KEY]
  *      returns json encoded success value
  * - create asset
  *      PUT or POST http://[YOUR-DOMAIN]/webservice/rest/asset?apikey=[API-KEY]
  *      body: json-encoded asset data in the same format as returned by get asset by id
  *              but with missing id field or id set to 0
  *      returns json encoded asset id
  * - update asset
  *      PUT or POST http://[YOUR-DOMAIN]/webservice/rest/asset?apikey=[API-KEY]
  *      body: same as for create asset but with asset id
  *      returns json encoded success value
  * @throws \Exception
  */
 public function assetAction()
 {
     $id = $this->getParam("id");
     $success = false;
     try {
         if ($this->isGet()) {
             $asset = Asset::getById($id);
             if (!$asset) {
                 $this->encoder->encode(array("success" => false, "msg" => "Asset does not exist", "code" => self::ELEMENT_DOES_NOT_EXIST));
                 return;
             }
             $this->checkPermission($asset, "get");
             if ($asset instanceof Asset\Folder) {
                 $object = $this->service->getAssetFolderById($id);
             } else {
                 $light = $this->getParam("light");
                 $options = array("LIGHT" => $light ? 1 : 0);
                 $object = $this->service->getAssetFileById($id, $options);
                 $algo = "sha1";
                 $thumbnailConfig = $this->getParam("thumbnail");
                 if ($thumbnailConfig && $asset->getType() == "image") {
                     $checksum = $asset->getThumbnail($thumbnailConfig)->getChecksum($algo);
                     $object->thumbnail = (string) $asset->getThumbnail($thumbnailConfig);
                 } else {
                     $checksum = $asset->getChecksum($algo);
                 }
                 $object->checksum = array("algo" => $algo, "value" => $checksum);
                 if ($light) {
                     unset($object->data);
                 }
             }
             $this->encoder->encode(array("success" => true, "data" => $object));
             return;
         } else {
             if ($this->isDelete()) {
                 $asset = Asset::getById($id);
                 if ($asset) {
                     $this->checkPermission($asset, "delete");
                 }
                 $success = $this->service->deleteAsset($id);
                 $this->encoder->encode(array("success" => $success));
                 return;
             } else {
                 if ($this->isPost() || $this->isPut()) {
                     $data = file_get_contents("php://input");
                     $data = \Zend_Json::decode($data);
                     $type = $data["type"];
                     $id = null;
                     if ($data["id"]) {
                         $asset = Asset::getById($data["id"]);
                         if ($asset) {
                             $this->checkPermission($asset, "update");
                         }
                         $isUpdate = true;
                         if ($type == "folder") {
                             $wsData = self::fillWebserviceData("\\Pimcore\\Model\\Webservice\\Data\\Asset\\Folder\\In", $data);
                             $success = $this->service->updateAssetFolder($wsData);
                         } else {
                             $wsData = self::fillWebserviceData("\\Pimcore\\Model\\Webservice\\Data\\Asset\\File\\In", $data);
                             $success = $this->service->updateAssetFile($wsData);
                         }
                     } else {
                         if ($type == "folder") {
                             $class = "\\Pimcore\\Model\\Webservice\\Data\\Asset\\Folder\\In";
                             $method = "createAssetFolder";
                         } else {
                             $class = "\\Pimcore\\Model\\Webservice\\Data\\Asset\\File\\In";
                             $method = "createAssetFile";
                         }
                         $wsData = self::fillWebserviceData($class, $data);
                         $asset = new Asset();
                         $asset->setId($wsData->parentId);
                         $this->checkPermission($asset, "create");
                         $id = $this->service->{$method}($wsData);
                     }
                     if (!$isUpdate) {
                         $success = $id != null;
                     }
                     if ($success && !$isUpdate) {
                         $this->encoder->encode(array("success" => $success, "data" => array("id" => $id)));
                     } else {
                         $this->encoder->encode(array("success" => $success));
//.........这里部分代码省略.........
开发者ID:yonetici,项目名称:pimcore-coreshop-demo,代码行数:101,代码来源:RestController.php

示例10: 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

示例11: 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

示例12: getAssetTypePath

 public static function getAssetTypePath($element)
 {
     $path = "";
     if ($element) {
         $parentId = $element->getParentId();
         if ($parentId) {
             $ne = Asset::getById($element->getParentId());
         }
     }
     if ($ne) {
         $path = self::getAssetTypePath($ne, $path);
     }
     if ($element) {
         $path = $path . "/" . $element->getType();
     }
     return $path;
 }
开发者ID:sebwebdev,项目名称:pimcore,代码行数:17,代码来源:ElementController.php

示例13: getFromWebserviceImport

 /**
  * @param Document\Webservice\Data\Document\Element $wsElement
  * @param null $idMapper
  * @throws \Exception
  */
 public function getFromWebserviceImport($wsElement, $idMapper = null)
 {
     $data = $wsElement->value;
     if ($data->id !== null) {
         $this->type = $data->type;
         $this->subtype = $data->subtype;
         if (is_numeric($this->id)) {
             if ($idMapper) {
                 $id = $idMapper->getMappedId($this->type, $this->id);
             }
             if ($this->type == "asset") {
                 $this->o = Asset::getById($id);
                 if (!$this->o instanceof Asset) {
                     if ($idMapper && $idMapper->ignoreMappingFailures()) {
                         $idMapper->recordMappingFailure($this->getDocumentId(), $this->type, $this->id);
                     } else {
                         throw new \Exception("cannot get values from web service import - referenced asset with id [ " . $this->id . " ] is unknown");
                     }
                 }
             } else {
                 if ($this->type == "document") {
                     $this->o = Document::getById($id);
                     if (!$this->o instanceof Document) {
                         if ($idMapper && $idMapper->ignoreMappingFailures()) {
                             $idMapper->recordMappingFailure($this->getDocumentId(), $this->type, $this->id);
                         } else {
                             throw new \Exception("cannot get values from web service import - referenced document with id [ " . $this->id . " ] is unknown");
                         }
                     }
                 } else {
                     if ($this->type == "object") {
                         $this->o = Object::getById($id);
                         if (!$this->o instanceof Object\AbstractObject) {
                             if ($idMapper && $idMapper->ignoreMappingFailures()) {
                                 $idMapper->recordMappingFailure($this->getDocumentId(), $this->type, $this->id);
                             } else {
                                 throw new \Exception("cannot get values from web service import - referenced object with id [ " . $this->id . " ] is unknown");
                             }
                         }
                     } else {
                         p_r($this);
                         throw new \Exception("cannot get values from web service import - type is not valid");
                     }
                 }
             }
         } else {
             throw new \Exception("cannot get values from web service import - id is not valid");
         }
     }
 }
开发者ID:sfie,项目名称:pimcore,代码行数:55,代码来源:Renderlet.php

示例14: getCacheTags

 /**
  * This is a dummy and is mostly implemented by relation types
  *
  * @param mixed $data
  * @param array $tags
  * @return array
  */
 public function getCacheTags($data, $tags = array())
 {
     $tags = is_array($tags) ? $tags : array();
     if ($data instanceof Object\Data\Link and $data->getInternal()) {
         if (intval($data->getInternal()) > 0) {
             if ($data->getInternalType() == "document") {
                 if ($doc = Document::getById($data->getInternal())) {
                     if (!array_key_exists($doc->getCacheTag(), $tags)) {
                         $tags = $doc->getCacheTags($tags);
                     }
                 }
             } elseif ($data->getInternalType() == "asset") {
                 if ($asset = Asset::getById($data->getInternal())) {
                     if (!array_key_exists($asset->getCacheTag(), $tags)) {
                         $tags = $asset->getCacheTags($tags);
                     }
                 }
             }
         }
     }
     return $tags;
 }
开发者ID:emanuel-london,项目名称:pimcore,代码行数:29,代码来源:Link.php

示例15: array

$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 ($opts->getOption("thumbnails")) {
    $allowedThumbs = explode(",", $opts->getOption("thumbnails"));
}
// get only images
$conditions = array("type = 'image'");
if ($opts->getOption("parent")) {
    $parent = Asset::getById($opts->getOption("parent"));
    if ($parent instanceof Asset\Folder) {
        $conditions[] = "path LIKE '" . $parent->getFullPath() . "/%'";
    } else {
        echo $opts->getOption("parent") . " is not a valid asset folder ID!\n";
        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();
开发者ID:sfie,项目名称:pimcore,代码行数:31,代码来源:image-thumbnails.php


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