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); }
/** * set a property * * @param string $name * @param string $type * @param mixed $data * @param boolean $inherited */ public function setProperty($name, $type, $data, $inherited = false) { $this->getProperties(); $property = new Property(); $property->setType($type); $property->setCid($this->getId()); $property->setName($name); $property->setCtype("asset"); $property->setData($data); $property->setInherited($inherited); $this->properties[$name] = $property; }
/** * 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 = array(1); $obj = $this->model->getParent(); if ($obj) { while ($obj) { $parentIds[] = $obj->getId(); $obj = $obj->getParent(); } } $propertiesRaw = $this->db->fetchAll("SELECT * FROM properties WHERE ((cid IN (" . implode(",", $parentIds) . ") AND inheritable = 1) OR cid = ? ) AND ctype='asset'", $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 Property(); $property->setType($propertyRaw["type"]); $property->setCid($this->model->getId()); $property->setName($propertyRaw["name"]); $property->setCtype("asset"); $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 asset " . $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; }
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; }
/** * @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; }