Beispiel #1
0
 protected function addPropertiesToDocument(Document $document)
 {
     // properties
     if ($this->_getParam("properties")) {
         $properties = array();
         // assign inherited properties
         foreach ($document->getProperties() as $p) {
             if ($p->isInherited()) {
                 $properties[$p->getName()] = $p;
             }
         }
         $propertiesData = Zend_Json::decode($this->_getParam("properties"));
         if (is_array($propertiesData)) {
             foreach ($propertiesData as $propertyName => $propertyData) {
                 $value = $propertyData["data"];
                 try {
                     $property = new Property();
                     $property->setType($propertyData["type"]);
                     $property->setName($propertyName);
                     $property->setCtype("document");
                     $property->setDataFromEditmode($value);
                     $property->setInheritable($propertyData["inheritable"]);
                     $properties[$propertyName] = $property;
                 } catch (Exception $e) {
                     Logger::warning("Can't add " . $propertyName . " to document " . $document->getFullPath());
                 }
             }
         }
         if ($document->isAllowed("properties")) {
             $document->setProperties($properties);
         }
     }
     // force loading of properties
     $document->getProperties();
 }
 public function saveAction()
 {
     $success = false;
     if ($this->_getParam("id")) {
         $asset = Asset::getById($this->_getParam("id"));
         if ($asset->isAllowed("publish")) {
             // properties
             if ($this->_getParam("properties")) {
                 $properties = array();
                 $propertiesData = Zend_Json::decode($this->_getParam("properties"));
                 if (is_array($propertiesData)) {
                     foreach ($propertiesData as $propertyName => $propertyData) {
                         $value = $propertyData["data"];
                         try {
                             $property = new Property();
                             $property->setType($propertyData["type"]);
                             $property->setName($propertyName);
                             $property->setCtype("asset");
                             $property->setDataFromEditmode($value);
                             $property->setInheritable($propertyData["inheritable"]);
                             $properties[$propertyName] = $property;
                         } catch (Exception $e) {
                             Logger::err("Can't add " . $propertyName . " to asset " . $asset->getFullPath());
                         }
                     }
                     $asset->setProperties($properties);
                 }
             }
             // scheduled tasks
             if ($this->_getParam("scheduler")) {
                 $tasks = array();
                 $tasksData = Zend_Json::decode($this->_getParam("scheduler"));
                 if (!empty($tasksData)) {
                     foreach ($tasksData as $taskData) {
                         $taskData["date"] = strtotime($taskData["date"] . " " . $taskData["time"]);
                         $task = new Schedule_Task($taskData);
                         $tasks[] = $task;
                     }
                 }
                 $asset->setScheduledTasks($tasks);
             }
             if ($this->_getParam("data")) {
                 $asset->setData($this->_getParam("data"));
             }
             $asset->setUserModification($this->getUser()->getId());
             try {
                 $asset->save();
                 $asset->getData();
                 $success = true;
             } catch (Exception $e) {
                 $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
             }
         } else {
             Logger::debug("prevented save asset because of missing permissions ");
         }
         $this->_helper->json(array("success" => $success));
     }
     $this->_helper->json(false);
 }
 protected function assignPropertiesFromEditmode($object)
 {
     if ($this->_getParam("properties")) {
         $properties = array();
         // assign inherited properties
         foreach ($object->getProperties() as $p) {
             if ($p->isInherited()) {
                 $properties[$p->getName()] = $p;
             }
         }
         $propertiesData = Zend_Json::decode($this->_getParam("properties"));
         if (is_array($propertiesData)) {
             foreach ($propertiesData as $propertyName => $propertyData) {
                 $value = $propertyData["data"];
                 try {
                     $property = new Property();
                     $property->setType($propertyData["type"]);
                     $property->setName($propertyName);
                     $property->setCtype("object");
                     $property->setDataFromEditmode($value);
                     $property->setInheritable($propertyData["inheritable"]);
                     $properties[$propertyName] = $property;
                 } catch (Exception $e) {
                     Logger::err("Can't add " . $propertyName . " to object " . $object->getFullPath());
                 }
             }
         }
         $object->setProperties($properties);
     }
     return $object;
 }
Beispiel #4
0
 /**
  * @param  string $ctype
  *
  * @return array
  */
 protected function getRandomProperties($ctype)
 {
     $document = $this->createRandomDocument("snippet");
     $asset = $this->createRandomAssetImage();
     $object = $this->createRandomObject("unittest");
     $properties = array();
     // object property
     $property = new Property();
     $property->setType("object");
     $property->setName("object");
     $property->setCtype($ctype);
     $property->setDataFromEditmode($object->getFullPath());
     $property->setInheritable(true);
     $properties["object"] = $property;
     // document property
     $property = new Property();
     $property->setType("document");
     $property->setName("document");
     $property->setCtype($ctype);
     $property->setDataFromEditmode($document->getFullPath());
     $property->setInheritable(true);
     $properties["document"] = $property;
     // asset property
     $property = new Property();
     $property->setType("asset");
     $property->setName("asset");
     $property->setCtype($ctype);
     $property->setDataFromEditmode($asset->getFullPath());
     $property->setInheritable(true);
     $properties["asset"] = $property;
     // text property
     $property = new Property();
     $property->setType("text");
     $property->setName("text");
     $property->setCtype($ctype);
     $property->setDataFromEditmode("hallo property");
     $property->setInheritable(true);
     $properties["text"] = $property;
     // bool  property
     $property = new Property();
     $property->setType("bool");
     $property->setName("bool");
     $property->setCtype($ctype);
     $property->setDataFromEditmode(true);
     $property->setInheritable(true);
     $properties["bool"] = $property;
     // date  property
     $property = new Property();
     $property->setType("date");
     $property->setName("date");
     $property->setCtype($ctype);
     $property->setDataFromEditmode(new Zend_Date());
     $property->setInheritable(true);
     $properties["date"] = $property;
     return $properties;
 }