本文整理汇总了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));
//.........这里部分代码省略.........
示例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]);
}