Inheritance: extends Pimcore\Model\Listing\AbstractListing
示例#1
0
 /**
  * @return array|mixed
  * @throws \Zend_Exception
  */
 protected function getData()
 {
     if (\Zend_Registry::isRegistered("Zend_Locale")) {
         $locale = (string) \Zend_Registry::get("Zend_Locale");
     } else {
         return array();
     }
     $siteId = "";
     try {
         $site = Model\Site::getCurrentSite();
         if ($site instanceof Model\Site) {
             $siteId = $site->getId();
         }
     } catch (\Exception $e) {
         // not inside a site
     }
     $cacheKey = "glossary_" . $locale . "_" . $siteId;
     try {
         $data = \Zend_Registry::get($cacheKey);
         return $data;
     } catch (\Exception $e) {
     }
     if (!($data = Model\Cache::load($cacheKey))) {
         $list = new Model\Glossary\Listing();
         $list->setCondition("(language = ? OR language IS NULL OR language = '') AND (site = ? OR site IS NULL OR site = '')", array($locale, $siteId));
         $list->setOrderKey("LENGTH(`text`)", false);
         $list->setOrder("DESC");
         $data = $list->getDataArray();
         $data = $this->prepareData($data);
         Model\Cache::save($data, $cacheKey, array("glossary"), null, 995);
         \Zend_Registry::set($cacheKey, $data);
     }
     return $data;
 }
 public function glossaryAction()
 {
     if ($this->getParam("data")) {
         $this->checkPermission("glossary");
         Cache::clearTag("glossary");
         if ($this->getParam("xaction") == "destroy") {
             $data = \Zend_Json::decode($this->getParam("data"));
             if (\Pimcore\Tool\Admin::isExtJS6()) {
                 $id = $data["id"];
             } else {
                 $id = $data;
             }
             $glossary = Glossary::getById($id);
             $glossary->delete();
             $this->_helper->json(array("success" => true, "data" => array()));
         } else {
             if ($this->getParam("xaction") == "update") {
                 $data = \Zend_Json::decode($this->getParam("data"));
                 // save glossary
                 $glossary = Glossary::getById($data["id"]);
                 if ($data["link"]) {
                     if ($doc = Document::getByPath($data["link"])) {
                         $tmpLink = $data["link"];
                         $data["link"] = $doc->getId();
                     }
                 }
                 $glossary->setValues($data);
                 $glossary->save();
                 if ($link = $glossary->getLink()) {
                     if (intval($link) > 0) {
                         if ($doc = Document::getById(intval($link))) {
                             $glossary->setLink($doc->getFullPath());
                         }
                     }
                 }
                 $this->_helper->json(array("data" => $glossary, "success" => true));
             } else {
                 if ($this->getParam("xaction") == "create") {
                     $data = \Zend_Json::decode($this->getParam("data"));
                     unset($data["id"]);
                     // save glossary
                     $glossary = new Glossary();
                     if ($data["link"]) {
                         if ($doc = Document::getByPath($data["link"])) {
                             $tmpLink = $data["link"];
                             $data["link"] = $doc->getId();
                         }
                     }
                     $glossary->setValues($data);
                     $glossary->save();
                     if ($link = $glossary->getLink()) {
                         if (intval($link) > 0) {
                             if ($doc = Document::getById(intval($link))) {
                                 $glossary->setLink($doc->getFullPath());
                             }
                         }
                     }
                     $this->_helper->json(array("data" => $glossary, "success" => true));
                 }
             }
         }
     } else {
         // get list of glossaries
         $list = new Glossary\Listing();
         $list->setLimit($this->getParam("limit"));
         $list->setOffset($this->getParam("start"));
         $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams());
         if ($sortingSettings['orderKey']) {
             $list->setOrderKey($sortingSettings['orderKey']);
             $list->setOrder($sortingSettings['order']);
         }
         if ($this->getParam("filter")) {
             $list->setCondition("`text` LIKE " . $list->quote("%" . $this->getParam("filter") . "%"));
         }
         $list->load();
         $glossaries = array();
         foreach ($list->getGlossary() as $glossary) {
             if ($link = $glossary->getLink()) {
                 if (intval($link) > 0) {
                     if ($doc = Document::getById(intval($link))) {
                         $glossary->setLink($doc->getFullPath());
                     }
                 }
             }
             $glossaries[] = $glossary;
         }
         $this->_helper->json(array("data" => $glossaries, "success" => true, "total" => $list->getTotalCount()));
     }
     $this->_helper->json(false);
 }