Inheritance: extends Pimcore\Model\Listing\AbstractListing
Beispiel #1
0
 /**
  * @return void
  */
 public function delete()
 {
     // delete all objects using this class
     $list = new Listing();
     $list->setCondition("o_classId = ?", $this->getId());
     $list->load();
     foreach ($list->getObjects() as $o) {
         $o->delete();
     }
     $this->deletePhpClasses();
     // empty object cache
     try {
         Cache::clearTag("class_" . $this->getId());
     } catch (\Exception $e) {
     }
     // empty output cache
     try {
         Cache::clearTag("output");
     } catch (\Exception $e) {
     }
     $customLayouts = new ClassDefinition\CustomLayout\Listing();
     $customLayouts->setCondition("classId = " . $this->getId());
     $customLayouts = $customLayouts->load();
     foreach ($customLayouts as $customLayout) {
         $customLayout->delete();
     }
     $this->getDao()->delete();
 }
Beispiel #2
0
 /**
  * @param Concrete $object
  * @return array
  */
 public static function getValidLayouts(Concrete $object)
 {
     $user = AdminTool::getCurrentUser();
     $resultList = array();
     $isMasterAllowed = $user->getAdmin();
     $permissionSet = $object->getPermissions("layouts", $user);
     $layoutPermissions = self::getLayoutPermissions($object->getClassId(), $permissionSet);
     if (!$layoutPermissions || isset($layoutPermissions[0])) {
         $isMasterAllowed = true;
     }
     if ($user->getAdmin()) {
         $superLayout = new ClassDefinition\CustomLayout();
         $superLayout->setId(-1);
         $superLayout->setName("Master (Admin Mode)");
         $resultList[-1] = $superLayout;
     }
     if ($isMasterAllowed) {
         $master = new ClassDefinition\CustomLayout();
         $master->setId(0);
         $master->setName("Master");
         $resultList[0] = $master;
     }
     $classId = $object->getClassId();
     $list = new ClassDefinition\CustomLayout\Listing();
     $list->setOrderKey("name");
     $condition = "classId = " . $list->quote($classId);
     if (count($layoutPermissions) && !$isMasterAllowed) {
         $layoutIds = array_values($layoutPermissions);
         $condition .= " AND id IN (" . implode(",", $layoutIds) . ")";
     }
     $list->setCondition($condition);
     $list = $list->load();
     if (!count($resultList) && !count($list) || count($resultList) == 1 && !count($list)) {
         return array();
     }
     foreach ($list as $customLayout) {
         $resultList[$customLayout->getId()] = $customLayout;
     }
     return $resultList;
 }
Beispiel #3
-1
 /**
  * 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]);
 }