public function collectionRelationsAction()
{
if ($this->getParam("data")) {
$dataParam = $this->getParam("data");
$data = \Zend_Json::decode($dataParam);
if (count($data) == count($data, 1)) {
$data = [$data];
}
foreach ($data as &$row) {
$colId = $row["colId"];
$groupId = $row["groupId"];
$sorter = $row["sorter"];
$config = new Classificationstore\CollectionGroupRelation();
$config->setGroupId($groupId);
$config->setColId($colId);
$config->setSorter($sorter);
$config->save();
$row["id"] = $config->getColId() . "-" . $config->getGroupId();
}
$this->_helper->json(["success" => true, "data" => $data]);
} else {
$mapping = ["groupName" => "name", "groupDescription" => "description"];
$start = 0;
$limit = 15;
$orderKey = "sorter";
$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\CollectionGroupRelation\Listing();
if ($limit > 0) {
$list->setLimit($limit);
}
$list->setOffset($start);
$list->setOrder($order);
$list->setOrderKey($orderKey);
if ($this->getParam("filter")) {
$db = Db::get();
$condition = "";
$filterString = $this->getParam("filter");
$filters = json_decode($filterString);
$count = 0;
foreach ($filters as $f) {
if ($count > 0) {
$condition .= " AND ";
}
$count++;
$fieldname = $mapping[$f->field];
$condition .= $db->getQuoteIdentifierSymbol() . $fieldname . $db->getQuoteIdentifierSymbol() . " LIKE " . $db->quote("%" . $f->value . "%");
}
}
$colId = $this->getParam("colId");
if ($condition) {
$condition = "( " . $condition . " ) AND";
}
$condition .= " colId = " . $list->quote($colId);
$list->setCondition($condition);
$listItems = $list->load();
$rootElement = [];
$data = [];
foreach ($listItems as $config) {
$item = ["colId" => $config->getColId(), "groupId" => $config->getGroupId(), "groupName" => $config->getName(), "groupDescription" => $config->getDescription(), "id" => $config->getColId() . "-" . $config->getGroupId(), "sorter" => $config->getSorter()];
$data[] = $item;
}
$rootElement["data"] = $data;
$rootElement["success"] = true;
$rootElement["total"] = $list->getTotalCount();
return $this->_helper->json($rootElement);
}
}