Пример #1
0
 protected function setValuesToDocument(Document_Link $link)
 {
     // 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();
         } else {
             if ($asset = Asset::getByPath($data["path"])) {
                 $data["linktype"] = "internal";
                 $data["internalType"] = "asset";
                 $data["internal"] = $asset->getId();
             } else {
                 $data["linktype"] = "direct";
                 $data["direct"] = $data["path"];
             }
         }
     }
     unset($data["path"]);
     $link->setValues($data);
     $this->addPropertiesToDocument($link);
 }
Пример #2
0
 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 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));
     }
 }
Пример #4
0
 /**
  * creates a new document
  * @return void
  * @depends testDocumentPageCreate
  */
 public function testDocumentLinkCreate()
 {
     $document = $this->createRandomDocument("link");
     $this->assertTrue($document->getId() > 0);
     $document->setKey($document->getKey() . "_data");
     $document->setProperties($this->getRandomProperties("document"));
     $refetch = Document_Link::getById($document->getId());
     //$this->assertTrue($refetch instanceof Document_Link);
     $linkedDoc = $this->createRandomDocument("page");
     $data["linktype"] = "internal";
     $data["internalType"] = "document";
     $data["internal"] = $linkedDoc->getId();
     $document->setObject($linkedDoc);
     $document->setValues($data);
     $document->save();
     $this->assertTrue(Test_Tool::documentsAreEqual($document, $refetch, false));
 }