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);
}