getById() public static méthode

public static getById ( $id ) : mixed | null | ClassDefinition
$id
Résultat mixed | null | ClassDefinition
Exemple #1
0
 /**
  * Loads a list of object-classes for the specicifies parameters, returns an array of Object|Class elements
  *
  * @return array
  */
 public function load()
 {
     $classes = array();
     $classesRaw = $this->db->fetchCol("SELECT id FROM classes" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
     foreach ($classesRaw as $classRaw) {
         $classes[] = Object\ClassDefinition::getById($classRaw);
     }
     $this->model->setClasses($classes);
     return $classes;
 }
 /**
  * @todo refactor steps into proper methods instead of doing it all in the action
  * @throws Exception
  */
 public function indexAction()
 {
     // reachable via http://your.domain/plugin/Prototyper/admin/index
     $this->view->previewData = null;
     $this->view->csvText = $this->getParam('csv');
     $this->view->classname = $this->getParam('classname');
     $csvData = array();
     $rowNr = 0;
     $rows = str_getcsv($this->view->csvText, "\n");
     //parse the rows
     foreach ($rows as $row) {
         $rowNr++;
         $rowData = str_getcsv($row, ";");
         $csvData[] = $rowData;
         if ($rowNr == 1) {
             $fieldNames = array();
             $fieldTitles = array();
             foreach ($rowData as $cell) {
                 $fieldTitles[] = $cell;
                 $fieldNames[] = $this->getFieldName($cell);
             }
             $csvData[] = $fieldNames;
         }
         if ($rowNr > 10) {
             break;
         }
     }
     $this->view->previewTable = $csvData;
     $fieldList = array();
     foreach ($fieldNames as $fieldName) {
         $fieldTitle = array_shift($fieldTitles);
         ob_start();
         include __DIR__ . "/../classes/field.json.php";
         $fieldList[] = ob_get_clean();
     }
     $fields = implode(',', $fieldList);
     ob_start();
     include __DIR__ . "/../classes/object.json.php";
     $jsonText = ob_get_clean();
     if ($this->getParam('generate') != '') {
         $class = Object\ClassDefinition::getByName($this->correctClassname($this->getParam("classname")));
         if ($class == null) {
             $class = Object\ClassDefinition::create(array('name' => $this->correctClassname($this->getParam("classname")), 'userOwner' => $this->user->getId()));
             $class->save();
         }
         $class = Object\ClassDefinition::getById($class->getId());
         $success = Object\ClassDefinition\Service::importClassDefinitionFromJson($class, $jsonText);
         if ($success) {
             $this->view->successMessage = '<strong>Class generation successful.</strong>';
         }
     }
 }
Exemple #3
0
 /**
  * @param $e
  * @return array
  * @throws
  * @throws \Exception
  */
 protected function exceptionHandler($e)
 {
     // create view if it doesn't exist already // HACK
     $pdoMySQL = preg_match("/Base table or view not found/", $e->getMessage());
     $Mysqli = preg_match("/Table (.*) doesn't exist/", $e->getMessage());
     if (($Mysqli || $pdoMySQL) && $this->firstException) {
         $this->firstException = false;
         $localizedFields = new Object\Localizedfield();
         $localizedFields->setClass(Object\ClassDefinition::getById($this->model->getClassId()));
         $localizedFields->createUpdateTable();
         return $this->load();
     }
     throw $e;
 }
Exemple #4
0
 /**
  * @param null $classId
  * @throws \Exception
  */
 public function __construct($classId = null)
 {
     $class = null;
     if (is_string($classId)) {
         $class = Object\ClassDefinition::getByName($classId);
     } elseif (is_int($classId)) {
         $class = Object\ClassDefinition::getById($classId);
     } elseif ($classId !== null) {
         throw new \Exception("No valid class identifier given (class name or ID)");
     }
     if ($class instanceof Object\ClassDefinition) {
         $this->setClass($class);
     }
 }
Exemple #5
0
 /**
  * @return Object\ClassDefinition
  */
 public function getClass()
 {
     $class = Object\ClassDefinition::getById($this->getClassId());
     return $class;
 }
 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 enrichLayoutDefinition($object)
 {
     $classId = $this->allowedClassId;
     $class = Object\ClassDefinition::getById($classId);
     if (!$classId) {
         return;
     }
     if (!$this->visibleFields) {
         return;
     }
     $this->visibleFieldDefinitions = array();
     $t = \Zend_Registry::get("Zend_Translate");
     $visibleFields = explode(',', $this->visibleFields);
     foreach ($visibleFields as $field) {
         $fd = $class->getFieldDefinition($field);
         if (!$fd) {
             $fieldFound = false;
             if ($localizedfields = $class->getFieldDefinitions()['localizedfields']) {
                 if ($fd = $localizedfields->getFieldDefinition($field)) {
                     $this->visibleFieldDefinitions[$field]["name"] = $fd->getName();
                     $this->visibleFieldDefinitions[$field]["title"] = $fd->getTitle();
                     $this->visibleFieldDefinitions[$field]["fieldtype"] = $fd->getFieldType();
                     if ($fd instanceof Object\ClassDefinition\Data\Select) {
                         $this->visibleFieldDefinitions[$field]["options"] = $fd->getOptions();
                     }
                     $fieldFound = true;
                 }
             }
             if (!$fieldFound) {
                 $this->visibleFieldDefinitions[$field]["name"] = $field;
                 $this->visibleFieldDefinitions[$field]["title"] = $t->translate($field);
                 $this->visibleFieldDefinitions[$field]["fieldtype"] = "input";
             }
         } else {
             $this->visibleFieldDefinitions[$field]["name"] = $fd->getName();
             $this->visibleFieldDefinitions[$field]["title"] = $fd->getTitle();
             $this->visibleFieldDefinitions[$field]["fieldtype"] = $fd->getFieldType();
             $this->visibleFieldDefinitions[$field]["noteditable"] = true;
             if ($fd instanceof Object\ClassDefinition\Data\Select) {
                 $this->visibleFieldDefinitions[$field]["options"] = $fd->getOptions();
             }
         }
     }
 }
Exemple #8
0
 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;
 }
 public function getBatchJobsAction()
 {
     if ($this->getParam("language")) {
         $this->setLanguage($this->getParam("language"), true);
     }
     $folder = Object::getById($this->getParam("folderId"));
     $class = Object\ClassDefinition::getById($this->getParam("classId"));
     $conditionFilters = array("o_path = ? OR o_path LIKE '" . str_replace("//", "/", $folder->getFullPath() . "/") . "%'");
     if ($this->getParam("filter")) {
         $conditionFilters[] = Object\Service::getFilterCondition($this->getParam("filter"), $class);
     }
     if ($this->getParam("condition")) {
         $conditionFilters[] = " (" . $this->getParam("condition") . ")";
     }
     $className = $class->getName();
     $listClass = "\\Pimcore\\Model\\Object\\" . ucfirst($className) . "\\Listing";
     $list = new $listClass();
     $list->setCondition(implode(" AND ", $conditionFilters), array($folder->getFullPath()));
     $list->setOrder("ASC");
     $list->setOrderKey("o_id");
     if ($this->getParam("objecttype")) {
         $list->setObjectTypes(array($this->getParam("objecttype")));
     }
     $jobs = $list->loadIdList();
     $this->_helper->json(array("success" => true, "jobs" => $jobs));
 }
Exemple #10
0
 public function getClasses()
 {
     if ($this->getChildAmount()) {
         $path = $this->model->getFullPath();
         if (!$this->model->getId() || $this->model->getId() == 1) {
             $path = "";
         }
         $classIds = $this->db->fetchCol("SELECT o_classId FROM objects WHERE o_path LIKE ? AND o_type = 'object' GROUP BY o_classId", $path . "/%");
         $classes = array();
         foreach ($classIds as $classId) {
             $classes[] = Object\ClassDefinition::getById($classId);
         }
         return $classes;
     } else {
         return array();
     }
 }
 /**
  * @param $objectBrick
  * @return string
  */
 public static function generateObjectBrickJson($objectBrick)
 {
     unset($objectBrick->key);
     unset($objectBrick->fieldDefinitions);
     // set classname attribute to the real class name not to the class ID
     // this will allow to import the brick on a different instance with identical class names but different class IDs
     if (is_array($objectBrick->classDefinitions)) {
         foreach ($objectBrick->classDefinitions as &$cd) {
             $class = Object\ClassDefinition::getById($cd["classname"]);
             if ($class) {
                 $cd["classname"] = $class->getName();
             }
         }
     }
     $json = \Zend_Json::encode($objectBrick);
     $json = \Zend_Json::prettyPrint($json);
     return $json;
 }
Exemple #12
0
 /**
  * @return void
  */
 public function delete()
 {
     @unlink($this->getDefinitionFile());
     @unlink($this->getPhpClassFile());
     $processedClasses = [];
     if (!empty($this->classDefinitions)) {
         foreach ($this->classDefinitions as $cl) {
             unset($this->oldClassDefinitions[$cl['classname']]);
             if (!$processedClasses[$cl['classname']]) {
                 $class = Object\ClassDefinition::getById($cl['classname']);
                 $this->getDao()->delete($class);
                 $processedClasses[$cl['classname']] = true;
                 foreach ($class->getFieldDefinitions() as $fieldDef) {
                     if ($fieldDef instanceof Object\ClassDefinition\Data\Objectbricks) {
                         $allowedTypes = $fieldDef->getAllowedTypes();
                         $idx = array_search($this->getKey(), $allowedTypes);
                         if ($idx !== false) {
                             array_splice($allowedTypes, $idx, 1);
                         }
                         $fieldDef->setAllowedTypes($allowedTypes);
                     }
                 }
                 $class->save();
             }
         }
     }
     // update classes
     $classList = new Object\ClassDefinition\Listing();
     $classes = $classList->load();
     if (is_array($classes)) {
         foreach ($classes as $class) {
             foreach ($class->getFieldDefinitions() as $fieldDef) {
                 if ($fieldDef instanceof Object\ClassDefinition\Data\Objectbricks) {
                     if (in_array($this->getKey(), $fieldDef->getAllowedTypes())) {
                         break;
                     }
                 }
             }
         }
     }
 }
Exemple #13
0
 /**
  * @return void
  */
 public function delete()
 {
     $fieldCollectionFolder = PIMCORE_CLASS_DIRECTORY . "/objectbricks";
     $fieldFile = $fieldCollectionFolder . "/" . $this->getKey() . ".psf";
     @unlink($fieldFile);
     $fieldClassFolder = PIMCORE_CLASS_DIRECTORY . "/Object/Objectbrick/Data";
     $fieldClass = $fieldClassFolder . "/" . ucfirst($this->getKey()) . ".php";
     @unlink($fieldClass);
     $processedClasses = array();
     if (!empty($this->classDefinitions)) {
         foreach ($this->classDefinitions as $cl) {
             unset($this->oldClassDefinitions[$cl['classname']]);
             if (!$processedClasses[$cl['classname']]) {
                 $class = Object\ClassDefinition::getById($cl['classname']);
                 $this->getDao()->delete($class);
                 $processedClasses[$cl['classname']] = true;
                 foreach ($class->getFieldDefinitions() as $fieldDef) {
                     if ($fieldDef instanceof Object\ClassDefinition\Data\Objectbricks) {
                         $allowedTypes = $fieldDef->getAllowedTypes();
                         $idx = array_search($this->getKey(), $allowedTypes);
                         if ($idx !== false) {
                             array_splice($allowedTypes, $idx, 1);
                         }
                         $fieldDef->setAllowedTypes($allowedTypes);
                     }
                 }
                 $class->save();
             }
         }
     }
     // update classes
     $classList = new Object\ClassDefinition\Listing();
     $classes = $classList->load();
     if (is_array($classes)) {
         foreach ($classes as $class) {
             foreach ($class->getFieldDefinitions() as $fieldDef) {
                 if ($fieldDef instanceof Object\ClassDefinition\Data\Objectbricks) {
                     if (in_array($this->getKey(), $fieldDef->getAllowedTypes())) {
                         break;
                     }
                 }
             }
         }
     }
 }
 /**
  * @return string
  */
 public function getOwnerClassName()
 {
     //fallback for legacy data
     if (empty($this->ownerClassName)) {
         try {
             $class = Object\ClassDefinition::getById($this->ownerClassId);
             $this->ownerClassName = $class->getName();
         } catch (\Exception $e) {
             \Logger::error($e->getMessage());
         }
     }
     return $this->ownerClassName;
 }
Exemple #15
0
 /**
  * @param $name
  * @param $value
  * @param null $language
  * @return void
  */
 public function setLocalizedValue($name, $value, $language = null)
 {
     if (self::$strictMode) {
         if (!$language || !in_array($language, Tool::getValidLanguages())) {
             throw new \Exception("Language " . $language . " not accepted in strict mode");
         }
     }
     $language = $this->getLanguage($language);
     if (!$this->languageExists($language)) {
         $this->items[$language] = [];
     }
     $contextInfo = $this->getContext();
     if ($contextInfo && $contextInfo["containerType"] == "block") {
         $classId = $contextInfo["classId"];
         $containerDefinition = ClassDefinition::getById($classId);
         $blockDefinition = $containerDefinition->getFieldDefinition($contextInfo["fieldname"]);
         $fieldDefinition = $blockDefinition->getFieldDefinition("localizedfields");
     } else {
         if ($contextInfo && $contextInfo["containerType"] == "fieldcollection") {
             $containerKey = $contextInfo["containerKey"];
             $containerDefinition = Fieldcollection\Definition::getByKey($containerKey);
         } else {
             $containerDefinition = $this->getObject()->getClass();
         }
         $localizedFieldDefinition = $containerDefinition->getFieldDefinition("localizedfields");
         $fieldDefinition = $localizedFieldDefinition->getFieldDefinition($name);
     }
     if (method_exists($fieldDefinition, "preSetData")) {
         $value = $fieldDefinition->preSetData($this, $value, ["language" => $language, "name" => $name]);
     }
     $this->items[$language][$name] = $value;
     return $this;
 }
Exemple #16
0
 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()]);
     }
 }
Exemple #17
0
 /**
  * @param $objectBrick
  * @param $json
  * @return bool
  */
 public static function importObjectBrickFromJson($objectBrick, $json, $throwException = false)
 {
     $importData = \Zend_Json::decode($json);
     // reverse map the class name to the class ID, see: self::generateObjectBrickJson()
     $toAssignClassDefinitions = [];
     if (is_array($importData["classDefinitions"])) {
         foreach ($importData["classDefinitions"] as &$cd) {
             if (is_numeric($cd["classname"])) {
                 $class = Object\ClassDefinition::getById($cd["classname"]);
                 if ($class) {
                     $toAssignClassDefinitions[] = $cd;
                 }
             } else {
                 $class = Object\ClassDefinition::getByName($cd["classname"]);
                 if ($class) {
                     $cd["classname"] = $class->getId();
                     $toAssignClassDefinitions[] = $cd;
                 }
             }
         }
     }
     $layout = self::generateLayoutTreeFromArray($importData["layoutDefinitions"], $throwException);
     $objectBrick->setLayoutDefinitions($layout);
     $objectBrick->setClassDefinitions($toAssignClassDefinitions);
     $objectBrick->setParentClass($importData["parentClass"]);
     $objectBrick->save();
     return true;
 }
Exemple #18
0
 /**
  * See http://www.pimcore.org/issues/browse/PIMCORE-2358
  * Add option to export/import all class definitions/brick definitions etc. at once
  */
 public function bulkExportAction()
 {
     $result = [];
     $this->removeViewRenderer();
     $fieldCollections = new Object\Fieldcollection\Definition\Listing();
     $fieldCollections = $fieldCollections->load();
     foreach ($fieldCollections as $fieldCollection) {
         $key = $fieldCollection->key;
         $fieldCollectionJson = json_decode(Object\ClassDefinition\Service::generateFieldCollectionJson($fieldCollection));
         $fieldCollectionJson->key = $key;
         $result["fieldcollection"][] = $fieldCollectionJson;
     }
     $classes = new Object\ClassDefinition\Listing();
     $classes->setOrder("ASC");
     $classes->setOrderKey("id");
     $classes = $classes->load();
     foreach ($classes as $class) {
         $data = Model\Webservice\Data\Mapper::map($class, "\\Pimcore\\Model\\Webservice\\Data\\ClassDefinition\\Out", "out");
         unset($data->fieldDefinitions);
         $result["class"][] = $data;
     }
     $objectBricks = new Object\Objectbrick\Definition\Listing();
     $objectBricks = $objectBricks->load();
     foreach ($objectBricks as $objectBrick) {
         $key = $objectBrick->key;
         $objectBrickJson = json_decode(Object\ClassDefinition\Service::generateObjectBrickJson($objectBrick));
         $objectBrickJson->key = $key;
         $result["objectbrick"][] = $objectBrickJson;
     }
     $customLayouts = new Object\ClassDefinition\CustomLayout\Listing();
     $customLayouts = $customLayouts->load();
     foreach ($customLayouts as $customLayout) {
         /** @var  $customLayout Object\ClassDefinition\CustomLayout */
         $classId = $customLayout->getClassId();
         $class = Object\ClassDefinition::getById($classId);
         $customLayout->className = $class->getName();
         $result["customlayout"][] = $customLayout;
     }
     header("Content-type: application/json");
     header("Content-Disposition: attachment; filename=\"bulk_export.json\"");
     $result = json_encode($result);
     echo $result;
 }
Exemple #19
0
 /**
  * @param $id
  * @throws \Exception
  */
 public function getClassById($id)
 {
     try {
         $class = Object\ClassDefinition::getById($id);
         if ($class instanceof Object\ClassDefinition) {
             $apiClass = Webservice\Data\Mapper::map($class, "\\Pimcore\\Model\\Webservice\\Data\\ClassDefinition\\Out", "out");
             unset($apiClass->fieldDefinitions);
             return $apiClass;
         }
         throw new \Exception("Class with given ID (" . $id . ") does not exist.");
     } catch (\Exception $e) {
         \Logger::error($e);
         throw $e;
     }
 }
Exemple #20
0
 /**
  * @return ClassDefinition
  */
 public function getClass()
 {
     if (!$this->o_class) {
         $this->setClass(ClassDefinition::getById($this->getClassId()));
     }
     return $this->o_class;
 }