public function relationsAction()
{
if ($this->getParam("data")) {
$dataParam = $this->getParam("data");
$data = \Zend_Json::decode($dataParam);
$keyId = $data["keyId"];
$groupId = $data["groupId"];
$sorter = $data["sorter"];
$config = new Classificationstore\KeyGroupRelation();
$config->setGroupId($groupId);
$config->setKeyId($keyId);
$config->setSorter($sorter);
$config->save();
$data["id"] = $config->getGroupId() . "-" . $config->getKeyId();
$this->_helper->json(array("success" => true, "data" => $data));
} else {
$mapping = array("keyName" => "name", "keyDescription" => "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);
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 . "%");
}
}
$groupId = $this->getParam("groupId");
if ($condition) {
$condition = "( " . $condition . " ) AND";
}
$condition .= " groupId = " . $list->quote($groupId);
$list->setCondition($condition);
$listItems = $list->load();
$rootElement = array();
$data = array();
foreach ($listItems as $config) {
$item = array("keyId" => $config->getKeyId(), "groupId" => $config->getGroupId(), "keyName" => $config->getName(), "keyDescription" => $config->getDescription(), "id" => $config->getGroupId() . "-" . $config->getKeyId(), "sorter" => $config->getSorter());
$data[] = $item;
}
$rootElement["data"] = $data;
$rootElement["success"] = true;
$rootElement["total"] = $list->getTotalCount();
return $this->_helper->json($rootElement);
}
}