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