상속: extends Pimcore\Model\AbstractModel
예제 #1
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();
         }
     }
 }
예제 #2
0
파일: Dao.php 프로젝트: sfie/pimcore
 /**
  * Loads a list of keyvalue group configs for the specifies parameters, returns an array of config elements
  *
  * @return array
  */
 public function load()
 {
     $sql = "SELECT id FROM " . Object\KeyValue\GroupConfig\Dao::TABLE_NAME_GROUPS . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit();
     $configsData = $this->db->fetchCol($sql, $this->model->getConditionVariables());
     $configData = array();
     foreach ($configsData as $config) {
         $configData[] = Object\KeyValue\GroupConfig::getById($config);
     }
     $this->model->setList($configData);
     return $configData;
 }
예제 #3
0
 /**
  * @param $name
  * @param $arguments
  * @return array|mixed|null|void
  * @throws \Exception
  */
 public function __call($name, $arguments)
 {
     $sub = substr($name, 0, 14);
     if (substr($name, 0, 16) == "getWithGroupName") {
         $key = substr($name, 16, strlen($name) - 16);
         $groupConfig = Object\KeyValue\GroupConfig::getByName($arguments[0]);
         return $this->getProperty($key, $groupConfig->getId());
     } else {
         if (substr($name, 0, 14) == "getWithGroupId") {
             $key = substr($name, 14, strlen($name) - 14);
             $groupConfig = Object\KeyValue\GroupConfig::getById($arguments[0]);
             return $this->getProperty($key, $groupConfig->getId());
         } else {
             if (substr($name, 0, 3) == "get") {
                 $key = substr($name, 3, strlen($name) - 3);
                 return $this->getProperty($key);
             } else {
                 if (substr($name, 0, 3) == "set") {
                     $key = substr($name, 3, strlen($name) - 3);
                     return $this->setProperty($key, $arguments[0]);
                 }
             }
         }
     }
     return parent::__call($name, $arguments);
 }
예제 #4
0
 /**
  * @see Object\ClassDefinition\Data::getDataForEditmode
  * @param Object\Data\KeyValue $data
  * @param null|Model\Object\AbstractObject $object
  * @param mixed $params
  * @return tbd
  */
 public function getDataForEditmode($data, $object = null, $params = [])
 {
     $result = [];
     if (!$data) {
         return $result;
     }
     $properties = $data->getProperties(true);
     foreach ($properties as $key => $property) {
         $key = $property["key"];
         $keyConfig = Object\KeyValue\KeyConfig::getById($key);
         $property["type"] = $keyConfig->getType();
         $property["possiblevalues"] = $keyConfig->getPossibleValues();
         $groupId = $keyConfig->getGroup();
         if ($groupId) {
             $group = Object\KeyValue\GroupConfig::getById($groupId);
             $property["group"] = $group->getName();
             $property["groupDesc"] = $group->getDescription();
         }
         $property["unit"] = $keyConfig->getUnit();
         $property["keyName"] = $keyConfig->getName();
         $property["keyDesc"] = $keyConfig->getDescription();
         $property["mandatory"] = $keyConfig->getMandatory();
         $result[] = $property;
     }
     return $result;
 }
예제 #5
0
 protected function getConfigItem($config)
 {
     $name = $config->getName();
     if (!$name) {
         $name = "EMPTY";
     }
     $groupDescription = null;
     if ($config->getGroup()) {
         try {
             $group = KeyValue\GroupConfig::getById($config->getGroup());
             $groupDescription = $group->getDescription();
             $groupName = $group->getName();
         } catch (\Exception $e) {
         }
         if (empty($groupDescription)) {
             $groupDescription = $group->getName();
         }
     }
     $item = ["id" => $config->getId(), "name" => $name, "description" => $config->getDescription(), "type" => $config->getType(), "unit" => $config->getUnit(), "possiblevalues" => $config->getPossibleValues(), "group" => $config->getGroup(), "groupdescription" => $groupDescription, "groupName" => $groupName, "translator" => $config->getTranslator(), "mandatory" => $config->getMandatory()];
     if ($config->getCreationDate()) {
         $item["creationDate"] = $config->getCreationDate();
     }
     if ($config->getModificationDate()) {
         $item["modificationDate"] = $config->getModificationDate();
     }
     return $item;
 }