示例#1
0
 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);
 }
示例#2
0
 /**
  * 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));
 }
示例#3
0
 /**
  * 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");
         }
     }
 }