Наследование: extends Pimcore\Model\Listing\AbstractListing
Пример #1
0
 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 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 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 addGroupsAction()
 {
     $db = Resource::get();
     $ids = \Zend_Json::decode($this->_getParam("groupIds"));
     $keyCondition = "groupId in (" . implode(",", $ids) . ")";
     $keyList = new Classificationstore\KeyGroupRelation\Listing();
     $keyList->setCondition($keyCondition);
     $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"];
         $definition = $keyData->getDefinition();
         $keyList[] = array("name" => $keyData->getName(), "id" => $keyData->getKeyId(), "description" => $keyData->getDescription(), "definition" => json_decode($definition));
         $data[$groupId]["keys"] = $keyList;
     }
     //        $data = array_values($data);
     return $this->_helper->json($data);
 }