From e556fbed49264b59639c3d2d77150188fdabc3c9 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 1 Dec 2017 23:54:17 +0100 Subject: [PATCH] Implement admin controller api test --- Config/OptionsTrait.php | 2 +- Config/SettingsAbstract.php | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Config/OptionsTrait.php b/Config/OptionsTrait.php index f6c6a62ba..e3a9e4390 100644 --- a/Config/OptionsTrait.php +++ b/Config/OptionsTrait.php @@ -56,7 +56,7 @@ trait OptionsTrait */ public function setOption($key, $value, bool $overwrite = true) : bool { - if ($overwrite || !array_key_exists($key, $this->options)) { + if ($overwrite || !isset($this->options[$key])) { $this->options[$key] = $value; return true; diff --git a/Config/SettingsAbstract.php b/Config/SettingsAbstract.php index 8d3f5ac00..c44f74d9d 100644 --- a/Config/SettingsAbstract.php +++ b/Config/SettingsAbstract.php @@ -84,6 +84,7 @@ abstract class SettingsAbstract implements OptionsInterface * @return mixed Option value * * @since 1.0.0 + * @todo: don't db request if exists. check exists() */ public function get($columns) { @@ -110,7 +111,7 @@ abstract class SettingsAbstract implements OptionsInterface break; } - return $options; + return count($options) > 1 ? $options : reset($options); } catch (\PDOException $e) { $exception = DatabaseExceptionFactory::createException($e); $message = DatabaseExceptionFactory::createExceptionMessage($e); @@ -134,7 +135,16 @@ abstract class SettingsAbstract implements OptionsInterface $this->setOptions($options); if ($store) { - // save to db + foreach($this->options as $key => $option) { + $query = new Builder($this->connection); + $sql = $query->update($this->connection->prefix . static::$table) + ->set([static::$columns[1] => $option]) + ->where(static::$columns[0], '=', $key) + ->toSql(); + + $sth = $this->connection->con->prepare($sql); + $sth->execute(); + } } } }