本文整理汇总了PHP中Pimcore\Model\Document\Service类的典型用法代码示例。如果您正苦于以下问题:PHP Service类的具体用法?PHP Service怎么用?PHP Service使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Service类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: importDocuments
public function importDocuments()
{
$file = sprintf('%s/documents.json', $this->baseDir);
$docs = new \Zend_Config_Json($file);
foreach ($docs as $def) {
$def = $def->toArray();
$parent = Document::getByPath($def['parent']);
unset($def['parent']);
if (!$parent) {
$parent = Document::getById(1);
}
$path = $parent->getFullPath() . '/' . $def['key'];
if (Document\Service::pathExists($path)) {
$doc = Document::getByPath($path);
} else {
$docClass = '\\Pimcore\\Model\\Document\\' . ucfirst($def['type']);
/** @var Document $doc */
$doc = $docClass::create($parent->getId(), $def, false);
$doc->setUserOwner(self::getUser()->getId());
$doc->setUserModification(self::getUser()->getId());
}
$doc->setValues($def);
$doc->setPublished(true);
$doc->save();
}
}
示例2: copyAction
public function copyAction()
{
$success = false;
$sourceId = intval($this->getParam("sourceId"));
$source = Document::getById($sourceId);
$session = Session::get("pimcore_copy");
$targetId = intval($this->getParam("targetId"));
if ($this->getParam("targetParentId")) {
$sourceParent = Document::getById($this->getParam("sourceParentId"));
// this is because the key can get the prefix "_copy" if the target does already exists
if ($session->{$this->getParam("transactionId")}["parentId"]) {
$targetParent = Document::getById($session->{$this->getParam("transactionId")}["parentId"]);
} else {
$targetParent = Document::getById($this->getParam("targetParentId"));
}
$targetPath = preg_replace("@^" . $sourceParent->getFullPath() . "@", $targetParent . "/", $source->getPath());
$target = Document::getByPath($targetPath);
} else {
$target = Document::getById($targetId);
}
if ($target instanceof Document) {
if ($target->isAllowed("create")) {
if ($source != null) {
if ($this->getParam("type") == "child") {
$enableInheritance = $this->getParam("enableInheritance") == "true" ? true : false;
$resetIndex = $this->getParam("resetIndex") == "true" ? true : false;
$newDocument = $this->_documentService->copyAsChild($target, $source, $enableInheritance, $resetIndex);
$session->{$this->getParam("transactionId")}["idMapping"][(int) $source->getId()] = (int) $newDocument->getId();
// this is because the key can get the prefix "_copy" if the target does already exists
if ($this->getParam("saveParentId")) {
$session->{$this->getParam("transactionId")}["parentId"] = $newDocument->getId();
}
Session::writeClose();
} else {
if ($this->getParam("type") == "replace") {
$this->_documentService->copyContents($target, $source);
}
}
$success = true;
} else {
\Logger::error("prevended copy/paste because document with same path+key already exists in this location");
}
} else {
\Logger::error("could not execute copy/paste because of missing permissions on target [ " . $targetId . " ]");
$this->_helper->json(array("success" => false, "message" => "missing_permission"));
}
}
$this->_helper->json(array("success" => $success));
}
示例3: postDispatch
//.........这里部分代码省略.........
}
}
}
//manipulate path for frontend
if (is_array($pluginCssPaths) and count($pluginCssPaths) > 0) {
for ($i = 0; $i < count($pluginCssPaths); $i++) {
if (is_file(PIMCORE_PLUGINS_PATH . $pluginCssPaths[$i])) {
$cssPaths[] = "/plugins" . $pluginCssPaths[$i];
}
}
}
}
}
$editmodeScripts = array_merge($editmodeScripts, $jsPaths);
$editmodeStylesheets = array_merge($editmodeStylesheets, $cssPaths);
} catch (\Exception $e) {
\Logger::alert("there is a problem with the plugin configuration");
\Logger::alert($e);
}
$editmodeHeadHtml = "\n\n\n<!-- pimcore editmode -->\n";
// include stylesheets
foreach ($editmodeStylesheets as $sheet) {
$editmodeHeadHtml .= '<link rel="stylesheet" type="text/css" href="' . $sheet . '?_dc=' . Version::$revision . '" />';
$editmodeHeadHtml .= "\n";
}
$editmodeHeadHtml .= "\n\n";
$editmodeHeadHtml .= '<script type="text/javascript">var jQueryPreviouslyLoaded = (typeof jQuery == "undefined") ? false : true;</script>' . "\n";
// include script libraries
foreach ($editmodeLibraries as $script) {
$editmodeHeadHtml .= '<script type="text/javascript" src="' . $script . '?_dc=' . Version::$revision . '"></script>';
$editmodeHeadHtml .= "\n";
}
// combine the pimcore scripts in non-devmode
if ($conf->general->devmode) {
foreach ($editmodeScripts as $script) {
$editmodeHeadHtml .= '<script type="text/javascript" src="' . $script . '?_dc=' . Version::$revision . '"></script>';
$editmodeHeadHtml .= "\n";
}
} else {
$scriptContents = "";
foreach ($editmodeScripts as $scriptUrl) {
$scriptContents .= file_get_contents(PIMCORE_DOCUMENT_ROOT . $scriptUrl) . "\n\n\n";
}
$editmodeHeadHtml .= '<script type="text/javascript" src="' . \Pimcore\Tool\Admin::getMinimizedScriptPath($scriptContents) . '?_dc=' . Version::$revision . '"></script>' . "\n";
}
$user = \Pimcore\Tool\Authentication::authenticateSession();
$lang = $user->getLanguage();
$editmodeHeadHtml .= '<script type="text/javascript" src="/admin/misc/json-translations-system/language/' . $lang . '/?_dc=' . Version::$revision . '"></script>' . "\n";
$editmodeHeadHtml .= '<script type="text/javascript" src="/admin/misc/json-translations-admin/language/' . $lang . '/?_dc=' . Version::$revision . '"></script>' . "\n";
$editmodeHeadHtml .= "\n\n";
// set var for editable configurations which is filled by Document\Tag::admin()
$editmodeHeadHtml .= '<script type="text/javascript">
var editableConfigurations = new Array();
var pimcore_document_id = ' . $request->getParam("document")->getId() . ';
if(jQueryPreviouslyLoaded) {
jQuery.noConflict( true );
}
</script>';
$editmodeHeadHtml .= "\n\n<!-- /pimcore editmode -->\n\n\n";
// add scripts in html header for pages in editmode
if ($this->controller->editmode && Document\Service::isValidType($this->controller->document->getType())) {
//ckogler
include_once "simple_html_dom.php";
$body = $this->getResponse()->getBody();
$html = str_get_html($body);
if ($html) {
$htmlElement = $html->find("html", 0);
$head = $html->find("head", 0);
$bodyElement = $html->find("body", 0);
// if there's no head and no body, create a wrapper including these elements
// add html headers for snippets in editmode, so there is no problem with javascript
if (!$head && !$bodyElement && !$htmlElement) {
$body = "<!DOCTYPE html>\n<html>\n<head></head><body>" . $body . "</body></html>";
$html = str_get_html($body);
// get them again with the updated html markup
$htmlElement = $html->find("html", 0);
$head = $html->find("head", 0);
$bodyElement = $html->find("body", 0);
}
if ($head && $bodyElement && $htmlElement) {
$head->innertext = $head->innertext . "\n\n" . $editmodeHeadHtml;
$bodyElement->onunload = "pimcoreOnUnload();";
if (\Pimcore\Tool\Admin::isExtJS6()) {
$bodyElement->innertext = $bodyElement->innertext . "\n\n" . '<script type="text/javascript" src="/pimcore/static6/js/pimcore/document/edit/startup.js?_dc=' . Version::$revision . '"></script>' . "\n\n";
} else {
$bodyElement->innertext = $bodyElement->innertext . "\n\n" . '<script type="text/javascript" src="/pimcore/static/js/pimcore/document/edit/startup.js?_dc=' . Version::$revision . '"></script>' . "\n\n";
}
$body = $html->save();
$this->getResponse()->setBody($body);
} else {
$this->getResponse()->setBody('<div style="font-size:30px; font-family: Arial; font-weight:bold; color:red; text-align: center; margin: 40px 0">You have to define a <html>, <head>, <body><br />HTML-tag in your view/layout markup!</div>');
}
$html->clear();
unset($html);
}
}
// IE compatibility
//$this->getResponse()->setHeader("X-UA-Compatible", "IE=8; IE=9", true);
}
示例4: documentAction
/** end point for document related data.
* - get document by id
* GET http://[YOUR-DOMAIN]/webservice/rest/document/id/1281?apikey=[API-KEY]
* returns json-encoded document data.
* - delete document by id
* DELETE http://[YOUR-DOMAIN]/webservice/rest/document/id/1281?apikey=[API-KEY]
* returns json encoded success value
* - create document
* PUT or POST http://[YOUR-DOMAIN]/webservice/rest/document?apikey=[API-KEY]
* body: json-encoded document data in the same format as returned by get document by id
* but with missing id field or id set to 0
* returns json encoded document id
* - update document
* PUT or POST http://[YOUR-DOMAIN]/webservice/rest/document?apikey=[API-KEY]
* body: same as for create document but with object id
* returns json encoded success value
* @throws \Exception
*/
public function documentAction()
{
$id = $this->getParam("id");
$success = false;
try {
if ($this->isGet()) {
$doc = Document::getById($id);
if (!$doc) {
$this->encoder->encode(array("success" => false, "msg" => "Document does not exist", "code" => self::ELEMENT_DOES_NOT_EXIST));
return;
}
$this->checkPermission($doc, "get");
if ($doc) {
$type = $doc->getType();
$getter = "getDocument" . ucfirst($type) . "ById";
if (method_exists($this->service, $getter)) {
$object = $this->service->{$getter}($id);
} else {
// check if the getter is implemented by a plugin
$class = "\\Pimcore\\Model\\Webservice\\Data\\Document\\" . ucfirst($type) . "\\Out";
if (Tool::classExists($class)) {
Document\Service::loadAllDocumentFields($doc);
$object = Webservice\Data\Mapper::map($doc, $class, "out");
} else {
throw new \Exception("unknown type");
}
}
}
if (!$object) {
throw new \Exception("could not find document");
}
@$this->encoder->encode(array("success" => true, "data" => $object));
return;
} else {
if ($this->isDelete()) {
$doc = Document::getById($id);
if ($doc) {
$this->checkPermission($doc, "delete");
}
$success = $this->service->deleteDocument($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;
$typeUpper = ucfirst($type);
$className = "\\Pimcore\\Model\\Webservice\\Data\\Document\\" . $typeUpper . "\\In";
if ($data["id"]) {
$doc = Document::getById($data["id"]);
if ($doc) {
$this->checkPermission($doc, "update");
}
$isUpdate = true;
$setter = "updateDocument" . $typeUpper;
if (!method_exists($this->service, $setter)) {
throw new \Exception("method does not exist " . $setter);
}
$wsData = self::fillWebserviceData($className, $data);
$success = $this->service->{$setter}($wsData);
} else {
$setter = "createDocument" . $typeUpper;
if (!method_exists($this->service, $setter)) {
throw new \Exception("method does not exist " . $setter);
}
$wsData = self::fillWebserviceData($className, $data);
$doc = new Document();
$doc->setId($wsData->parentId);
$this->checkPermission($doc, "create");
$id = $this->service->{$setter}($wsData);
}
if (!$isUpdate) {
$success = $id != null;
}
if ($success && !$isUpdate) {
$this->encoder->encode(array("success" => $success, "id" => $id));
} else {
$this->encoder->encode(array("success" => $success));
}
return;
//.........这里部分代码省略.........
示例5: replaceAssignmentsAction
public function replaceAssignmentsAction()
{
$success = false;
$message = "";
$element = Element\Service::getElementById($this->getParam("type"), $this->getParam("id"));
$sourceEl = Element\Service::getElementById($this->getParam("sourceType"), $this->getParam("sourceId"));
$targetEl = Element\Service::getElementById($this->getParam("targetType"), $this->getParam("targetId"));
if ($element && $sourceEl && $targetEl && $this->getParam("sourceType") == $this->getParam("targetType") && $sourceEl->getType() == $targetEl->getType()) {
$rewriteConfig = [$this->getParam("sourceType") => [$sourceEl->getId() => $targetEl->getId()]];
if ($element instanceof Document) {
$element = Document\Service::rewriteIds($element, $rewriteConfig);
} elseif ($element instanceof Object\AbstractObject) {
$element = Object\Service::rewriteIds($element, $rewriteConfig);
} elseif ($element instanceof Asset) {
$element = Asset\Service::rewriteIds($element, $rewriteConfig);
}
$element->setUserModification($this->getUser()->getId());
$element->save();
$success = true;
} else {
$message = "source-type and target-type do not match";
}
$this->_helper->json(["success" => $success, "message" => $message]);
}
示例6: getFullPath
/**
* Returns the full path of the document including the key (path+key)
*
* @return string
*/
public function getFullPath()
{
// check if this document is also the site root, if so return /
try {
if (Site::isSiteRequest()) {
$site = Site::getCurrentSite();
if ($site instanceof Site) {
if ($site->getRootDocument()->getId() == $this->getId()) {
return "/";
}
}
}
} catch (\Exception $e) {
\Logger::error($e);
}
// @TODO please forgive me, this is the dirtiest hack I've ever made :(
// if you got confused by this functionality drop me a line and I'll buy you some beers :)
// this is for the case that a link points to a document outside of the current site
// in this case we look for a hardlink in the current site which points to the current document
// why this could happen: we have 2 sites, in one site there's a hardlink to the other site and on a page inside
// the hardlink there are snippets embedded and this snippets have links pointing to a document which is also
// inside the hardlink scope, but this is an ID link, so we cannot rewrite the link the usual way because in the
// snippet / link we don't know anymore that whe a inside a hardlink wrapped document
if (!\Pimcore::inAdmin() && Site::isSiteRequest() && !FrontendTool::isDocumentInCurrentSite($this)) {
$documentService = new Document\Service();
$parent = $this;
while ($parent) {
if ($hardlinkId = $documentService->getDocumentIdFromHardlinkInSameSite(Site::getCurrentSite(), $parent)) {
$hardlink = Document::getById($hardlinkId);
if (FrontendTool::isDocumentInCurrentSite($hardlink)) {
$siteRootPath = Site::getCurrentSite()->getRootPath();
$siteRootPath = preg_quote($siteRootPath);
$hardlinkPath = preg_replace("@^" . $siteRootPath . "@", "", $hardlink->getRealFullPath());
return preg_replace("@^" . preg_quote($parent->getRealFullPath()) . "@", $hardlinkPath, $this->getRealFullPath());
break;
}
}
$parent = $parent->getParent();
}
$config = \Pimcore\Config::getSystemConfig();
$front = \Zend_Controller_Front::getInstance();
$scheme = ($front->getRequest()->isSecure() ? "https" : "http") . "://";
if ($site = FrontendTool::getSiteForDocument($this)) {
if ($site->getMainDomain()) {
// check if current document is the root of the different site, if so, preg_replace below doesn't work, so just return /
if ($site->getRootDocument()->getId() == $this->getId()) {
return $scheme . $site->getMainDomain() . "/";
}
return $scheme . $site->getMainDomain() . preg_replace("@^" . $site->getRootPath() . "/@", "/", $this->getRealFullPath());
}
}
if ($config->general->domain) {
return $scheme . $config->general->domain . $this->getRealFullPath();
}
}
$path = $this->getPath() . $this->getKey();
return $path;
}
示例7: findAction
/**
* @return void
*/
public function findAction()
{
$user = $this->getUser();
$query = $this->getParam("query");
if ($query == "*") {
$query = "";
}
$query = str_replace("%", "*", $query);
$types = explode(",", $this->getParam("type"));
$subtypes = explode(",", $this->getParam("subtype"));
$classnames = explode(",", $this->getParam("class"));
if ($this->getParam("type") == "object" && is_array($classnames) && empty($classnames[0])) {
$subtypes = array("object", "variant", "folder");
}
$offset = intval($this->getParam("start"));
$limit = intval($this->getParam("limit"));
$offset = $offset ? $offset : 0;
$limit = $limit ? $limit : 50;
$searcherList = new Data\Listing();
$conditionParts = array();
$db = \Pimcore\Db::get();
//exclude forbidden assets
if (in_array("asset", $types)) {
if (!$user->isAllowed("assets")) {
$forbiddenConditions[] = " `type` != 'asset' ";
} else {
$forbiddenAssetPaths = Element\Service::findForbiddenPaths("asset", $user);
if (count($forbiddenAssetPaths) > 0) {
for ($i = 0; $i < count($forbiddenAssetPaths); $i++) {
$forbiddenAssetPaths[$i] = " (maintype = 'asset' AND fullpath not like " . $db->quote($forbiddenAssetPaths[$i] . "%") . ")";
}
$forbiddenConditions[] = implode(" AND ", $forbiddenAssetPaths);
}
}
}
//exclude forbidden documents
if (in_array("document", $types)) {
if (!$user->isAllowed("documents")) {
$forbiddenConditions[] = " `type` != 'document' ";
} else {
$forbiddenDocumentPaths = Element\Service::findForbiddenPaths("document", $user);
if (count($forbiddenDocumentPaths) > 0) {
for ($i = 0; $i < count($forbiddenDocumentPaths); $i++) {
$forbiddenDocumentPaths[$i] = " (maintype = 'document' AND fullpath not like " . $db->quote($forbiddenDocumentPaths[$i] . "%") . ")";
}
$forbiddenConditions[] = implode(" AND ", $forbiddenDocumentPaths);
}
}
}
//exclude forbidden objects
if (in_array("object", $types)) {
if (!$user->isAllowed("objects")) {
$forbiddenConditions[] = " `type` != 'object' ";
} else {
$forbiddenObjectPaths = Element\Service::findForbiddenPaths("object", $user);
if (count($forbiddenObjectPaths) > 0) {
for ($i = 0; $i < count($forbiddenObjectPaths); $i++) {
$forbiddenObjectPaths[$i] = " (maintype = 'object' AND fullpath not like " . $db->quote($forbiddenObjectPaths[$i] . "%") . ")";
}
$forbiddenConditions[] = implode(" AND ", $forbiddenObjectPaths);
}
}
}
if ($forbiddenConditions) {
$conditionParts[] = "(" . implode(" AND ", $forbiddenConditions) . ")";
}
if (!empty($query)) {
$queryCondition = "( MATCH (`data`,`properties`) AGAINST (" . $db->quote($query) . " IN BOOLEAN MODE) )";
// the following should be done with an exact-search now "ID", because the Element-ID is now in the fulltext index
// if the query is numeric the user might want to search by id
//if(is_numeric($query)) {
//$queryCondition = "(" . $queryCondition . " OR id = " . $db->quote($query) ." )";
//}
$conditionParts[] = $queryCondition;
}
//For objects - handling of bricks
$fields = array();
$bricks = array();
if ($this->getParam("fields")) {
$fields = $this->getParam("fields");
foreach ($fields as $f) {
$parts = explode("~", $f);
if (substr($f, 0, 1) == "~") {
// $type = $parts[1];
// $field = $parts[2];
// $keyid = $parts[3];
// key value, ignore for now
} else {
if (count($parts) > 1) {
$bricks[$parts[0]] = $parts[0];
}
}
}
}
// filtering for objects
if ($this->getParam("filter") && $this->getParam("class")) {
$class = Object\ClassDefinition::getByName($this->getParam("class"));
//.........这里部分代码省略.........
示例8: renderDocument
public function renderDocument($params)
{
$html = Document\Service::render($this, $params, true);
return $html;
}
示例9: loadAllFields
/**
* @static
* @param ElementInterface $element
* @return ElementInterface
*/
public static function loadAllFields(ElementInterface $element)
{
if ($element instanceof Document) {
Document\Service::loadAllDocumentFields($element);
} else {
if ($element instanceof Object\Concrete) {
Object\Service::loadAllObjectFields($element);
} else {
if ($element instanceof Asset) {
Asset\Service::loadAllFields($element);
}
}
}
return $element;
}
示例10: addTranslationsData
/**
* @param Model\Document $document
*/
protected function addTranslationsData(Model\Document $document)
{
$service = new Model\Document\Service();
$translations = $service->getTranslations($document);
$language = $document->getProperty("language");
unset($translations[$language]);
$document->translations = $translations;
}
示例11: wordExportAction
public function wordExportAction()
{
//error_reporting(E_ERROR);
//ini_set("display_errors", "off");
$id = $this->getParam("id");
$data = \Zend_Json::decode($this->getParam("data"));
$source = $this->getParam("source");
$exportFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/" . $id . ".html";
if (!is_file($exportFile)) {
/*file_put_contents($exportFile, '<!DOCTYPE html>' . "\n" . '<html>
<head>
<style type="text/css">' . file_get_contents(PIMCORE_PATH . "/static/css/word-export.css") . '</style>
</head>
<body>
');*/
File::put($exportFile, '<style type="text/css">' . file_get_contents(PIMCORE_PATH . "/static6/css/word-export.css") . '</style>');
}
foreach ($data as $el) {
try {
$element = Element\Service::getElementById($el["type"], $el["id"]);
$output = "";
// check supported types (subtypes)
if (!in_array($element->getType(), array("page", "snippet", "email", "object"))) {
continue;
}
if ($element instanceof Element\ElementInterface) {
$output .= '<h1 class="element-headline">' . ucfirst($element->getType()) . " - " . $element->getFullPath() . ' (ID: ' . $element->getId() . ')</h1>';
}
if ($element instanceof Document\PageSnippet) {
if ($element instanceof Document\Page) {
$structuredDataEmpty = true;
$structuredData = '
<table border="1" cellspacing="0" cellpadding="5">
<tr>
<td colspan="2"><span style="color:#cc2929;font-weight: bold;">Structured Data</span></td>
</tr>
';
if ($element->getTitle()) {
$structuredData .= '<tr>
<td><span style="color:#cc2929;">Title</span></td>
<td>' . $element->getTitle() . ' </td>
</tr>';
$structuredDataEmpty = false;
}
if ($element->getDescription()) {
$structuredData .= '<tr>
<td><span style="color:#cc2929;">Description</span></td>
<td>' . $element->getDescription() . ' </td>
</tr>';
$structuredDataEmpty = false;
}
if ($element->getKeywords()) {
$structuredData .= '<tr>
<td><span style="color:#cc2929;">Keywords</span></td>
<td>' . $element->getKeywords() . ' </td>
</tr>';
$structuredDataEmpty = false;
}
if ($element->getProperty("navigation_name")) {
$structuredData .= '<tr>
<td><span style="color:#cc2929;">Navigation</span></td>
<td>' . $element->getProperty("navigation_name") . ' </td>
</tr>';
$structuredDataEmpty = false;
}
$structuredData .= '</table>';
if (!$structuredDataEmpty) {
$output .= $structuredData;
}
}
// we need to set the parameter "pimcore_admin" here to be able to render unpublished documents
$reqBak = $_REQUEST;
$_REQUEST["pimcore_admin"] = true;
$html = Document\Service::render($element, array(), false);
$_REQUEST = $reqBak;
// set the request back to original
$html = preg_replace("@</?(img|meta|div|section|aside|article|body|bdi|bdo|canvas|embed|footer|head|header|html)([^>]+)?>@", "", $html);
$html = preg_replace('/<!--(.*)-->/Uis', '', $html);
include_once "simple_html_dom.php";
$dom = str_get_html($html);
if ($dom) {
// remove containers including their contents
$elements = $dom->find("form,script,style,noframes,noscript,object,area,mapm,video,audio,iframe,textarea,input,select,button,");
if ($elements) {
foreach ($elements as $el) {
$el->outertext = "";
}
}
$clearText = function ($string) {
$string = str_replace("\r\n", "", $string);
$string = str_replace("\n", "", $string);
$string = str_replace("\r", "", $string);
$string = str_replace("\t", "", $string);
$string = preg_replace('/&[a-zA-Z0-9]+;/', '', $string);
// remove html entities
$string = preg_replace('#[ ]+#', '', $string);
return $string;
};
// remove empty tags (where it matters)
$elements = $dom->find("a, li");
//.........这里部分代码省略.........
示例12: translationAddAction
public function translationAddAction()
{
$sourceDocument = Document::getById($this->getParam("sourceId"));
$targetDocument = Document::getByPath($this->getParam("targetPath"));
if ($sourceDocument && $targetDocument) {
$service = new Document\Service();
$service->addTranslation($sourceDocument, $targetDocument);
}
$this->_helper->json(["success" => true]);
}
示例13: documentAction
/** end point for document related data.
* - get document by id
* GET http://[YOUR-DOMAIN]/webservice/rest/document/id/1281?apikey=[API-KEY]
* returns json-encoded document data.
* - delete document by id
* DELETE http://[YOUR-DOMAIN]/webservice/rest/document/id/1281?apikey=[API-KEY]
* returns json encoded success value
* - create document
* PUT or POST http://[YOUR-DOMAIN]/webservice/rest/document?apikey=[API-KEY]
* body: json-encoded document data in the same format as returned by get document by id
* but with missing id field or id set to 0
* returns json encoded document id
* - update document
* PUT or POST http://[YOUR-DOMAIN]/webservice/rest/document?apikey=[API-KEY]
* body: same as for create document but with object id
* returns json encoded success value
* @throws \Exception
*/
public function documentAction()
{
$id = $this->getParam("id");
$success = false;
try {
if ($this->isGet()) {
/**
* @api {get} /document Get document
* @apiName getDocument
* @apiGroup Document
* @apiSampleRequest off
* @apiParam {int} id The id of document you search
* @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:
* HTTP/1.1 200 OK
* {
* "success":true
* }
* @apiError {boolean} success Returns false if failed
* @apiErrorExample {json} Error-Response:
* {"success":false,"msg":"exception 'Exception' with message 'Document with given ID (712131243) does not exist.'"}
*/
$doc = Document::getById($id);
if (!$doc) {
$this->encoder->encode(["success" => false, "msg" => "Document does not exist", "code" => self::ELEMENT_DOES_NOT_EXIST]);
return;
}
$this->checkPermission($doc, "get");
if ($doc) {
$type = $doc->getType();
$getter = "getDocument" . ucfirst($type) . "ById";
if (method_exists($this->service, $getter)) {
$object = $this->service->{$getter}($id);
} else {
// check if the getter is implemented by a plugin
$class = "\\Pimcore\\Model\\Webservice\\Data\\Document\\" . ucfirst($type) . "\\Out";
if (Tool::classExists($class)) {
Document\Service::loadAllDocumentFields($doc);
$object = Webservice\Data\Mapper::map($doc, $class, "out");
} else {
throw new \Exception("unknown type");
}
}
}
if (!$object) {
throw new \Exception("could not find document");
}
@$this->encoder->encode(["success" => true, "data" => $object]);
return;
} elseif ($this->isDelete()) {
/**
* @api {delete} /document Delete document
* @apiName deleteDocument
* @apiGroup Document
* @apiParam {int} id The id of document 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:
* HTTP/1.1 200 OK
* {
* "success":true
* }
* @apiError {boolean} success Returns false if failed
* @apiErrorExample {json} Error-Response:
* {"success":false,"msg":"exception 'Exception' with message 'Document with given ID (712131243) does not exist.'"}
*/
$doc = Document::getById($id);
if ($doc) {
$this->checkPermission($doc, "delete");
}
//.........这里部分代码省略.........
示例14: getUniqueKey
/**
* returns a unique key for an element
*
* @param $element
* @return string
*/
public static function getUniqueKey($element)
{
if ($element instanceof Object\AbstractObject) {
return Object\Service::getUniqueKey($element);
} elseif ($element instanceof Document) {
return Document\Service::getUniqueKey($element);
} elseif ($element instanceof Asset) {
return Asset\Service::getUniqueKey($element);
}
}
示例15: getDocumentSnippetById
/**
* @param $id
* @throws \Exception
*/
public function getDocumentSnippetById($id)
{
try {
$snippet = Document::getById($id);
if ($snippet instanceof Document\Snippet) {
// load all data (eg. href, snippet, ... which are lazy loaded)
Document\Service::loadAllDocumentFields($snippet);
$className = Webservice\Data\Mapper::findWebserviceClass($snippet, "out");
$apiSnippet = Webservice\Data\Mapper::map($snippet, $className, "out");
return $apiSnippet;
}
throw new \Exception("Document Snippet with given ID (" . $id . ") does not exist.");
} catch (\Exception $e) {
\Logger::error($e);
throw $e;
}
}