Inheritance: extends Pimcore\Model\AbstractModel
Esempio n. 1
0
 /**
  * Loads a list of Classificationstore group configs for the specified parameters, returns an array of config elements
  *
  * @return array
  */
 public function load()
 {
     $condition = $this->getCondition();
     if ($condition) {
         $condition = $condition . " AND ";
     } else {
         $condition = " where ";
     }
     $condition .= Object\Classificationstore\KeyGroupRelation\Dao::TABLE_NAME_RELATIONS . ".keyId = " . Object\Classificationstore\KeyConfig\Dao::TABLE_NAME_KEYS . ".id";
     $resourceGroupName = $this->model->getResolveGroupName();
     if ($resourceGroupName) {
         $condition .= " and " . Object\Classificationstore\GroupConfig\Dao::TABLE_NAME_GROUPS . ".id = " . Object\Classificationstore\KeyGroupRelation\Dao::TABLE_NAME_RELATIONS . ".groupId";
     }
     $sql = "SELECT " . Object\Classificationstore\KeyGroupRelation\Dao::TABLE_NAME_RELATIONS . ".*," . Object\Classificationstore\KeyConfig\Dao::TABLE_NAME_KEYS . ".*";
     if ($resourceGroupName) {
         $sql .= ", " . Object\Classificationstore\GroupConfig\Dao::TABLE_NAME_GROUPS . ".name as groupName";
     }
     $sql .= " FROM " . Object\Classificationstore\KeyGroupRelation\Dao::TABLE_NAME_RELATIONS . "," . Object\Classificationstore\KeyConfig\Dao::TABLE_NAME_KEYS;
     if ($resourceGroupName) {
         $sql .= ", " . Object\Classificationstore\GroupConfig\Dao::TABLE_NAME_GROUPS;
     }
     $sql .= $condition;
     $sql .= $this->getOrder() . $this->getOffsetLimit();
     $data = $this->db->fetchAll($sql, $this->model->getConditionVariables());
     $configData = [];
     foreach ($data as $dataItem) {
         $entry = new Object\Classificationstore\KeyGroupRelation();
         $resource = $entry->getDao();
         $resource->assignVariablesToModel($dataItem);
         $configData[] = $entry;
     }
     $this->model->setList($configData);
     return $configData;
 }
Esempio n. 2
0
File: Dao.php Progetto: sfie/pimcore
 /**
  * Loads a list of Classificationstore group configs for the specifies parameters, returns an array of config elements
  *
  * @return array
  */
 public function load()
 {
     $condition = $this->getCondition();
     if ($condition) {
         $condition = $condition . " AND ";
     } else {
         $condition = " where ";
     }
     $condition .= Object\Classificationstore\KeyGroupRelation\Dao::TABLE_NAME_RELATIONS . ".keyId = " . Object\Classificationstore\KeyConfig\Dao::TABLE_NAME_KEYS . ".id";
     $sql = "SELECT * FROM " . Object\Classificationstore\KeyGroupRelation\Dao::TABLE_NAME_RELATIONS . "," . Object\Classificationstore\KeyConfig\Dao::TABLE_NAME_KEYS . $condition . $this->getOrder() . $this->getOffsetLimit();
     $data = $this->db->fetchAll($sql, $this->model->getConditionVariables());
     $configData = array();
     foreach ($data as $dataItem) {
         $entry = new Object\Classificationstore\KeyGroupRelation();
         $resource = $entry->getDao();
         $resource->assignVariablesToModel($dataItem);
         $configData[] = $entry;
     }
     $this->model->setList($configData);
     return $configData;
 }
 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);
     }
 }
 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"];
         $mandatory = $data["mandatory"];
         $config = new Classificationstore\KeyGroupRelation();
         $config->setGroupId($groupId);
         $config->setKeyId($keyId);
         $config->setSorter($sorter);
         $config->setMandatory($mandatory);
         $config->save();
         $data["id"] = $config->getGroupId() . "-" . $config->getKeyId();
         $this->_helper->json(["success" => true, "data" => $data]);
     } else {
         $mapping = ["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();
             $conditionParts = [];
             $filterString = $this->getParam("filter");
             $filters = json_decode($filterString);
             $count = 0;
             foreach ($filters as $f) {
                 $count++;
                 $fieldname = $mapping[$f->field];
                 $conditionParts[] = $db->getQuoteIdentifierSymbol() . $fieldname . $db->getQuoteIdentifierSymbol() . " LIKE " . $db->quote("%" . $f->value . "%");
             }
         }
         if (!$this->getParam("relationIds")) {
             $groupId = $this->getParam("groupId");
             $conditionParts[] = " groupId = " . $list->quote($groupId);
         }
         $relationIds = $this->getParam("relationIds");
         if ($relationIds) {
             $relationIds = json_decode($relationIds, true);
             $relationParts = [];
             foreach ($relationIds as $relationId) {
                 $keyId = $relationId["keyId"];
                 $groupId = $relationId["groupId"];
                 $relationParts[] = "(keyId = " . $keyId . " and groupId = " . $groupId . ")";
             }
             $conditionParts[] = "(" . implode(" OR ", $relationParts) . ")";
         }
         $condition = implode(" AND ", $conditionParts);
         $list->setCondition($condition);
         $listItems = $list->load();
         $rootElement = [];
         $data = [];
         /** @var  $config Classificationstore\KeyGroupRelation */
         foreach ($listItems as $config) {
             $type = $config->getType();
             $definition = json_decode($config->getDefinition());
             $definition = \Pimcore\Model\Object\Classificationstore\Service::getFieldDefinitionFromJson($definition, $type);
             $item = ["keyId" => $config->getKeyId(), "groupId" => $config->getGroupId(), "keyName" => $config->getName(), "keyDescription" => $config->getDescription(), "id" => $config->getGroupId() . "-" . $config->getKeyId(), "sorter" => $config->getSorter(), "layout" => $definition, "mandatory" => $config->isMandatory()];
             $data[] = $item;
         }
         $rootElement["data"] = $data;
         $rootElement["success"] = true;
         $rootElement["total"] = $list->getTotalCount();
         return $this->_helper->json($rootElement);
     }
 }