public static getFieldDefinitionFromJson ( $definition, $type ) : |
||
$definition | ||
$type | ||
Résultat |
if ($definition->isLocalized()) { $languages = array_merge($languages, \Pimcore\Tool::getValidLanguages()); } foreach ($activeGroups as $activeGroupId => $enabled) { if (!$enabled) { continue; } /** @var $groupDefinition Object\Classificationstore\GroupConfig */ $groupDefinition = Pimcore\Model\Object\Classificationstore\GroupConfig::getById($activeGroupId); if (!$groupDefinition) { continue; } /** @var $keyGroupRelation Object\Classificationstore\KeyGroupRelation */ $keyGroupRelations = $groupDefinition->getRelations(); foreach ($keyGroupRelations as $keyGroupRelation) { $keyDef = Object\Classificationstore\Service::getFieldDefinitionFromJson(json_decode($keyGroupRelation->getDefinition()), $keyGroupRelation->getType()); if (!$keyDef) { continue; } foreach ($languages as $language) { $keyData = $storedata->getLocalizedKeyValue($activeGroupId, $keyGroupRelation->getKeyId(), $language, true, true); $preview = $keyDef->getVersionPreview($keyData); ?> <tr<?php if ($c % 2) { ?> class="odd"<?php } ?> >
/** * Checks if data is valid for current data field * * @param mixed $data * @param boolean $omitMandatoryCheck * @throws \Exception */ public function checkValidity($data, $omitMandatoryCheck = false) { $activeGroups = $data->getActiveGroups(); if (!$activeGroups) { return; } $items = $data->getItems(); $validLanguages = $this->getValidLanguages(); $errors = []; if (!$omitMandatoryCheck) { foreach ($activeGroups as $activeGroupId => $enabled) { if ($enabled) { $groupDefinition = Object\Classificationstore\GroupConfig::getById($activeGroupId); if (!$groupDefinition) { continue; } /** @var $keyGroupRelation Object\Classificationstore\KeyGroupRelation */ $keyGroupRelations = $groupDefinition->getRelations(); foreach ($keyGroupRelations as $keyGroupRelation) { foreach ($validLanguages as $validLanguage) { $keyId = $keyGroupRelation->getKeyId(); $value = $items[$activeGroupId][$keyId][$validLanguage]; $keyDef = Object\Classificationstore\Service::getFieldDefinitionFromJson(json_decode($keyGroupRelation->getDefinition()), $keyGroupRelation->getType()); if ($keyGroupRelation->isMandatory()) { $keyDef->setMandatory(1); } try { $keyDef->checkValidity($value); } catch (\Exception $e) { $errors[] = $e; } } } } } } if ($errors) { $messages = []; foreach ($errors as $e) { $messages[] = $e->getMessage() . " (" . $validLanguage . ")"; } $validationException = new Model\Element\ValidationException(implode(", ", $messages)); $validationException->setSubItems($errors); throw $validationException; } }
/** * * @param string $filterJson * @param ClassDefinition $class * @return string */ public static function getFeatureFilters($filterJson, $class) { $joins = []; $conditions = []; // create filter condition $conditionPartsFilters = []; if ($filterJson) { $db = \Pimcore\Db::get(); $filters = \Zend_Json::decode($filterJson); foreach ($filters as $filter) { $operator = "="; $filterField = $filter["property"]; $filterOperator = $filter["operator"]; if ($filter["type"] == "string") { $operator = "LIKE"; } elseif ($filter["type"] == "numeric") { if ($filterOperator == "lt") { $operator = "<"; } elseif ($filterOperator == "gt") { $operator = ">"; } elseif ($filterOperator == "eq") { $operator = "="; } } elseif ($filter["type"] == "date") { if ($filterOperator == "lt") { $operator = "<"; } elseif ($filterOperator == "gt") { $operator = ">"; } elseif ($filterOperator == "eq") { $operator = "="; } $filter["value"] = strtotime($filter["value"]); } elseif ($filter["type"] == "list") { $operator = "="; } elseif ($filter["type"] == "boolean") { $operator = "="; $filter["value"] = (int) $filter["value"]; } $keyParts = explode("~", $filterField); if (substr($filterField, 0, 1) != "~") { continue; } $type = $keyParts[1]; if ($type != "classificationstore") { continue; } $fieldName = $keyParts[2]; $groupKeyId = explode("-", $keyParts[3]); $groupId = $groupKeyId[0]; $keyid = $groupKeyId[1]; $keyConfig = Model\Object\Classificationstore\KeyConfig::getById($keyid); $type = $keyConfig->getType(); $definition = json_decode($keyConfig->getDefinition()); $field = \Pimcore\Model\Object\Classificationstore\Service::getFieldDefinitionFromJson($definition, $type); if ($field instanceof ClassDefinition\Data) { $mappedKey = "cskey_" . $fieldName . "_" . $groupId . "_" . $keyid; $joins[] = ['fieldname' => $fieldName, 'groupId' => $groupId, "keyId" => $keyid]; $condition = $field->getFilterConditionExt($filter["value"], $operator, ["name" => $mappedKey]); $conditions[$mappedKey] = $condition; } } } $result = ["joins" => $joins, "conditions" => $conditions]; return $result; }
public function addGroupsAction() { $ids = \Zend_Json::decode($this->getParam("groupIds")); $keyCondition = "groupId in (" . implode(",", $ids) . ")"; $keyList = new Classificationstore\KeyGroupRelation\Listing(); $keyList->setCondition($keyCondition); $keyList->setOrderKey(array("sorter", "id")); $keyList->setOrder(array("ASC", "ASC")); $keyList = $keyList->load(); $groupCondition = "id in (" . implode(",", $ids) . ")"; $groupList = new Classificationstore\GroupConfig\Listing(); $groupList->setCondition($groupCondition); $groupList->setOrder("ASC"); $groupList->setOrderKey("id"); $groupList = $groupList->load(); $data = array(); foreach ($groupList as $groupData) { $data[$groupData->getId()] = array("name" => $groupData->getName(), "id" => $groupData->getId(), "description" => $groupData->getDescription(), "keys" => array()); } foreach ($keyList as $keyData) { $groupId = $keyData->getGroupId(); $keyList = $data[$groupId]["keys"]; $type = $keyData->getType(); $definition = json_decode($keyData->getDefinition()); $definition = \Pimcore\Model\Object\Classificationstore\Service::getFieldDefinitionFromJson($definition, $type); if (method_exists($definition, "__wakeup")) { $definition->__wakeup(); } $keyList[] = array("name" => $keyData->getName(), "id" => $keyData->getKeyId(), "description" => $keyData->getDescription(), "definition" => $definition); $data[$groupId]["keys"] = $keyList; } return $this->_helper->json($data); }
protected function getCsvFieldData($field, $object, $requestedLanguage) { //check if field is systemfield $systemFieldMap = ['id' => "getId", 'fullpath' => "getRealFullPath", 'published' => "getPublished", 'creationDate' => "getCreationDate", 'modificationDate' => "getModificationDate", 'filename' => "getKey", 'classname' => "getClassname"]; if (in_array($field, array_keys($systemFieldMap))) { return $object->{$systemFieldMap[$field]}(); } else { //check if field is standard object field $fieldDefinition = $object->getClass()->getFieldDefinition($field); if ($fieldDefinition) { return $fieldDefinition->getForCsvExport($object); } else { $fieldParts = explode("~", $field); // check for objects bricks and localized fields if (substr($field, 0, 1) == "~") { $type = $fieldParts[1]; if ($type == "classificationstore") { $fieldname = $fieldParts[2]; $groupKeyId = explode("-", $fieldParts[3]); $groupId = $groupKeyId[0]; $keyId = $groupKeyId[1]; $getter = "get" . ucfirst($fieldname); if (method_exists($object, $getter)) { /** @var $classificationStoreData Classificationstore */ $keyConfig = Pimcore\Model\Object\Classificationstore\KeyConfig::getById($keyId); $type = $keyConfig->getType(); $definition = json_decode($keyConfig->getDefinition()); $fieldDefinition = \Pimcore\Model\Object\Classificationstore\Service::getFieldDefinitionFromJson($definition, $type); return $fieldDefinition->getForCsvExport($object, ["context" => ["containerType" => "classificationstore", "fieldname" => $fieldname, "groupId" => $groupId, "keyId" => $keyId, "language" => $requestedLanguage]]); } } //key value store - ignore for now } elseif (count($fieldParts) > 1) { // brick $brickType = $fieldParts[0]; $brickKey = $fieldParts[1]; $key = Object\Service::getFieldForBrickType($object->getClass(), $brickType); $brickClass = Pimcore\Model\Object\Objectbrick\Definition::getByKey($brickType); $fieldDefinition = $brickClass->getFieldDefinition($brickKey); if ($fieldDefinition) { $brickContainer = $object->{"get" . ucfirst($key)}(); if ($brickContainer && !empty($brickKey)) { $brick = $brickContainer->{"get" . ucfirst($brickType)}(); if ($brick) { return $fieldDefinition->getForCsvExport($brick); } } } } elseif ($locFields = $object->getClass()->getFieldDefinition("localizedfields")) { // if the definition is not set try to get the definition from localized fields $fieldDefinition = $locFields->getFieldDefinition($field); if ($fieldDefinition) { $needLocalizedPermissions = true; return $fieldDefinition->getForCsvExport($object->getLocalizedFields(), ["language" => $this->getParam("language")]); } } } } }