Sets the value of the property with the given id
public setPropertyWithId ( $keyId, $value, boolean $fromGrid = false ) : |
||
$keyId | the id of the key | |
$value | the value | |
$fromGrid | boolean | if true then the data is coming from the grid, we have to check if the value needs to be translated |
리턴 | the resulting object |
public function gridProxyAction() { if ($this->getParam("language")) { $this->setLanguage($this->getParam("language"), true); } if ($this->getParam("data")) { if ($this->getParam("xaction") == "update") { try { $data = \Zend_Json::decode($this->getParam("data")); // save $object = Object::getById($data["id"]); /** @var Object\ClassDefinition $class */ $class = $object->getClass(); if (!$object->isAllowed("publish")) { throw new \Exception("Permission denied. You don't have the rights to save this object."); } $user = Tool\Admin::getCurrentUser(); if (!$user->isAdmin()) { $languagePermissions = $object->getPermissions("lEdit", $user); $languagePermissions = explode(",", $languagePermissions["lEdit"]); } $objectData = array(); foreach ($data as $key => $value) { $parts = explode("~", $key); if (substr($key, 0, 1) == "~") { $type = $parts[1]; $field = $parts[2]; $keyid = $parts[3]; $getter = "get" . ucfirst($field); $setter = "set" . ucfirst($field); $keyValuePairs = $object->{$getter}(); if (!$keyValuePairs) { $keyValuePairs = new Object\Data\KeyValue(); $keyValuePairs->setObjectId($object->getId()); $keyValuePairs->setClass($object->getClass()); } $keyValuePairs->setPropertyWithId($keyid, $value, true); $object->{$setter}($keyValuePairs); } elseif (count($parts) > 1) { $brickType = $parts[0]; $brickKey = $parts[1]; $brickField = Object\Service::getFieldForBrickType($object->getClass(), $brickType); $fieldGetter = "get" . ucfirst($brickField); $brickGetter = "get" . ucfirst($brickType); $valueSetter = "set" . ucfirst($brickKey); $brick = $object->{$fieldGetter}()->{$brickGetter}(); if (empty($brick)) { $classname = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($brickType); $brickSetter = "set" . ucfirst($brickType); $brick = new $classname($object); $object->{$fieldGetter}()->{$brickSetter}($brick); } $brick->{$valueSetter}($value); } else { if (!$user->isAdmin() && $languagePermissions) { $fd = $class->getFieldDefinition($key); if (!$fd) { // try to get via localized fields $localized = $class->getFieldDefinition("localizedfields"); if ($localized instanceof Object\ClassDefinition\Data\Localizedfields) { $field = $localized->getFieldDefinition($key); if ($field) { $currentLocale = (string) \Zend_Registry::get("Zend_Locale"); if (!in_array($currentLocale, $languagePermissions)) { continue; } } } } } $objectData[$key] = $value; } } $object->setValues($objectData); $object->save(); $this->_helper->json(array("data" => Object\Service::gridObjectData($object, $this->getParam("fields")), "success" => true)); } catch (\Exception $e) { $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } } else { // get list of objects $folder = Object::getById($this->getParam("folderId")); $class = Object\ClassDefinition::getById($this->getParam("classId")); $className = $class->getName(); $colMappings = array("filename" => "o_key", "fullpath" => array("o_path", "o_key"), "id" => "o_id", "published" => "o_published", "modificationDate" => "o_modificationDate", "creationDate" => "o_creationDate"); $start = 0; $limit = 20; $orderKey = "o_id"; $order = "ASC"; $fields = array(); $bricks = array(); if ($this->getParam("fields")) { $fields = $this->getParam("fields"); foreach ($fields as $f) { $parts = explode("~", $f); $sub = substr($f, 0, 1); if (substr($f, 0, 1) == "~") { // $type = $parts[1]; // $field = $parts[2]; // $keyid = $parts[3]; // key value, ignore for now } elseif (count($parts) > 1) { $bricks[$parts[0]] = $parts[0]; } } } if ($this->getParam("limit")) { $limit = $this->getParam("limit"); } if ($this->getParam("start")) { $start = $this->getParam("start"); } $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['order']) { $order = $sortingSettings['order']; } if (strlen($sortingSettings['orderKey']) > 0) { $orderKey = $sortingSettings['orderKey']; if (!(substr($orderKey, 0, 1) == "~")) { if (array_key_exists($orderKey, $colMappings)) { $orderKey = $colMappings[$orderKey]; } } } $listClass = "\\Pimcore\\Model\\Object\\" . ucfirst($className) . "\\Listing"; $conditionFilters = array(); if ($this->getParam("only_direct_children") == "true") { $conditionFilters[] = "o_parentId = " . $folder->getId(); } else { $conditionFilters[] = "(o_path = '" . $folder->getFullPath() . "' OR o_path LIKE '" . str_replace("//", "/", $folder->getFullPath() . "/") . "%')"; } // create filter condition if ($this->getParam("filter")) { $conditionFilters[] = Object\Service::getFilterCondition($this->getParam("filter"), $class); } if ($this->getParam("condition")) { $conditionFilters[] = "(" . $this->getParam("condition") . ")"; } $list = new $listClass(); if (!empty($bricks)) { foreach ($bricks as $b) { $list->addObjectbrick($b); } } $list->setCondition(implode(" AND ", $conditionFilters)); $list->setLimit($limit); $list->setOffset($start); $list->setOrder($order); $list->setOrderKey($orderKey); if ($class->getShowVariants()) { $list->setObjectTypes([Object\AbstractObject::OBJECT_TYPE_OBJECT, Object\AbstractObject::OBJECT_TYPE_VARIANT]); } $list->load(); $objects = array(); foreach ($list->getObjects() as $object) { $o = Object\Service::gridObjectData($object, $fields); $objects[] = $o; } $this->_helper->json(array("data" => $objects, "success" => true, "total" => $list->getTotalCount())); } }
public function getVariantsAction() { // get list of variants if ($this->getParam("language")) { $this->setLanguage($this->getParam("language"), true); } if ($this->getParam("xaction") == "update") { $data = \Zend_Json::decode($this->getParam("data")); // save $object = Object::getById($data["id"]); if ($object->isAllowed("publish")) { $objectData = []; foreach ($data as $key => $value) { $parts = explode("~", $key); if (substr($key, 0, 1) == "~") { $type = $parts[1]; $field = $parts[2]; $keyid = $parts[3]; $getter = "get" . ucfirst($field); $setter = "set" . ucfirst($field); $keyValuePairs = $object->{$getter}(); if (!$keyValuePairs) { $keyValuePairs = new Object\Data\KeyValue(); $keyValuePairs->setObjectId($object->getId()); $keyValuePairs->setClass($object->getClass()); } $keyValuePairs->setPropertyWithId($keyid, $value, true); $object->{$setter}($keyValuePairs); } elseif (count($parts) > 1) { $brickType = $parts[0]; $brickKey = $parts[1]; $brickField = Object\Service::getFieldForBrickType($object->getClass(), $brickType); $fieldGetter = "get" . ucfirst($brickField); $brickGetter = "get" . ucfirst($brickType); $valueSetter = "set" . ucfirst($brickKey); $brick = $object->{$fieldGetter}()->{$brickGetter}(); if (empty($brick)) { $classname = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($brickType); $brickSetter = "set" . ucfirst($brickType); $brick = new $classname($object); $object->{$fieldGetter}()->{$brickSetter}($brick); } $brick->{$valueSetter}($value); } else { $objectData[$key] = $value; } } $object->setValues($objectData); try { $object->save(); $this->_helper->json(["data" => Object\Service::gridObjectData($object, $this->getParam("fields")), "success" => true]); } catch (\Exception $e) { $this->_helper->json(["success" => false, "message" => $e->getMessage()]); } } else { throw new \Exception("Permission denied"); } } else { $parentObject = Object\Concrete::getById($this->getParam("objectId")); if (empty($parentObject)) { throw new \Exception("No Object found with id " . $this->getParam("objectId")); } if ($parentObject->isAllowed("view")) { $class = $parentObject->getClass(); $className = $parentObject->getClass()->getName(); $start = 0; $limit = 15; $orderKey = "o_id"; $order = "ASC"; $fields = []; $bricks = []; if ($this->getParam("fields")) { $fields = $this->getParam("fields"); foreach ($fields as $f) { $parts = explode("~", $f); if (count($parts) > 1) { $bricks[$parts[0]] = $parts[0]; } } } if ($this->getParam("limit")) { $limit = $this->getParam("limit"); } if ($this->getParam("start")) { $start = $this->getParam("start"); } $orderKey = "o_id"; $order = "ASC"; $colMappings = ["filename" => "o_key", "fullpath" => ["o_path", "o_key"], "id" => "o_id", "published" => "o_published", "modificationDate" => "o_modificationDate", "creationDate" => "o_creationDate"]; $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['orderKey'] && $sortingSettings['order']) { $orderKey = $sortingSettings['orderKey']; if (array_key_exists($orderKey, $colMappings)) { $orderKey = $colMappings[$orderKey]; } $order = $sortingSettings['order']; } if ($this->getParam("dir")) { $order = $this->getParam("dir"); } $listClass = "\\Pimcore\\Model\\Object\\" . ucfirst($className) . "\\Listing"; $conditionFilters = ["o_parentId = " . $parentObject->getId()]; // create filter condition if ($this->getParam("filter")) { $conditionFilters[] = Object\Service::getFilterCondition($this->getParam("filter"), $class); } if ($this->getParam("condition")) { $conditionFilters[] = "(" . $this->getParam("condition") . ")"; } $list = new $listClass(); if (!empty($bricks)) { foreach ($bricks as $b) { $list->addObjectbrick($b); } } $list->setCondition(implode(" AND ", $conditionFilters)); $list->setLimit($limit); $list->setOffset($start); $list->setOrder($order); $list->setOrderKey($orderKey); $list->setObjectTypes([Object\AbstractObject::OBJECT_TYPE_VARIANT]); $list->load(); $objects = []; foreach ($list->getObjects() as $object) { if ($object->isAllowed("view")) { $o = Object\Service::gridObjectData($object, $fields); $objects[] = $o; } } $this->_helper->json(["data" => $objects, "success" => true, "total" => $list->getTotalCount()]); } else { throw new \Exception("Permission denied"); } } }
public function batchAction() { $success = true; try { $object = Object::getById($this->getParam("job")); if ($object) { $className = $object->getClassName(); $class = Object\ClassDefinition::getByName($className); $value = $this->getParam("value"); if ($this->getParam("valueType") == "object") { $value = \Zend_Json::decode($value); } $name = $this->getParam("name"); $parts = explode("~", $name); if (substr($name, 0, 1) == "~") { $type = $parts[1]; $field = $parts[2]; $keyid = $parts[3]; $getter = "get" . ucfirst($field); $setter = "set" . ucfirst($field); $keyValuePairs = $object->{$getter}(); if (!$keyValuePairs) { $keyValuePairs = new Object\Data\KeyValue(); $keyValuePairs->setObjectId($object->getId()); $keyValuePairs->setClass($object->getClass()); } $keyValuePairs->setPropertyWithId($keyid, $value, true); $object->{$setter}($keyValuePairs); } else { if (count($parts) > 1) { // check for bricks $brickType = $parts[0]; $brickKey = $parts[1]; $brickField = Object\Service::getFieldForBrickType($object->getClass(), $brickType); $fieldGetter = "get" . ucfirst($brickField); $brickGetter = "get" . ucfirst($brickType); $valueSetter = "set" . ucfirst($brickKey); $brick = $object->{$fieldGetter}()->{$brickGetter}(); if (empty($brick)) { $classname = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($brickType); $brickSetter = "set" . ucfirst($brickType); $brick = new $classname($object); $object->{$fieldGetter}()->{$brickSetter}($brick); } $brickClass = Object\Objectbrick\Definition::getByKey($brickType); $field = $brickClass->getFieldDefinition($brickKey); $brick->{$valueSetter}($field->getDataFromEditmode($value, $object)); } else { // everything else $field = $class->getFieldDefinition($name); if ($field) { $object->setValue($name, $field->getDataFromEditmode($value, $object)); } else { // check if it is a localized field if ($this->getParam("language")) { $localizedField = $class->getFieldDefinition("localizedfields"); if ($localizedField) { $field = $localizedField->getFieldDefinition($name); if ($field) { $object->{"set" . $name}($value, $this->getParam("language")); } } } // seems to be a system field, this is actually only possible for the "published" field yet if ($name == "published") { if ($value == "false" || empty($value)) { $object->setPublished(false); } else { $object->setPublished(true); } } } } } try { // don't check for mandatory fields here $object->setOmitMandatoryCheck(true); $object->setUserModification($this->getUser()->getId()); $object->save(); $success = true; } catch (\Exception $e) { $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } else { \Logger::debug("ObjectController::batchAction => There is no object left to update."); $this->_helper->json(array("success" => false, "message" => "ObjectController::batchAction => There is no object left to update.")); } } catch (\Exception $e) { \Logger::err($e); $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } $this->_helper->json(array("success" => $success)); }
public function gridProxyAction() { $requestedLanguage = $this->getParam("language"); if ($requestedLanguage) { if ($requestedLanguage != "default") { $this->setLanguage($requestedLanguage, true); } } else { $requestedLanguage = $this->getLanguage(); } if ($this->getParam("data")) { if ($this->getParam("xaction") == "update") { try { $data = \Zend_Json::decode($this->getParam("data")); // save $object = Object::getById($data["id"]); /** @var Object\ClassDefinition $class */ $class = $object->getClass(); if (!$object->isAllowed("publish")) { throw new \Exception("Permission denied. You don't have the rights to save this object."); } $user = Tool\Admin::getCurrentUser(); $allLanguagesAllowed = false; if (!$user->isAdmin()) { $languagePermissions = $object->getPermissions("lEdit", $user); //sets allowed all languages modification when the lEdit column is empty $allLanguagesAllowed = $languagePermissions["lEdit"] == ''; $languagePermissions = explode(",", $languagePermissions["lEdit"]); } $objectData = []; foreach ($data as $key => $value) { $parts = explode("~", $key); if (substr($key, 0, 1) == "~") { $type = $parts[1]; $field = $parts[2]; $keyid = $parts[3]; if ($type == "classificationstore") { $groupKeyId = explode("-", $keyid); $groupId = $groupKeyId[0]; $keyid = $groupKeyId[1]; $getter = "get" . ucfirst($field); if (method_exists($object, $getter)) { /** @var $classificationStoreData Object\Classificationstore */ $classificationStoreData = $object->{$getter}(); $classificationStoreData->setLocalizedKeyValue($groupId, $keyid, $value, $requestedLanguage); } } else { $getter = "get" . ucfirst($field); $setter = "set" . ucfirst($field); $keyValuePairs = $object->{$getter}(); if (!$keyValuePairs) { $keyValuePairs = new Object\Data\KeyValue(); $keyValuePairs->setObjectId($object->getId()); $keyValuePairs->setClass($object->getClass()); } $keyValuePairs->setPropertyWithId($keyid, $value, true); $object->{$setter}($keyValuePairs); } } elseif (count($parts) > 1) { $brickType = $parts[0]; $brickKey = $parts[1]; $brickField = Object\Service::getFieldForBrickType($object->getClass(), $brickType); $fieldGetter = "get" . ucfirst($brickField); $brickGetter = "get" . ucfirst($brickType); $valueSetter = "set" . ucfirst($brickKey); $brick = $object->{$fieldGetter}()->{$brickGetter}(); if (empty($brick)) { $classname = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($brickType); $brickSetter = "set" . ucfirst($brickType); $brick = new $classname($object); $object->{$fieldGetter}()->{$brickSetter}($brick); } $brick->{$valueSetter}($value); } else { if (!$user->isAdmin() && $languagePermissions) { $fd = $class->getFieldDefinition($key); if (!$fd) { // try to get via localized fields $localized = $class->getFieldDefinition("localizedfields"); if ($localized instanceof Object\ClassDefinition\Data\Localizedfields) { $field = $localized->getFieldDefinition($key); if ($field) { $currentLocale = (string) \Zend_Registry::get("Zend_Locale"); if (!$allLanguagesAllowed && !in_array($currentLocale, $languagePermissions)) { continue; } } } } } $objectData[$key] = $value; } } $object->setValues($objectData); $object->save(); $this->_helper->json(["data" => Object\Service::gridObjectData($object, $this->getParam("fields"), $requestedLanguage), "success" => true]); } catch (\Exception $e) { $this->_helper->json(["success" => false, "message" => $e->getMessage()]); } } } else { // get list of objects $folder = Object::getById($this->getParam("folderId")); $class = Object\ClassDefinition::getById($this->getParam("classId")); $className = $class->getName(); $colMappings = ["filename" => "o_key", "fullpath" => ["o_path", "o_key"], "id" => "o_id", "published" => "o_published", "modificationDate" => "o_modificationDate", "creationDate" => "o_creationDate"]; $start = 0; $limit = 20; $orderKey = "o_id"; $order = "ASC"; $fields = []; $bricks = []; if ($this->getParam("fields")) { $fields = $this->getParam("fields"); foreach ($fields as $f) { $parts = explode("~", $f); $sub = substr($f, 0, 1); if (substr($f, 0, 1) == "~") { $type = $parts[1]; // $field = $parts[2]; // $keyid = $parts[3]; // key value, ignore for now if ($type == "classificationstore") { } } elseif (count($parts) > 1) { $bricks[$parts[0]] = $parts[0]; } } } if ($this->getParam("limit")) { $limit = $this->getParam("limit"); } if ($this->getParam("start")) { $start = $this->getParam("start"); } $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); $doNotQuote = false; if ($sortingSettings['order']) { $order = $sortingSettings['order']; } if (strlen($sortingSettings['orderKey']) > 0) { $orderKey = $sortingSettings['orderKey']; if (!(substr($orderKey, 0, 1) == "~")) { if (array_key_exists($orderKey, $colMappings)) { $orderKey = $colMappings[$orderKey]; } elseif ($class->getFieldDefinition($orderKey) instanceof Object\ClassDefinition\Data\QuantityValue) { $orderKey = "concat(" . $orderKey . "__unit, " . $orderKey . "__value)"; $doNotQuote = true; } elseif (strpos($orderKey, "~") !== false) { $orderKeyParts = explode("~", $orderKey); if (count($orderKeyParts) == 2) { $orderKey = $orderKeyParts[1]; } } } } $listClass = "\\Pimcore\\Model\\Object\\" . ucfirst($className) . "\\Listing"; $conditionFilters = []; if ($this->getParam("only_direct_children") == "true") { $conditionFilters[] = "o_parentId = " . $folder->getId(); } else { $conditionFilters[] = "(o_path = '" . $folder->getRealFullPath() . "' OR o_path LIKE '" . str_replace("//", "/", $folder->getRealFullPath() . "/") . "%')"; } if (!$this->getUser()->isAdmin()) { $userIds = $this->getUser()->getRoles(); $userIds[] = $this->getUser()->getId(); $conditionFilters[] .= " (\n (select list from users_workspaces_object where userId in (" . implode(',', $userIds) . ") and LOCATE(CONCAT(o_path,o_key),cpath)=1 ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\n OR\n (select list from users_workspaces_object where userId in (" . implode(',', $userIds) . ") and LOCATE(cpath,CONCAT(o_path,o_key))=1 ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\n )"; } $featureJoins = []; $featureFilters = false; // create filter condition if ($this->getParam("filter")) { $conditionFilters[] = Object\Service::getFilterCondition($this->getParam("filter"), $class); $featureFilters = Object\Service::getFeatureFilters($this->getParam("filter"), $class); if ($featureFilters) { $featureJoins = array_merge($featureJoins, $featureFilters["joins"]); } } if ($this->getParam("condition")) { $conditionFilters[] = "(" . $this->getParam("condition") . ")"; } $list = new $listClass(); if (!empty($bricks)) { foreach ($bricks as $b) { $list->addObjectbrick($b); } } $list->setCondition(implode(" AND ", $conditionFilters)); $list->setLimit($limit); $list->setOffset($start); if (isset($sortingSettings["isFeature"]) && $sortingSettings["isFeature"]) { $orderKey = "cskey_" . $sortingSettings["fieldname"] . "_" . $sortingSettings["groupId"] . "_" . $sortingSettings["keyId"]; $list->setOrderKey($orderKey); $list->setGroupBy("o_id"); $featureJoins[] = $sortingSettings; } else { $list->setOrderKey($orderKey, !$doNotQuote); } $list->setOrder($order); if ($class->getShowVariants()) { $list->setObjectTypes([Object\AbstractObject::OBJECT_TYPE_OBJECT, Object\AbstractObject::OBJECT_TYPE_VARIANT]); } Object\Service::addGridFeatureJoins($list, $featureJoins, $class, $featureFilters, $requestedLanguage); $list->load(); $objects = []; foreach ($list->getObjects() as $object) { $o = Object\Service::gridObjectData($object, $fields, $requestedLanguage); $objects[] = $o; } $this->_helper->json(["data" => $objects, "success" => true, "total" => $list->getTotalCount()]); } }