| | <?php |
| |
|
| | namespace Kanboard\Model; |
| |
|
| | use Kanboard\Core\Base; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | abstract class SettingModel extends Base |
| | { |
| | |
| | |
| | |
| | |
| | |
| | const TABLE = 'settings'; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | abstract public function prepare(array $values); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | public function getAll() |
| | { |
| | return $this->db->hashtable(self::TABLE)->getAll('option', 'value'); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function getOption($name, $default = '') |
| | { |
| | $value = $this->db |
| | ->table(self::TABLE) |
| | ->eq('option', $name) |
| | ->findOneColumn('value'); |
| |
|
| | return $value === null || $value === false || $value === '' ? $default : $value; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function exists($name) |
| | { |
| | return $this->db |
| | ->table(self::TABLE) |
| | ->eq('option', $name) |
| | ->exists(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function save(array $values) |
| | { |
| | $results = array(); |
| | $values = $this->prepare($values); |
| | $user_id = $this->userSession->getId(); |
| | $timestamp = time(); |
| |
|
| | $this->db->startTransaction(); |
| |
|
| | foreach ($values as $option => $value) { |
| | if ($this->exists($option)) { |
| | $results[] = $this->db->table(self::TABLE)->eq('option', $option)->update(array( |
| | 'value' => $value, |
| | 'changed_on' => $timestamp, |
| | 'changed_by' => $user_id, |
| | )); |
| | } else { |
| | $results[] = $this->db->table(self::TABLE)->insert(array( |
| | 'option' => $option, |
| | 'value' => $value, |
| | 'changed_on' => $timestamp, |
| | 'changed_by' => $user_id, |
| | )); |
| | } |
| | } |
| |
|
| | $this->db->closeTransaction(); |
| |
|
| | return ! in_array(false, $results, true); |
| | } |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function remove($option) |
| | { |
| | return $this->db->table(self::TABLE) |
| | ->eq('option', $option) |
| | ->remove(); |
| | } |
| | } |
| |
|