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_Service::wrap($c); $c->setHardLinkSource($hardLink); $c->setPath(preg_replace("@^" . preg_quote($hardLink->getSourceDocument()->getFullpath()) . "@", $hardLink->getFullpath(), $c->getPath())); } } $this->setChilds($childs); } return $this->childs; }
public function saveAction() { if ($this->_getParam("id")) { $snippet = Document_Snippet::getById($this->_getParam("id")); $snippet = $this->getLatestVersion($snippet); $snippet->getPermissionsForUser($this->getUser()); $snippet->setUserModification($this->getUser()->getId()); // save to session $key = "document_" . $this->_getParam("id"); $session = new Zend_Session_Namespace("pimcore_documents"); $session->{$key} = $snippet; if ($this->_getParam("task") == "unpublish") { $snippet->setPublished(false); } if ($this->_getParam("task") == "publish") { $snippet->setPublished(true); } if ($this->_getParam("task") == "publish" && $snippet->isAllowed("publish") or $this->_getParam("task") == "unpublish" && $snippet->isAllowed("unpublish")) { $this->setValuesToDocument($snippet); try { $snippet->save(); $this->_helper->json(array("success" => true)); } catch (Exception $e) { $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } else { if ($snippet->isAllowed("save")) { $this->setValuesToDocument($snippet); try { $snippet->saveVersion(); $this->_helper->json(array("success" => true)); } catch (Exception $e) { $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } } } $this->_helper->json(false); }
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)); } }
/** * creates a new document * @return void */ public function testDocumentSnippetCreate() { $document = $this->createRandomDocument("snippet"); $this->assertTrue($document->getId() > 0); $document->setKey($document->getKey() . "_data"); $document->setProperties($this->getRandomProperties("document")); $document->save(); $refetch = Document_Snippet::getById($document->getId()); //$this->assertTrue($refetch instanceof Document_Snippet); //todo data $this->assertTrue(Test_Tool::documentsAreEqual($document, $refetch, false)); }
/** * Receives a Webservice_Data_Document_Element from webservice import and fill the current tag's data * * @abstract * @param Webservice_Data_Document_Element $data * @return void */ public function getFromWebserviceImport($wsElement) { $data = $wsElement->value; if ($data->id !== null) { $this->id = $data->id; if (is_numeric($this->id)) { $this->snippet = Document_Snippet::getById($this->id); if (!$this->snippet instanceof Document_Snippet) { throw new Exception("cannot get values from web service import - referenced snippet with id [ " . $this->id . " ] is unknown"); } } else { throw new Exception("cannot get values from web service import - id is not valid"); } } }