diff --git a/library/Director/Data/Db/DbObjectWithSettings.php b/library/Director/Data/Db/DbObjectWithSettings.php index 39cb05fb..eba41f00 100644 --- a/library/Director/Data/Db/DbObjectWithSettings.php +++ b/library/Director/Data/Db/DbObjectWithSettings.php @@ -2,13 +2,18 @@ namespace Icinga\Module\Director\Data\Db; +use Icinga\Module\Director\Db; + abstract class DbObjectWithSettings extends DbObject { + /** @var Db $connection */ + protected $connection; + protected $settingsTable = 'your_table_name'; protected $settingsRemoteId = 'column_pointing_to_main_table_id'; - protected $settings = array(); + protected $settings = []; public function set($key, $value) { @@ -54,15 +59,13 @@ abstract class DbObjectWithSettings extends DbObject public function __unset($key) { if ($this->hasProperty($key)) { - return parent::__unset($key); + parent::__unset($key); } if (array_key_exists($key, $this->settings)) { unset($this->settings[$key]); $this->hasBeenModified = true; } - - return $this; } protected function onStore() @@ -70,9 +73,9 @@ abstract class DbObjectWithSettings extends DbObject $old = $this->fetchSettingsFromDb(); $oldKeys = array_keys($old); $newKeys = array_keys($this->settings); - $add = array(); - $mod = array(); - $del = array(); + $add = []; + $mod = []; + $del = []; $id = $this->get('id'); foreach ($this->settings as $key => $val) { @@ -94,7 +97,7 @@ abstract class DbObjectWithSettings extends DbObject foreach ($mod as $key => $val) { $db->update( $this->settingsTable, - array('setting_value' => $val), + ['setting_value' => $val], $db->quoteInto($where, $key) ); } @@ -102,11 +105,11 @@ abstract class DbObjectWithSettings extends DbObject foreach ($add as $key => $val) { $db->insert( $this->settingsTable, - array( + [ $this->settingsRemoteId => $id, 'setting_name' => $key, 'setting_value' => $val - ) + ] ); } @@ -121,7 +124,7 @@ abstract class DbObjectWithSettings extends DbObject $db = $this->getDb(); return $db->fetchPairs( $db->select() - ->from($this->settingsTable, array('setting_name', 'setting_value')) + ->from($this->settingsTable, ['setting_name', 'setting_value']) ->where($this->settingsRemoteId . ' = ?', $this->get('id')) ); }