getByKeyAndLanguage() public static method

public static getByKeyAndLanguage ( $key, $language, $targetSubtype = null ) : Predefined
$key
$language
return Pimcore\Model\Metadata\Predefined
 public function metadataAction()
 {
     if ($this->getParam("data")) {
         $this->checkPermission("predefined_properties");
         if ($this->getParam("xaction") == "destroy") {
             $data = \Zend_Json::decode($this->getParam("data"));
             if (\Pimcore\Tool\Admin::isExtJS6()) {
                 $id = $data["id"];
             } else {
                 $id = $data;
             }
             $metadata = Metadata\Predefined::getById($id);
             $metadata->delete();
             $this->_helper->json(array("success" => true, "data" => array()));
         } else {
             if ($this->getParam("xaction") == "update") {
                 $data = \Zend_Json::decode($this->getParam("data"));
                 // save type
                 $metadata = Metadata\Predefined::getById($data["id"]);
                 $metadata->setValues($data);
                 $existingItem = Metadata\Predefined\Listing::getByKeyAndLanguage($metadata->getName(), $metadata->getLanguage(), $metadata->getTargetSubtype());
                 if ($existingItem && $existingItem->getId() != $metadata->getId()) {
                     $this->_helper->json(array("message" => "rule_violation", "success" => false));
                 }
                 $metadata->minimize();
                 $metadata->save();
                 $metadata->expand();
                 $this->_helper->json(array("data" => $metadata, "success" => true));
             } else {
                 if ($this->getParam("xaction") == "create") {
                     $data = \Zend_Json::decode($this->getParam("data"));
                     unset($data["id"]);
                     // save type
                     $metadata = Metadata\Predefined::create();
                     $metadata->setValues($data);
                     $existingItem = Metadata\Predefined\Listing::getByKeyAndLanguage($metadata->getName(), $metadata->getLanguage(), $metadata->getTargetSubtype());
                     if ($existingItem) {
                         $this->_helper->json(array("message" => "rule_violation", "success" => false));
                     }
                     $metadata->save();
                     $this->_helper->json(array("data" => $metadata, "success" => true));
                 }
             }
         }
     } else {
         // get list of types
         $list = new Metadata\Predefined\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']);
         } else {
             $list->setOrderKey("name");
         }
         if ($this->getParam("filter")) {
             $list->setCondition("`name` LIKE " . $list->quote("%" . $this->getParam("filter") . "%") . " OR `description` LIKE " . $list->quote("%" . $this->getParam("filter") . "%"));
         }
         $list->load();
         $properties = array();
         if (is_array($list->getDefinitions())) {
             foreach ($list->getDefinitions() as $metadata) {
                 $metadata->expand();
                 $properties[] = $metadata;
             }
         }
         $this->_helper->json(array("data" => $properties, "success" => true, "total" => $list->getTotalCount()));
     }
 }
Beispiel #2
0
 public function metadataAction()
 {
     if ($this->getParam("data")) {
         $this->checkPermission("asset_metadata");
         if ($this->getParam("xaction") == "destroy") {
             $data = \Zend_Json::decode($this->getParam("data"));
             if (\Pimcore\Tool\Admin::isExtJS6()) {
                 $id = $data["id"];
             } else {
                 $id = $data;
             }
             $metadata = Metadata\Predefined::getById($id);
             $metadata->delete();
             $this->_helper->json(["success" => true, "data" => []]);
         } elseif ($this->getParam("xaction") == "update") {
             $data = \Zend_Json::decode($this->getParam("data"));
             // save type
             $metadata = Metadata\Predefined::getById($data["id"]);
             $metadata->setValues($data);
             $existingItem = Metadata\Predefined\Listing::getByKeyAndLanguage($metadata->getName(), $metadata->getLanguage(), $metadata->getTargetSubtype());
             if ($existingItem && $existingItem->getId() != $metadata->getId()) {
                 $this->_helper->json(["message" => "rule_violation", "success" => false]);
             }
             $metadata->minimize();
             $metadata->save();
             $metadata->expand();
             $this->_helper->json(["data" => $metadata, "success" => true]);
         } elseif ($this->getParam("xaction") == "create") {
             $data = \Zend_Json::decode($this->getParam("data"));
             unset($data["id"]);
             // save type
             $metadata = Metadata\Predefined::create();
             $metadata->setValues($data);
             $existingItem = Metadata\Predefined\Listing::getByKeyAndLanguage($metadata->getName(), $metadata->getLanguage(), $metadata->getTargetSubtype());
             if ($existingItem) {
                 $this->_helper->json(["message" => "rule_violation", "success" => false]);
             }
             $metadata->save();
             $this->_helper->json(["data" => $metadata, "success" => true]);
         }
     } else {
         // get list of types
         $list = new Metadata\Predefined\Listing();
         if ($this->getParam("filter")) {
             $filter = $this->getParam("filter");
             $list->setFilter(function ($row) use($filter) {
                 foreach ($row as $value) {
                     if (strpos($value, $filter) !== false) {
                         return true;
                     }
                 }
                 return false;
             });
         }
         $list->load();
         $properties = [];
         if (is_array($list->getDefinitions())) {
             foreach ($list->getDefinitions() as $metadata) {
                 $metadata->expand();
                 $properties[] = $metadata;
             }
         }
         $this->_helper->json(["data" => $properties, "success" => true, "total" => $list->getTotalCount()]);
     }
 }