protected function setValuesToDocument(Document_Hardlink $link) { // data $data = Zend_Json::decode($this->_getParam("data")); $sourceId = null; if ($sourceDocument = Document::getByPath($data["sourcePath"])) { $sourceId = $sourceDocument->getId(); } $link->setSourceId($sourceId); $link->setValues($data); $this->addPropertiesToDocument($link); }
public function getChilds() { if ($this->childs === null) { $childs = parent::getChilds(); $hardLink = $this->getHardLinkSource(); if ($hardLink->getChildsFromSource() && $hardLink->getSourceDocument() && !Pimcore::inAdmin()) { foreach ($childs as &$c) { $c = Document_Hardlink_Wrapper::wrap($c); $c->setHardLinkSource($hardLink); $c->setPath(preg_replace("@^" . preg_quote($hardLink->getSourceDocument()->getFullpath()) . "@", $hardLink->getFullpath(), $c->getPath())); } } $this->setChilds($childs); } return $this->childs; }
/** * this is used to get childs below a hardlink by a path * for example: the requested path is /de/service/contact but /de/service is a hardlink to /en/service * then $hardlink would be /en/service and $path /de/service/contact and this function returns then /en/service/contact * @static * @param Document_Hardlink $hardlink * @param $path */ public static function getChildByPath(Document_Hardlink $hardlink, $path) { if ($hardlink->getChildsFromSource() && $hardlink->getSourceDocument()) { $hardlinkRealPath = preg_replace("@^" . preg_quote($hardlink->getRealFullPath()) . "@", $hardlink->getSourceDocument()->getFullpath(), $path); $hardLinkedDocument = Document::getByPath($hardlinkRealPath); if ($hardLinkedDocument instanceof Document) { $hardLinkedDocument = Document_Hardlink_Service::wrap($hardLinkedDocument); $hardLinkedDocument->setHardLinkSource($hardlink); $_path = $path != "/" ? $_path = dirname($path) : $path; $_path = str_replace("\\", "/", $_path); // windows patch $_path .= $_path != "/" ? "/" : ""; $hardLinkedDocument->setPath($_path); return $hardLinkedDocument; } } return null; }
public function addAction() { $success = false; // 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 if ($this->_getParam("docTypeId") && is_numeric($this->_getParam("docTypeId"))) { $docType = Document_DocType::getById(intval($this->_getParam("docTypeId"))); $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"] = Pimcore_Config::getSystemConfig()->documents->default_controller; $createValues["action"] = Pimcore_Config::getSystemConfig()->documents->default_action; } } switch ($this->_getParam("type")) { case "page": $document = Document_Page::create($this->_getParam("parentId"), $createValues); $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: Logger::debug("Unknown document type, can't add [ " . $this->_getParam("type") . " ] "); break; } } else { Logger::debug("prevented adding a document because document with same path+key [ {$intendedPath} ] already exists"); } } else { Logger::debug("prevented adding a document because of missing permissions"); } if ($success) { $this->_helper->json(array("success" => $success, "id" => $document->getId(), "type" => $document->getType())); } else { $this->_helper->json(array("success" => $success)); } }