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


PHP Asset::setId方法代码示例

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


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

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

示例2: assetAction


//.........这里部分代码省略.........
                 $this->encoder->encode(["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 = ["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 = ["algo" => $algo, "value" => $checksum];
                 if ($light) {
                     unset($object->data);
                 }
             }
             $this->encoder->encode(["success" => true, "data" => $object]);
             return;
         } elseif ($this->isDelete()) {
             /**
              * @api {delete} /asset Delete asset
              * @apiName deleteAsset
              * @apiGroup Asset
              * @apiParam {int} id The id of asset you delete
              * @apiSampleRequest off
              * @apiParamExample {json} Request-Example:
              *     {
              *       "id": 4711
              *       "apikey": '2132sdf2321rwefdcvvce22'
              *     }
              * @apiParam {string} apikey your access token
              * @apiSuccess {boolean} success Returns true if finished successfully
              * @apiSuccessExample {json} Succes-Response:
              *                    {"success":true}
              * @apiError {boolean} success Returns false if failed
              * @apiErrorExample {json} Error-Response:
              *                  {"success":false,"msg":"exception 'Exception' with message 'Asset with given ID (712131243) does not exist.'"}
              */
             $asset = Asset::getById($id);
             if ($asset) {
                 $this->checkPermission($asset, "delete");
             }
             $success = $this->service->deleteAsset($id);
             $this->encoder->encode(["success" => $success]);
             return;
         } elseif ($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(["success" => $success, "data" => ["id" => $id]]);
             } else {
                 $this->encoder->encode(["success" => $success]);
             }
             return;
         }
     } catch (\Exception $e) {
         Logger::error($e);
         $this->encoder->encode(["success" => false, "msg" => (string) $e]);
     }
     $this->encoder->encode(["success" => false]);
 }
开发者ID:pimcore,项目名称:pimcore,代码行数:101,代码来源:RestController.php


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