상속: extends AbstractModel
예제 #1
0
 /**
  * @param Model\Document $document
  * @throws \Zend_Json_Exception
  */
 protected function addPropertiesToDocument(Model\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();
 }
예제 #2
0
 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 Model\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;
 }
예제 #3
0
 /**
  * Get the properties for the object from database and assign it
  *
  * @return void
  */
 public function getProperties($onlyInherited = false)
 {
     $properties = array();
     // collect properties via parent - ids
     $parentIds = $this->getParentIds();
     $propertiesRaw = $this->db->fetchAll("SELECT * FROM properties WHERE ((cid IN (" . implode(",", $parentIds) . ") AND inheritable = 1) OR cid = ? )  AND ctype='object'", $this->model->getId());
     // because this should be faster than mysql
     usort($propertiesRaw, function ($left, $right) {
         return strcmp($left["cpath"], $right["cpath"]);
     });
     foreach ($propertiesRaw as $propertyRaw) {
         try {
             $property = new Model\Property();
             $property->setType($propertyRaw["type"]);
             $property->setCid($this->model->getId());
             $property->setName($propertyRaw["name"]);
             $property->setCtype("object");
             $property->setDataFromResource($propertyRaw["data"]);
             $property->setInherited(true);
             if ($propertyRaw["cid"] == $this->model->getId()) {
                 $property->setInherited(false);
             }
             $property->setInheritable(false);
             if ($propertyRaw["inheritable"]) {
                 $property->setInheritable(true);
             }
             if ($onlyInherited && !$property->getInherited()) {
                 continue;
             }
             $properties[$propertyRaw["name"]] = $property;
         } catch (\Exception $e) {
             \Logger::error("can't add property " . $propertyRaw["name"] . " to object " . $this->model->getFullPath());
         }
     }
     // if only inherited then only return it and dont call the setter in the model
     if ($onlyInherited) {
         return $properties;
     }
     $this->model->setProperties($properties);
     return $properties;
 }
예제 #4
0
 /**
  * @param $name
  * @param $type
  * @param $data
  * @param bool $inherited
  * @param bool $inheritable
  * @return $this
  */
 public function setProperty($name, $type, $data, $inherited = false, $inheritable = false)
 {
     $this->getProperties();
     $property = new Model\Property();
     $property->setType($type);
     $property->setCid($this->getId());
     $property->setName($name);
     $property->setCtype("object");
     $property->setData($data);
     $property->setInherited($inherited);
     $property->setInheritable($inheritable);
     $this->o_properties[$name] = $property;
     return $this;
 }
 public function saveAction()
 {
     $success = false;
     if ($this->getParam("id")) {
         $asset = Asset::getById($this->getParam("id"));
         if ($asset->isAllowed("publish")) {
             // metadata
             if ($this->getParam("metadata")) {
                 $metadata = \Zend_Json::decode($this->getParam("metadata"));
                 $metadata = Asset\Service::minimizeMetadata($metadata);
                 $asset->setMetadata($metadata);
             }
             // 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 Model\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 Model\Schedule\Task($taskData);
                         $tasks[] = $task;
                     }
                 }
                 $asset->setScheduledTasks($tasks);
             }
             if ($this->hasParam("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);
 }