/** * Save a group */ public function save() { $blueprints = new Blueprints('blueprints://'); $blueprint = $blueprints->get('user/group'); $fields = $blueprint->fields(); self::getGrav()['config']->set("groups.{$this->groupname}", []); foreach ($fields as $field) { if ($field['type'] == 'text') { $value = $field['name']; if (isset($this->items[$value])) { self::getGrav()['config']->set("groups.{$this->groupname}.{$value}", $this->items[$value]); } } if ($field['type'] == 'array') { $value = $field['name']; $arrayValues = Utils::resolve($this->items, $field['name']); if ($arrayValues) { foreach ($arrayValues as $arrayIndex => $arrayValue) { self::getGrav()['config']->set("groups.{$this->groupname}.{$value}.{$arrayIndex}", $arrayValue); } } } } $type = 'groups'; $blueprints = $this->blueprints("config/{$type}"); $obj = new Data(self::getGrav()['config']->get($type), $blueprints); $file = CompiledYamlFile::instance(self::getGrav()['locator']->findResource("config://{$type}.yaml")); $obj->file($file); $obj->save(); }
/** * Checks user authorization to the action. * * @param string $action * * @return bool */ public function authorize($action) { if (empty($this->items)) { return false; } if (isset($this->state) && $this->state !== 'enabled') { return false; } $return = false; //Check group access level $groups = $this->get('groups'); if ($groups) { foreach ((array) $groups as $group) { $permission = self::getGrav()['config']->get("groups.{$group}.access.{$action}"); $return = Utils::isPositive($permission); if ($return === true) { break; } } } //Check user access level if ($this->get('access')) { if (Utils::resolve($this->get('access'), $action) !== null) { $permission = $this->get("access.{$action}"); $return = Utils::isPositive($permission); } } return $return; }
public function testResolve() { $array = ['test' => ['test2' => 'test2Value']]; $this->assertEquals('test2Value', Utils::resolve($array, 'test.test2')); }