Esempio n. 1
0
 public function translationsAction()
 {
     $admin = $this->getParam("admin");
     if ($admin) {
         $class = "\\Pimcore\\Model\\Translation\\Admin";
         $this->checkPermission("translations_admin");
     } else {
         $class = "\\Pimcore\\Model\\Translation\\Website";
         $this->checkPermission("translations");
     }
     // clear translation cache
     Translation\Website::clearDependentCache();
     if ($this->getParam("data")) {
         $data = \Zend_Json::decode($this->getParam("data"));
         if ($this->getParam("xaction") == "destroy") {
             $data = \Zend_Json::decode($this->getParam("data"));
             if (\Pimcore\Tool\Admin::isExtJS6()) {
                 $t = $class::getByKey($data["key"]);
             } else {
                 $t = $class::getByKey($data);
             }
             $t->delete();
             $this->_helper->json(array("success" => true, "data" => array()));
         } else {
             if ($this->getParam("xaction") == "update") {
                 $t = $class::getByKey($data["key"]);
                 foreach ($data as $key => $value) {
                     if ($key != "key") {
                         $t->addTranslation($key, $value);
                     }
                 }
                 if ($data["key"]) {
                     $t->setKey($data["key"]);
                 }
                 $t->setModificationDate(time());
                 $t->save();
                 $return = array_merge(array("key" => $t->getKey(), "creationDate" => $t->getCreationDate(), "modificationDate" => $t->getModificationDate()), $t->getTranslations());
                 $this->_helper->json(array("data" => $return, "success" => true));
             } else {
                 if ($this->getParam("xaction") == "create") {
                     try {
                         $t = $class::getByKey($data["key"]);
                     } catch (\Exception $e) {
                         $t = new $class();
                         $t->setKey($data["key"]);
                         $t->setCreationDate(time());
                         $t->setModificationDate(time());
                         foreach (Tool::getValidLanguages() as $lang) {
                             $t->addTranslation($lang, "");
                         }
                         $t->save();
                     }
                     $return = array_merge(array("key" => $t->getKey(), "creationDate" => $t->getCreationDate(), "modificationDate" => $t->getModificationDate()), $t->getTranslations());
                     $this->_helper->json(array("data" => $return, "success" => true));
                 }
             }
         }
     } else {
         // get list of types
         if ($admin) {
             $list = new Translation\Admin\Listing();
         } else {
             $list = new Translation\Website\Listing();
         }
         $list->setOrder("asc");
         $list->setOrderKey("key");
         $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams());
         if ($sortingSettings['orderKey']) {
             $list->setOrderKey($sortingSettings['orderKey']);
         }
         if ($sortingSettings['order']) {
             $list->setOrder($sortingSettings['order']);
         }
         $list->setLimit($this->getParam("limit"));
         $list->setOffset($this->getParam("start"));
         $condition = $this->getGridFilterCondition();
         if ($condition) {
             $list->setCondition($condition);
         }
         $list->load();
         $translations = array();
         foreach ($list->getTranslations() as $t) {
             $translations[] = array_merge($t->getTranslations(), array("key" => $t->getKey(), "creationDate" => $t->getCreationDate(), "modificationDate" => $t->getModificationDate()));
         }
         $this->_helper->json(array("data" => $translations, "success" => true, "total" => $list->getTotalCount()));
     }
 }