getByName() public static method

public static getByName ( $name ) : GroupConfig
$name
return GroupConfig
示例#1
0
 public function getgroupAction()
 {
     $id = $this->getParam("id");
     $config = KeyValue\GroupConfig::getByName($id);
     $data = ["id" => $id, "name" => $config->getName(), "description" => $config->getDescription()];
     $this->_helper->json($data);
 }
示例#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 $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);
 }