Inheritance: extends pimcore\model\AbstractModel
Exemple #1
0
 /**
  * Loads a list of keyvalue key configs for the specifies parameters, returns an array of config elements
  *
  * @return array
  */
 public function load()
 {
     $sql = "SELECT id FROM " . Object\KeyValue\KeyConfig\Dao::TABLE_NAME_KEYS . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit();
     $configsData = $this->db->fetchCol($sql, $this->model->getConditionVariables());
     $configData = array();
     foreach ($configsData as $config) {
         $configData[] = Object\KeyValue\KeyConfig::getById($config);
     }
     $this->model->setList($configData);
     return $configData;
 }
Exemple #2
0
 /** Imports the group/key config from XML.
  * @param $config
  */
 public static function import($config)
 {
     if (is_array($config["groups"])) {
         $groups = $config["groups"]["group"];
         if (!isset($groups[0])) {
             $groups = array($groups);
         }
         $groupIdMapping = array();
         foreach ($groups as $groupConfig) {
             $name = $groupConfig["name"];
             $group = Object\KeyValue\GroupConfig::getByName($name);
             if (!$group) {
                 $group = new Object\KeyValue\GroupConfig();
                 $group->setName($name);
             }
             $group->setDescription($groupConfig["description"]);
             $group->save();
             // mapping of remote id to local id
             $groupIdMapping[$groupConfig["id"]] = $group->getId();
         }
     }
     if (is_array($config["keys"])) {
         $keys = $config["keys"]["key"];
         if (!isset($keys[0])) {
             $keys = array($keys);
         }
         foreach ($keys as $keyConfig) {
             $name = $keyConfig["name"];
             $key = Object\KeyValue\KeyConfig::getByName($name);
             if (!$key) {
                 $key = new Object\KeyValue\KeyConfig();
                 $key->setName($name);
             }
             $key->setDescription($keyConfig["description"]);
             $key->setType($keyConfig["type"]);
             if (!empty($keyConfig["unit"])) {
                 $key->setUnit($keyConfig["unit"]);
             }
             if (!empty($keyConfig["possiblevalues"])) {
                 $key->setPossibleValues($keyConfig["possiblevalues"]);
             }
             $originalGroupId = $keyConfig["group"];
             if (!empty($originalGroupId)) {
                 $mappedGroupId = $groupIdMapping[$originalGroupId];
                 $key->setGroup($mappedGroupId);
             }
             $key->save();
         }
     }
 }
 /**
  * @param $keyId
  * @param $value
  * @return string
  */
 private function getTranslatedValue($keyId, $value)
 {
     $translatedValue = "";
     $keyConfig = Object\KeyValue\KeyConfig::getById($keyId);
     $translatorID = $keyConfig->getTranslator();
     $translatorConfig = Object\KeyValue\TranslatorConfig::getById($translatorID);
     $className = $translatorConfig->getTranslator();
     if (\Pimcore\Tool::classExists($className)) {
         $translator = new $className();
         $translatedValue = $translator->translate($value);
         if (!$translatedValue) {
             $translatedValue = $value;
         }
     }
     return $translatedValue;
 }
Exemple #4
0
 /**
  * converts data to be exposed via webservices
  * @param string $object
  * @param mixed $params
  * @return mixed
  */
 public function getForWebserviceExport($object, $params = [])
 {
     $data = $this->getDataFromObjectParam($object, $params);
     if ($data) {
         $result = [];
         foreach ($data->arr as $item) {
             $keyConfig = Object\KeyValue\KeyConfig::getById($item["key"]);
             $keyName = $keyConfig->getName();
             $resultItem = ["id" => $item["key"], "name" => $keyName, "value" => $item["value"], "metadata" => $item["metadata"]];
             if ($keyConfig->getType() == "translated") {
                 $resultItem["translated"] = $item["translated"];
             }
             $result[] = $resultItem;
         }
         return $result;
     }
 }
 public function translateAction()
 {
     $success = false;
     $keyId = $this->getParam("keyId");
     $objectId = $this->getParam("objectId");
     $recordId = $this->getParam("recordId");
     $text = $this->getParam("text");
     $translatedValue = $text;
     try {
         $keyConfig = KeyValue\KeyConfig::getById($keyId);
         $translatorID = $keyConfig->getTranslator();
         $translatorConfig = KeyValue\TranslatorConfig::getById($translatorID);
         $className = $translatorConfig->getTranslator();
         if (\Pimcore\Tool::classExists($className)) {
             $translator = new $className();
             $translatedValue = $translator->translate($text);
             if (!$translatedValue) {
                 $translatedValue = $text;
             }
         }
         $this->_helper->json(["success" => true, "keyId" => $this->getParam("keyId"), "text" => $text, "translated" => $translatedValue, "recordId" => $recordId]);
     } catch (\Exception $e) {
     }
     $this->_helper->json(["success" => $success]);
 }