상속: extends Pimcore\Model\AbstractModel
예제 #1
0
파일: Dao.php 프로젝트: pimcore/pimcore
 /**
  * Loads a list of Classificationstore collection configs for the specified parameters, returns an array of config elements
  *
  * @return array
  */
 public function load()
 {
     $sql = "SELECT id FROM " . Object\Classificationstore\CollectionConfig\Dao::TABLE_NAME_COLLECTIONS . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit();
     $configsData = $this->db->fetchCol($sql, $this->model->getConditionVariables());
     $configData = [];
     foreach ($configsData as $config) {
         $configData[] = Object\Classificationstore\CollectionConfig::getById($config);
     }
     $this->model->setList($configData);
     return $configData;
 }
 public function collectionsAction()
 {
     if ($this->getParam("data")) {
         $dataParam = $this->getParam("data");
         $data = \Zend_Json::decode($dataParam);
         $id = $data["id"];
         $config = Classificationstore\CollectionConfig::getById($id);
         foreach ($data as $key => $value) {
             if ($key != "id") {
                 $setter = "set" . $key;
                 $config->{$setter}($value);
             }
         }
         $config->save();
         $this->_helper->json(array("success" => true, "data" => $config));
     } else {
         $start = 0;
         $limit = 15;
         $orderKey = "name";
         $order = "ASC";
         if ($this->getParam("dir")) {
             $order = $this->getParam("dir");
         }
         if ($this->getParam("limit")) {
             $limit = $this->getParam("limit");
         }
         if ($this->getParam("start")) {
             $start = $this->getParam("start");
         }
         $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";
         }
         $allowedCollectionIds = array();
         if ($this->getParam("oid")) {
             $object = Object_Concrete::getById($this->getParam("oid"));
             $class = $object->getClass();
             $fd = $class->getFieldDefinition($this->getParam("fieldname"));
             $allowedGroupIds = $fd->getAllowedGroupIds();
             if ($allowedGroupIds) {
                 $db = \Pimcore\Db::get();
                 $query = "select * from classificationstore_collectionrelations where groupId in (" . implode(",", $allowedGroupIds) . ")";
                 $relationList = $db->fetchAll($query);
                 if (is_array($relationList)) {
                     foreach ($relationList as $item) {
                         $allowedCollectionIds[] = $item["colId"];
                     }
                 }
             }
         }
         $list = new Classificationstore\CollectionConfig\Listing();
         $list->setLimit($limit);
         $list->setOffset($start);
         $list->setOrder($order);
         $list->setOrderKey($orderKey);
         $condition = "";
         $db = Db::get();
         $searchfilter = $this->getParam("searchfilter");
         if ($searchfilter) {
             $condition = "(name LIKE " . $db->quote("%" . $searchfilter . "%") . " OR description LIKE " . $db->quote("%" . $searchfilter . "%") . ")";
         }
         if ($this->getParam("filter")) {
             $filterString = $this->getParam("filter");
             $filters = json_decode($filterString);
             $count = 0;
             foreach ($filters as $f) {
                 if ($count > 0) {
                     $condition .= " AND ";
                 }
                 $count++;
                 if (\Pimcore\Tool\Admin::isExtJS6()) {
                     $condition .= $db->getQuoteIdentifierSymbol() . $f->property . $db->getQuoteIdentifierSymbol() . " LIKE " . $db->quote("%" . $f->value . "%");
                 } else {
                     $condition .= $db->getQuoteIdentifierSymbol() . $f->field . $db->getQuoteIdentifierSymbol() . " LIKE " . $db->quote("%" . $f->value . "%");
                 }
             }
         }
         if ($allowedCollectionIds) {
             if ($condition) {
                 $condition .= " AND ";
             }
             $condition .= " id in (" . implode(",", $allowedCollectionIds) . ")";
         }
         $list->setCondition($condition);
         $list->load();
         $configList = $list->getList();
         $rootElement = array();
         $data = array();
         foreach ($configList as $config) {
             $name = $config->getName();
             if (!$name) {
                 $name = "EMPTY";
             }
             $item = array("id" => $config->getId(), "name" => $name, "description" => $config->getDescription());
             if ($config->getCreationDate()) {
                 $item["creationDate"] = $config->getCreationDate();
             }
             if ($config->getModificationDate()) {
                 $item["modificationDate"] = $config->getModificationDate();
             }
             $data[] = $item;
         }
         $rootElement["data"] = $data;
         $rootElement["success"] = true;
         $rootElement["total"] = $list->getTotalCount();
         return $this->_helper->json($rootElement);
     }
 }
 public function propertiesAction()
 {
     if ($this->getParam("data")) {
         $dataParam = $this->getParam("data");
         $data = \Zend_Json::decode($dataParam);
         $id = $data["id"];
         $config = Classificationstore\KeyConfig::getById($id);
         foreach ($data as $key => $value) {
             if ($key != "id") {
                 $setter = "set" . $key;
                 if (method_exists($config, $setter)) {
                     $config->{$setter}($value);
                 }
             }
         }
         $config->save();
         $item = $this->getConfigItem($config);
         $this->_helper->json(["success" => true, "data" => $item]);
     } else {
         $storeId = $this->getParam("storeId");
         $frameName = $this->getParam("frameName");
         $db = \Pimcore\Db::get();
         $conditionParts = [];
         if ($frameName) {
             $keyCriteria = " FALSE ";
             $frameConfig = Classificationstore\CollectionConfig::getByName($frameName, $storeId);
             if ($frameConfig) {
                 // get all keys within that collection / frame
                 $frameId = $frameConfig->getId();
                 $groupList = new Pimcore\Model\Object\Classificationstore\CollectionGroupRelation\Listing();
                 $groupList->setCondition("colId = " . $db->quote($frameId));
                 $groupList = $groupList->load();
                 $groupIdList = [];
                 foreach ($groupList as $groupEntry) {
                     $groupIdList[] = $groupEntry->getGroupId();
                 }
                 if ($groupIdList) {
                     $keyIdList = new Classificationstore\KeyGroupRelation\Listing();
                     $keyIdList->setCondition("groupId in (" . implode(",", $groupIdList) . ")");
                     $keyIdList = $keyIdList->load();
                     if ($keyIdList) {
                         $keyIds = [];
                         /** @var  $keyEntry Classificationstore\KeyGroupRelation */
                         foreach ($keyIdList as $keyEntry) {
                             $keyIds[] = $keyEntry->getKeyId();
                         }
                         if ($keyIds) {
                             $keyCriteria = " id in (" . implode(",", $keyIds) . ")";
                         }
                     }
                 }
             }
             if ($keyCriteria) {
                 $conditionParts[] = $keyCriteria;
             }
         }
         $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\KeyConfig\Listing();
         if ($limit > 0) {
             $list->setLimit($limit);
         }
         $list->setOffset($start);
         $list->setOrder($order);
         $list->setOrderKey($orderKey);
         $searchfilter = $this->getParam("searchfilter");
         if ($searchfilter) {
             $conditionParts[] = "(name LIKE " . $db->quote("%" . $searchfilter . "%") . " OR description LIKE " . $db->quote("%" . $searchfilter . "%") . ")";
         }
         if ($storeId) {
             $conditionParts[] = "(storeId = " . $storeId . ")";
         }
         if ($this->getParam("filter")) {
             $filterString = $this->getParam("filter");
             $filters = json_decode($filterString);
             foreach ($filters as $f) {
                 if (\Pimcore\Tool\Admin::isExtJS6()) {
                     $conditionParts[] = $db->getQuoteIdentifierSymbol() . $f->property . $db->getQuoteIdentifierSymbol() . " LIKE " . $db->quote("%" . $f->value . "%");
                 } else {
                     $conditionParts[] = $db->getQuoteIdentifierSymbol() . $f->field . $db->getQuoteIdentifierSymbol() . " LIKE " . $db->quote("%" . $f->value . "%");
                 }
             }
         }
         $condition = implode(" AND ", $conditionParts);
         $list->setCondition($condition);
         if ($this->getParam("groupIds") || $this->getParam("keyIds")) {
             $db = Db::get();
             if ($this->getParam("groupIds")) {
                 $ids = \Zend_Json::decode($this->getParam("groupIds"));
                 $col = "group";
             } else {
                 $ids = \Zend_Json::decode($this->getParam("keyIds"));
                 $col = "id";
             }
             $condition = $db->getQuoteIdentifierSymbol() . $col . $db->getQuoteIdentifierSymbol() . " IN (";
             $count = 0;
             foreach ($ids as $theId) {
                 if ($count > 0) {
                     $condition .= ",";
                 }
                 $condition .= $theId;
                 $count++;
             }
             $condition .= ")";
             $list->setCondition($condition);
         }
         $list->load();
         $configList = $list->getList();
         $rootElement = [];
         $data = [];
         foreach ($configList as $config) {
             $item = $this->getConfigItem($config);
             $data[] = $item;
         }
         $rootElement["data"] = $data;
         $rootElement["success"] = true;
         $rootElement["total"] = $list->getTotalCount();
         return $this->_helper->json($rootElement);
     }
 }