public function enrichLayoutDefinition($object) { $groupCollectionMapping = $this->recursiveGetActiveGroupCollectionMapping($object); $this->activeGroupDefinitions = []; $activeGroupIds = $this->recursiveGetActiveGroupsIds($object); if (!$activeGroupIds) { return; } $filteredGroupIds = []; foreach ($activeGroupIds as $groupId => $enabled) { if ($enabled) { $filteredGroupIds[] = $groupId; } } $condition = "ID in (" . implode(',', $filteredGroupIds) . ")"; $groupList = new Object\Classificationstore\GroupConfig\Listing(); $groupList->setCondition($condition); $groupList->setOrder(["ASC", "ASC"]); $groupList = $groupList->load(); /** @var $group Object\Classificationstore\GroupConfig */ foreach ($groupList as $group) { $keyList = []; $relation = new Object\Classificationstore\KeyGroupRelation\Listing(); $relation->setCondition("groupId = " . $relation->quote($group->getId())); $relation->setOrderKey(["sorter", "id"]); $relation->setOrder(["ASC", "ASC"]); $relation = $relation->load(); /** @var $key Object\Classificationstore\KeyGroupRelation */ foreach ($relation as $key) { $definition = \Pimcore\Model\Object\Classificationstore\Service::getFieldDefinitionFromKeyConfig($key); if (method_exists($definition, "__wakeup")) { $definition->__wakeup(); } if ($definition) { $definition->setMandatory($definition->getMandatory() || $key->isMandatory()); } $keyList[] = ["name" => $key->getName(), "id" => $key->getKeyId(), "description" => $key->getDescription(), "definition" => $definition]; } $this->activeGroupDefinitions[$group->getId()] = ["name" => $group->getName(), "id" => $group->getId(), "description" => $group->getDescription(), "keys" => $keyList]; } if ($groupCollectionMapping) { $collectionIds = array_values($groupCollectionMapping); $relation = new Object\Classificationstore\CollectionGroupRelation\Listing(); $condition = "colId IN (" . implode(",", $collectionIds) . ")"; $relation->setCondition($condition); $relation = $relation->load(); $sorting = []; /** @var $item Object\Classificationstore\CollectionGroupRelation */ foreach ($relation as $item) { $sorting[$item->getGroupId()] = $item->getSorter(); } usort($this->activeGroupDefinitions, function ($a, $b) use($sorting) { $s1 = $sorting[$a["id"]] ? $sorting[$a["id"]] : 0; $s2 = $sorting[$b["id"]] ? $sorting[$b["id"]] : 0; if ($s1 < $s2) { return 1; } elseif ($s2 > $s1) { return -1; } else { return 0; } }); } }
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 } ?> >
/** * */ public function load() { /** @var $classificationStore Object\Classificationstore */ $classificationStore = $this->model; $object = $this->model->getObject(); $dataTableName = $this->getDataTableName(); $objectId = $object->getId(); $fieldname = $this->model->getFieldname(); $query = "SELECT * FROM " . $dataTableName . " WHERE o_id = " . $this->db->quote($objectId) . " AND fieldname = " . $this->db->quote($fieldname); $data = $this->db->fetchAll($query); $groupCollectionMapping = array(); foreach ($data as $item) { $groupId = $item["groupId"]; $keyId = $item["keyId"]; $collectionId = $item["collectionId"]; $groupCollectionMapping[$groupId] = $collectionId; $value = $item["value"]; $keyConfig = DefinitionCache::get($keyId); $fd = Service::getFieldDefinitionFromKeyConfig($keyConfig); $value = $fd->getDataFromResource($value); $language = $item["language"]; $classificationStore->setLocalizedKeyValue($groupId, $keyId, $value, $language); } $groupsTableName = $this->getGroupsTableName(); $query = "SELECT * FROM " . $groupsTableName . " WHERE o_id = " . $this->db->quote($objectId) . " AND fieldname = " . $this->db->quote($fieldname); $data = $this->db->fetchAll($query); $list = array(); foreach ($data as $item) { $list[$item["groupId"]] = true; } $classificationStore->setActiveGroups($list); $classificationStore->setGroupCollectionMappings($groupCollectionMapping); }
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); }
public function enrichLayoutDefinition($object) { $this->activeGroupDefinitions = array(); $activeGroupIds = $this->recursiveGetActiveGroupsIds($object); if (!$activeGroupIds) { return; } $filteredGroupIds = array(); foreach ($activeGroupIds as $groupId => $enabled) { if ($enabled) { $filteredGroupIds[] = $groupId; } } $condition = "ID in (" . implode(',', $filteredGroupIds) . ")"; $groupList = new Object\Classificationstore\GroupConfig\Listing(); $groupList->setCondition($condition); $groupList->setOrderKey(array("sorter", "id")); $groupList->setOrder(array("ASC", "ASC")); $groupList = $groupList->load(); /** @var $group Object\Classificationstore\GroupConfig */ foreach ($groupList as $group) { $keyList = array(); $relation = new Object\Classificationstore\KeyGroupRelation\Listing(); $relation->setCondition("groupId = " . $relation->quote($group->getId())); $relation->setOrderKey(array("sorter", "id")); $relation->setOrder(array("ASC", "ASC")); $relation = $relation->load(); foreach ($relation as $key) { $definition = \Pimcore\Model\Object\Classificationstore\Service::getFieldDefinitionFromKeyConfig($key); if (method_exists($definition, "__wakeup")) { $definition->__wakeup(); } $keyList[] = array("name" => $key->getName(), "id" => $key->getKeyId(), "description" => $key->getDescription(), "definition" => $definition); } $this->activeGroupDefinitions[$group->getId()] = array("name" => $group->getName(), "id" => $group->getId(), "description" => $group->getDescription(), "keys" => $keyList); } }
/** * * @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; }
/** * @param $keyId * @param $groupId * @param string $language * @param bool|false $ignoreFallbackLanguage * @return null */ public function getLocalizedKeyValue($groupId, $keyId, $language = "default", $ignoreFallbackLanguage = false, $ignoreDefaultLanguage = false) { $oid = $this->object->getId(); \Logger::debug($oid); $keyConfig = Model\Object\Classificationstore\DefinitionCache::get($keyId); $fieldDefinition = Model\Object\Classificationstore\Service::getFieldDefinitionFromKeyConfig($keyConfig); $language = $this->getLanguage($language); $data = null; if (array_key_exists($groupId, $this->items) && array_key_exists($keyId, $this->items[$groupId]) && array_key_exists($language, $this->items[$groupId][$keyId])) { $data = $this->items[$groupId][$keyId][$language]; } // check for fallback value if ($fieldDefinition->isEmpty($data) && !$ignoreFallbackLanguage && self::doGetFallbackValues()) { $data = $this->getFallbackValue($groupId, $keyId, $language, $fieldDefinition); } if ($fieldDefinition->isEmpty($data) && !$ignoreDefaultLanguage && $language != "default") { $data = $this->items[$groupId][$keyId]["default"]; } // check for inherited value $doGetInheritedValues = AbstractObject::doGetInheritedValues(); if ($fieldDefinition->isEmpty($data) && $doGetInheritedValues) { $object = $this->getObject(); $class = $object->getClass(); $allowInherit = $class->getAllowInherit(); if ($allowInherit) { if ($object->getParent() instanceof AbstractObject) { $parent = $object->getParent(); while ($parent && $parent->getType() == "folder") { $parent = $parent->getParent(); } if ($parent && ($parent->getType() == "object" || $parent->getType() == "variant")) { if ($parent->getClassId() == $object->getClassId()) { $method = "getLocalizedfields"; if (method_exists($parent, $method)) { $getter = "get" . ucfirst($this->fieldname); $classificationStore = $parent->{$getter}(); if ($classificationStore instanceof Classificationstore) { if ($classificationStore->object->getId() != $this->object->getId()) { $data = $classificationStore->getLocalizedKeyValue($groupId, $keyId, $language, false); \Logger::debug($data); } } } } } } } } if ($fieldDefinition && method_exists($fieldDefinition, "preGetData")) { $data = $fieldDefinition->preGetData($this, array("data" => $data, "language" => $language, "name" => $groupId . "-" . $keyId)); } return $data; }
public function enrichLayoutDefinition($object) { $groupList = new Object\Classificationstore\GroupConfig\Listing(); $groupList = $groupList->load(); $this->activeGroupDefinitions = array(); $activeGroupIds = $this->recursiveGetActiveGroupsIds($object); asort($activeGroupIds); /** @var $group Object\Classificationstore\GroupConfig */ foreach ($activeGroupIds as $groupId => $enabled) { if ($enabled) { $group = Object\Classificationstore\GroupConfig::getById($groupId); $keyList = array(); $relation = new Object\Classificationstore\KeyGroupRelation\Listing(); $relation->setCondition("groupId = " . $relation->quote($group->getId())); $relation = $relation->load(); foreach ($relation as $key) { // $definition = $key->getDefinition(); $definition = \Pimcore\Model\Object\Classificationstore\Service::getFieldDefinitionFromKeyConfig($key); if (method_exists($definition, "__wakeup")) { $definition->__wakeup(); } $keyList[] = array("name" => $key->getName(), "id" => $key->getKeyId(), "description" => $key->getDescription(), "definition" => $definition); } $this->activeGroupDefinitions[$group->getId()] = array("name" => $group->getName(), "id" => $group->getId(), "description" => $group->getDescription(), "keys" => $keyList); } } }
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")]); } } } } }