/** * Loads a list of Classificationstore group configs for the specifies parameters, returns an array of config elements * * @return array */ public function load() { $sql = "SELECT id FROM " . Object\Classificationstore\GroupConfig\Resource::TABLE_NAME_GROUPS . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(); $configsData = $this->db->fetchCol($sql, $this->model->getConditionVariables()); $configData = array(); foreach ($configsData as $config) { $configData[] = Object\Classificationstore\GroupConfig::getById($config); } $this->model->setList($configData); return $configData; }
/** * 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; } }
public function groupsAction() { if ($this->getParam("data")) { $dataParam = $this->getParam("data"); $data = \Zend_Json::decode($dataParam); $id = $data["id"]; $config = Classificationstore\GroupConfig::getById($id); foreach ($data as $key => $value) { if ($key != "id") { $setter = "set" . $key; $config->{$setter}($value); } } $config->save(); $this->_helper->json(array("success" => true, "data" => $config)); } else { $start = 0; $limit = 15; $orderKey = "name"; $order = "ASC"; if ($this->getParam("dir")) { $order = $this->getParam("dir"); } if ($this->getParam("sort")) { $orderKey = $this->getParam("sort"); } 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['orderKey'] && $sortingSettings['order']) { $orderKey = $sortingSettings['orderKey']; $order = $sortingSettings['order']; } if ($this->getParam("overrideSort") == "true") { $orderKey = "id"; $order = "DESC"; } $list = new Classificationstore\GroupConfig\Listing(); $list->setLimit($limit); $list->setOffset($start); $list->setOrder($order); $list->setOrderKey($orderKey); $condition = ""; $db = Db::get(); $searchfilter = $this->getParam("searchfilter"); if ($searchfilter) { $condition = "(name LIKE " . $db->quote("%" . $searchfilter . "%") . " OR description LIKE " . $db->quote("%" . $searchfilter . "%") . ")"; } if ($this->getParam("filter")) { $filterString = $this->getParam("filter"); $filters = json_decode($filterString); $count = 0; foreach ($filters as $f) { if ($count > 0) { $condition .= " AND "; } $count++; if (\Pimcore\Tool\Admin::isExtJS6()) { $condition .= $db->getQuoteIdentifierSymbol() . $f->property . $db->getQuoteIdentifierSymbol() . " LIKE " . $db->quote("%" . $f->value . "%"); } else { $condition .= $db->getQuoteIdentifierSymbol() . $f->field . $db->getQuoteIdentifierSymbol() . " LIKE " . $db->quote("%" . $f->value . "%"); } } } if ($this->getParam("oid")) { $object = Object_Concrete::getById($this->getParam("oid")); $class = $object->getClass(); $fd = $class->getFieldDefinition($this->getParam("fieldname")); $allowedGroupIds = $fd->getAllowedGroupIds(); if ($allowedGroupIds) { if ($condition) { $condition = "(" . $condition . ") AND "; } $condition .= "ID in (" . implode(",", $allowedGroupIds) . ")"; } } $list->setCondition($condition); $list->load(); $configList = $list->getList(); $rootElement = array(); $data = array(); foreach ($configList as $config) { $name = $config->getName(); if (!$name) { $name = "EMPTY"; } $item = array("id" => $config->getId(), "name" => $name, "description" => $config->getDescription()); if ($config->getCreationDate()) { $item["creationDate"] = $config->getCreationDate(); } if ($config->getModificationDate()) { $item["modificationDate"] = $config->getModificationDate(); } $data[] = $item; } $rootElement["data"] = $data; $rootElement["success"] = true; $rootElement["total"] = $list->getTotalCount(); return $this->_helper->json($rootElement); } }
public function searchRelationsAction() { $db = Db::get(); $storeId = $this->getParam("storeId"); $mapping = ["groupName" => Object\Classificationstore\GroupConfig\Dao::TABLE_NAME_GROUPS . ".name", "keyName" => Object\Classificationstore\KeyConfig\Dao::TABLE_NAME_KEYS . ".name", "keyDescription" => Object\Classificationstore\KeyConfig\Dao::TABLE_NAME_KEYS . ".description"]; $start = 0; $limit = 15; $orderKey = "name"; $order = "ASC"; if ($this->getParam("dir")) { $order = $this->getParam("dir"); } $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['orderKey'] && $sortingSettings['order']) { $orderKey = $sortingSettings['orderKey']; $order = $sortingSettings['order']; } if ($this->getParam("overrideSort") == "true") { $orderKey = "id"; $order = "DESC"; } if ($this->getParam("limit")) { $limit = $this->getParam("limit"); } if ($this->getParam("start")) { $start = $this->getParam("start"); } $list = new Classificationstore\KeyGroupRelation\Listing(); if ($limit > 0) { $list->setLimit($limit); } $list->setOffset($start); $list->setOrder($order); $list->setOrderKey($orderKey); $conditionParts = []; if ($this->getParam("filter")) { $db = Db::get(); $filterString = $this->getParam("filter"); $filters = json_decode($filterString); $count = 0; foreach ($filters as $f) { $count++; $fieldname = $mapping[$f->property]; $conditionParts[] = $fieldname . " LIKE " . $db->quote("%" . $f->value . "%"); } } $conditionParts[] = " groupId IN (select id from classificationstore_groups where storeId = " . $db->quote($storeId) . ")"; $searchfilter = $this->getParam("searchfilter"); if ($searchfilter) { $conditionParts[] = "(" . Classificationstore\KeyConfig\Dao::TABLE_NAME_KEYS . ".name LIKE " . $db->quote("%" . $searchfilter . "%") . " OR " . Classificationstore\GroupConfig\Dao::TABLE_NAME_GROUPS . ".name LIKE " . $db->quote("%" . $searchfilter . "%") . " OR " . Classificationstore\KeyConfig\Dao::TABLE_NAME_KEYS . ".description LIKE " . $db->quote("%" . $searchfilter . "%") . ")"; } $condition = implode(" AND ", $conditionParts); $list->setCondition($condition); $list->setResolveGroupName(1); $listItems = $list->load(); $rootElement = []; $data = []; foreach ($listItems as $config) { $item = ["keyId" => $config->getKeyId(), "groupId" => $config->getGroupId(), "keyName" => $config->getName(), "keyDescription" => $config->getDescription(), "id" => $config->getGroupId() . "-" . $config->getKeyId(), "sorter" => $config->getSorter()]; $groupConfig = Classificationstore\GroupConfig::getById($config->getGroupId()); if ($groupConfig) { $item["groupName"] = $groupConfig->getName(); } $data[] = $item; } $rootElement["data"] = $data; $rootElement["success"] = true; $rootElement["total"] = $list->getTotalCount(); return $this->_helper->json($rootElement); }
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 mapFieldname($field) { if (substr($field, 0, 1) == "~") { $fieldParts = explode("~", $field); $type = $fieldParts[1]; if ($type == "classificationstore") { $fieldname = $fieldParts[2]; $groupKeyId = explode("-", $fieldParts[3]); $groupId = $groupKeyId[0]; $keyId = $groupKeyId[1]; $groupConfig = Object\Classificationstore\GroupConfig::getById($groupId); $keyConfig = Object\Classificationstore\KeyConfig::getById($keyId); $field = $fieldname . "~" . $groupConfig->getName() . "~" . $keyConfig->getName(); } } return $field; }