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; } }); } }
/** * */ 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); }
/** * @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) { $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); } }
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); } } }