save() public method

Saves the group config
public save ( )
Exemplo n.º 1
0
 public function addgroupAction()
 {
     $name = $this->getParam("name");
     $alreadyExist = false;
     $config = KeyValue\GroupConfig::getByName($name);
     if (!$config) {
         $config = new KeyValue\GroupConfig();
         $config->setName($name);
         $config->save();
     }
     $this->_helper->json(["success" => !$alreadyExist, "id" => $config->getName()]);
 }
Exemplo n.º 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();
         }
     }
 }