/** * Loads a list of custom layouts for the specified parameters, returns an array of Object\ClassDefinition\CustomLayout elements * * @return array */ public function load() { $layouts = array(); $layoutsRaw = $this->db->fetchCol("SELECT id FROM custom_layouts" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables()); foreach ($layoutsRaw as $classRaw) { $layouts[] = Model\Object\ClassDefinition\CustomLayout::getById($classRaw); } $this->model->setLayoutDefinitions($layouts); return $layouts; }
public function getAction() { // check for lock if (Element\Editlock::isLocked($this->getParam("id"), "object")) { $this->_helper->json(array("editlock" => Element\Editlock::getByElement($this->getParam("id"), "object"))); } Element\Editlock::lock($this->getParam("id"), "object"); $object = Object::getById(intval($this->getParam("id"))); // set the latest available version for editmode $latestObject = $this->getLatestVersion($object); // we need to know if the latest version is published or not (a version), because of lazy loaded fields in $this->getDataForObject() $objectFromVersion = $latestObject === $object ? false : true; $object = $latestObject; if ($object->isAllowed("view")) { $objectData = array(); $objectData["idPath"] = Element\Service::getIdPath($object); $objectData["previewUrl"] = $object->getClass()->getPreviewUrl(); $objectData["general"] = array(); $allowedKeys = array("o_published", "o_key", "o_id", "o_modificationDate", "o_creationDate", "o_classId", "o_className", "o_locked", "o_type", "o_parentId", "o_userOwner", "o_userModification"); foreach (get_object_vars($object) as $key => $value) { if (strstr($key, "o_") && in_array($key, $allowedKeys)) { $objectData["general"][$key] = $value; } } $objectData["general"]["o_locked"] = $object->isLocked(); $this->getDataForObject($object, $objectFromVersion); $objectData["data"] = $this->objectData; $objectData["metaData"] = $this->metaData; $objectData["layout"] = $object->getClass()->getLayoutDefinitions(); $objectData["properties"] = Element\Service::minimizePropertiesForEditmode($object->getProperties()); $objectData["userPermissions"] = $object->getUserPermissions(); $objectData["versions"] = array_splice($object->getVersions(), 0, 1); $objectData["scheduledTasks"] = $object->getScheduledTasks(); $objectData["general"]["allowVariants"] = $object->getClass()->getAllowVariants(); $objectData["general"]["showVariants"] = $object->getClass()->getShowVariants(); $objectData["general"]["fullpath"] = $object->getFullPath(); if ($object->getElementAdminStyle()->getElementIcon()) { $objectData["general"]["icon"] = $object->getElementAdminStyle()->getElementIcon(); } if ($object->getElementAdminStyle()->getElementIconClass()) { $objectData["general"]["iconCls"] = $object->getElementAdminStyle()->getElementIconClass(); } if ($object instanceof Object\Concrete) { $objectData["lazyLoadedFields"] = $object->getLazyLoadedFields(); } $objectData["childdata"]["id"] = $object->getId(); $objectData["childdata"]["data"]["classes"] = $object->getDao()->getClasses(); $currentLayoutId = $this->getParam("layoutId", null); $validLayouts = Object\Service::getValidLayouts($object); //master layout has id 0 so we check for is_null() if (is_null($currentLayoutId) && !empty($validLayouts)) { foreach ($validLayouts as $checkDefaultLayout) { if ($checkDefaultLayout->getDefault()) { $currentLayoutId = $checkDefaultLayout->getId(); } } } if (!empty($validLayouts)) { $objectData["validLayouts"] = array(); foreach ($validLayouts as $validLayout) { $objectData["validLayouts"][] = array("id" => $validLayout->getId(), "name" => $validLayout->getName()); } $user = Tool\Admin::getCurrentUser(); if ($currentLayoutId == 0 && !$user->isAdmin()) { $first = reset($validLayouts); $currentLayoutId = $first->getId(); } if ($currentLayoutId > 0) { // check if user has sufficient rights if ($validLayouts && $validLayouts[$currentLayoutId]) { $customLayout = Object\ClassDefinition\CustomLayout::getById($currentLayoutId); $customLayoutDefinition = $customLayout->getLayoutDefinitions(); $objectData["layout"] = $customLayoutDefinition; } else { $currentLayoutId = 0; } } elseif ($currentLayoutId == -1 && $user->isAdmin()) { $layout = Object\Service::getSuperLayoutDefinition($object); $objectData["layout"] = $layout; } $objectData["currentLayoutId"] = $currentLayoutId; } $objectData = $this->filterLocalizedFields($object, $objectData); Object\Service::enrichLayoutDefinition($objectData["layout"], $object); //Hook for modifying return value - e.g. for changing permissions based on object data //data need to wrapped into a container in order to pass parameter to event listeners by reference so that they can change the values $returnValueContainer = new Model\Tool\Admin\EventDataContainer($objectData); \Pimcore::getEventManager()->trigger("admin.object.get.preSendData", $this, ["object" => $object, "returnValueContainer" => $returnValueContainer]); $this->_helper->json($returnValueContainer->getData()); } else { \Logger::debug("prevented getting object id [ " . $object->getId() . " ] because of missing permissions"); $this->_helper->json(array("success" => false, "message" => "missing_permission")); } }
public static function getCustomGridFieldDefinitions($classId, $objectId) { $object = AbstractObject::getById($objectId); $class = ClassDefinition::getById($classId); $masterFieldDefinition = $class->getFieldDefinitions(); if (!$object) { return null; } $user = AdminTool::getCurrentUser(); if ($user->isAdmin()) { return null; } $permissionList = array(); $parentPermissionSet = $object->getPermissions(null, $user, true); if ($parentPermissionSet) { $permissionList[] = $parentPermissionSet; } $childPermissions = $object->getChildPermissions(null, $user); $permissionList = array_merge($permissionList, $childPermissions); $layoutDefinitions = array(); foreach ($permissionList as $permissionSet) { $allowedLayoutIds = self::getLayoutPermissions($classId, $permissionSet); if (is_array($allowedLayoutIds)) { foreach ($allowedLayoutIds as $allowedLayoutId) { if ($allowedLayoutId) { if (!$layoutDefinitions[$allowedLayoutId]) { $customLayout = ClassDefinition\CustomLayout::getById($allowedLayoutId); if (!$customLayout) { continue; } $layoutDefinitions[$allowedLayoutId] = $customLayout; } } } } } $mergedFieldDefinition = unserialize(serialize($masterFieldDefinition)); if (count($layoutDefinitions)) { foreach ($mergedFieldDefinition as $key => $def) { if ($def instanceof ClassDefinition\Data\Localizedfields) { $mergedLocalizedFieldDefinitions = $mergedFieldDefinition[$key]->getFieldDefinitions(); foreach ($mergedLocalizedFieldDefinitions as $locKey => $locValue) { $mergedLocalizedFieldDefinitions[$locKey]->setInvisible(false); $mergedLocalizedFieldDefinitions[$locKey]->setNotEditable(false); } $mergedFieldDefinition[$key]->setChilds($mergedLocalizedFieldDefinitions); } else { $mergedFieldDefinition[$key]->setInvisible(false); $mergedFieldDefinition[$key]->setNotEditable(false); } } } foreach ($layoutDefinitions as $customLayoutDefinition) { $layoutName = $customLayoutDefinition->getName(); $layoutDefinitions = $customLayoutDefinition->getLayoutDefinitions(); $dummyClass = new ClassDefinition(); $dummyClass->setLayoutDefinitions($layoutDefinitions); $customFieldDefinitions = $dummyClass->getFieldDefinitions(); foreach ($mergedFieldDefinition as $key => $value) { if (!$customFieldDefinitions[$key]) { unset($mergedFieldDefinition[$key]); } } foreach ($customFieldDefinitions as $key => $def) { if ($def instanceof ClassDefinition\Data\Localizedfields) { if (!$mergedFieldDefinition[$key]) { continue; } $customLocalizedFieldDefinitions = $def->getFieldDefinitions(); $mergedLocalizedFieldDefinitions = $mergedFieldDefinition[$key]->getFieldDefinitions(); foreach ($mergedLocalizedFieldDefinitions as $locKey => $locValue) { self::mergeFieldDefinition($mergedLocalizedFieldDefinitions, $customLocalizedFieldDefinitions, $locKey); } $mergedFieldDefinition[$key]->setChilds($mergedLocalizedFieldDefinitions); } else { self::mergeFieldDefinition($mergedFieldDefinition, $customFieldDefinitions, $key); } } } return $mergedFieldDefinition; }
/** * Deletes object from database * * @return void */ public function delete() { $this->db->delete("custom_layouts", $this->db->quoteInto("id = ?", $this->model->getId())); @unlink(PIMCORE_CUSTOMLAYOUT_DIRECTORY . "/custom_definition_" . $this->model->getId() . ".psf"); }
/** * Fired before information is sent back to the admin UI about an element * @param \Zend_EventManager_Event $e * @throws \Exception */ public static function adminElementGetPreSendData($e) { $element = self::extractElementFromEvent($e); $returnValueContainer = $e->getParam('returnValueContainer'); $data = $returnValueContainer->getData(); //create a new namespace for WorkflowManagement //set some defaults $data['workflowManagement'] = ['hasWorkflowManagement' => false]; if (Workflow\Manager::elementCanAction($element)) { $data['workflowManagement']['hasWorkflowManagement'] = true; //see if we can change the layout $currentUser = Admin::getCurrentUser(); $manager = Workflow\Manager\Factory::getManager($element, $currentUser); $data['workflowManagement']['workflowName'] = $manager->getWorkflow()->getName(); //get the state and status $state = $manager->getElementState(); $data['workflowManagement']['state'] = $manager->getWorkflow()->getStateConfig($state); $status = $manager->getElementStatus(); $data['workflowManagement']['status'] = $manager->getWorkflow()->getStatusConfig($status); if ($element instanceof ConcreteObject) { $workflowLayoutId = $manager->getObjectLayout(); //check for !is_null here as we might want to specify 0 in the workflow config if (!is_null($workflowLayoutId)) { //load the new layout into the object container $validLayouts = Object\Service::getValidLayouts($element); //check that the layout id is valid before trying to load if (!empty($validLayouts)) { //todo check user permissions again if ($validLayouts && $validLayouts[$workflowLayoutId]) { $customLayout = ClassDefinition\CustomLayout::getById($workflowLayoutId); $customLayoutDefinition = $customLayout->getLayoutDefinitions(); Object\Service::enrichLayoutDefinition($customLayoutDefinition, $e->getParam('object')); $data["layout"] = $customLayoutDefinition; } } } } } $returnValueContainer->setData($data); }
/** * See http://www.pimcore.org/issues/browse/PIMCORE-2358 * Add option to export/import all class definitions/brick definitions etc. at once */ public function bulkCommitAction() { $filename = $this->getParam("filename"); $data = json_decode($this->getParam("data"), true); $json = @file_get_contents($filename); $json = json_decode($json, true); $type = $data["type"]; $name = $data["name"]; $list = $json[$type]; foreach ($list as $item) { unset($item["creationDate"]); unset($item["modificationDate"]); unset($item["userOwner"]); unset($item["userModification"]); unset($item["id"]); if ($type == "class" && $item["name"] == $name) { $class = Object\ClassDefinition::getByName($name); if (!$class) { $class = new Object\ClassDefinition(); $class->setName($name); } $success = Object\ClassDefinition\Service::importClassDefinitionFromJson($class, json_encode($item), true); $this->_helper->json(["success" => $success !== false]); } elseif ($type == "objectbrick" && $item["key"] == $name) { try { $brick = Object\Objectbrick\Definition::getByKey($name); } catch (\Exception $e) { $brick = new Object\Objectbrick\Definition(); $brick->setKey($name); } $success = Object\ClassDefinition\Service::importObjectBrickFromJson($brick, json_encode($item), true); $this->_helper->json(["success" => $success !== false]); } elseif ($type == "fieldcollection" && $item["key"] == $name) { try { $fieldCollection = Object\Fieldcollection\Definition::getByKey($name); } catch (\Exception $e) { $fieldCollection = new Object\Fieldcollection\Definition(); $fieldCollection->setKey($name); } $success = Object\ClassDefinition\Service::importFieldCollectionFromJson($fieldCollection, json_encode($item), true); $this->_helper->json(["success" => $success !== false]); } elseif ($type == "customlayout") { $layoutData = unserialize($data["name"]); $className = $layoutData["className"]; $layoutName = $layoutData["name"]; if ($item["name"] == $layoutName && $item["className"] == $className) { $class = Object\ClassDefinition::getByName($className); if (!$class) { throw new \Exception("Class does not exist"); } $classId = $class->getId(); $layoutList = new Object\ClassDefinition\CustomLayout\Listing(); $db = \Pimcore\Db::get(); $layoutList->setCondition("name = " . $db->quote($layoutName) . " AND classId = " . $classId); $layoutList = $layoutList->load(); $layoutDefinition = null; if ($layoutList) { $layoutDefinition = $layoutList[0]; } if (!$layoutDefinition) { $layoutDefinition = new Object\ClassDefinition\CustomLayout(); $layoutDefinition->setName($layoutName); $layoutDefinition->setClassId($classId); } try { $layoutDefinition->setDescription($item["description"]); $layoutDef = Object\ClassDefinition\Service::generateLayoutTreeFromArray($item["layoutDefinitions"], true); $layoutDefinition->setLayoutDefinitions($layoutDef); $layoutDefinition->save(); } catch (\Exception $e) { Logger::error($e->getMessage()); $this->_helper->json(["success" => false, "message" => $e->getMessage()]); } } } } $this->_helper->json(["success" => true]); }