protected function setValuesToDocument(Document\Link $link) { // data if ($this->getParam("data")) { $data = \Zend_Json::decode($this->getParam("data")); if (!empty($data["path"])) { if ($document = Document::getByPath($data["path"])) { $data["linktype"] = "internal"; $data["internalType"] = "document"; $data["internal"] = $document->getId(); } elseif ($asset = Asset::getByPath($data["path"])) { $data["linktype"] = "internal"; $data["internalType"] = "asset"; $data["internal"] = $asset->getId(); } else { $data["linktype"] = "direct"; $data["direct"] = $data["path"]; } } else { // clear content of link $data["linktype"] = "internal"; $data["direct"] = ""; $data["internalType"] = null; $data["internal"] = null; } unset($data["path"]); $link->setValues($data); } $this->addPropertiesToDocument($link); }
public function addAction() { $success = false; $errorMessage = ""; // check for permission $parentDocument = Document::getById(intval($this->getParam("parentId"))); if ($parentDocument->isAllowed("create")) { $intendedPath = $parentDocument->getFullPath() . "/" . $this->getParam("key"); if (!Document\Service::pathExists($intendedPath)) { $createValues = array("userOwner" => $this->getUser()->getId(), "userModification" => $this->getUser()->getId(), "published" => false); $createValues["key"] = $this->getParam("key"); // check for a docType $docType = Document\DocType::getById(intval($this->getParam("docTypeId"))); if ($docType) { $createValues["template"] = $docType->getTemplate(); $createValues["controller"] = $docType->getController(); $createValues["action"] = $docType->getAction(); $createValues["module"] = $docType->getModule(); } else { if ($this->getParam("type") == "page" || $this->getParam("type") == "snippet" || $this->getParam("type") == "email") { $createValues["controller"] = Config::getSystemConfig()->documents->default_controller; $createValues["action"] = Config::getSystemConfig()->documents->default_action; } } switch ($this->getParam("type")) { case "page": $document = Document\Page::create($this->getParam("parentId"), $createValues, false); $document->setTitle($this->getParam('title', null)); $document->setProperty("navigation_name", "text", $this->getParam('name', null), false); $document->save(); $success = true; break; case "snippet": $document = Document\Snippet::create($this->getParam("parentId"), $createValues); $success = true; break; case "email": //ckogler $document = Document\Email::create($this->getParam("parentId"), $createValues); $success = true; break; case "link": $document = Document\Link::create($this->getParam("parentId"), $createValues); $success = true; break; case "hardlink": $document = Document\Hardlink::create($this->getParam("parentId"), $createValues); $success = true; break; case "folder": $document = Document\Folder::create($this->getParam("parentId"), $createValues); $document->setPublished(true); try { $document->save(); $success = true; } catch (\Exception $e) { $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } break; default: $classname = "\\Pimcore\\Model\\Document\\" . ucfirst($this->getParam("type")); // this is the fallback for custom document types using prefixes // so we need to check if the class exists first if (!\Pimcore\Tool::classExists($classname)) { $oldStyleClass = "\\Document_" . ucfirst($this->getParam("type")); if (\Pimcore\Tool::classExists($oldStyleClass)) { $classname = $oldStyleClass; } } if (Tool::classExists($classname)) { $document = $classname::create($this->getParam("parentId"), $createValues); try { $document->save(); $success = true; } catch (\Exception $e) { $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } break; } else { \Logger::debug("Unknown document type, can't add [ " . $this->getParam("type") . " ] "); } break; } } else { $errorMessage = "prevented adding a document because document with same path+key [ {$intendedPath} ] already exists"; \Logger::debug($errorMessage); } } else { $errorMessage = "prevented adding a document because of missing permissions"; \Logger::debug($errorMessage); } if ($success) { $this->_helper->json(array("success" => $success, "id" => $document->getId(), "type" => $document->getType())); } else { $this->_helper->json(array("success" => $success, "message" => $errorMessage)); } }