summaryrefslogtreecommitdiff
path: root/app/Model/Setting.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-05-28 19:48:22 -0400
committerFrederic Guillot <fred@kanboard.net>2016-05-28 19:48:22 -0400
commit14713b0ec7ed93ca45578da069ad4e19a7d8addf (patch)
tree79972d53f6091a1ddb17f64a6a05a5523f5d5168 /app/Model/Setting.php
parent936376ffe74c583d3cb819e98f53a85137fdf8bc (diff)
Rename all models
Diffstat (limited to 'app/Model/Setting.php')
-rw-r--r--app/Model/Setting.php113
1 files changed, 0 insertions, 113 deletions
diff --git a/app/Model/Setting.php b/app/Model/Setting.php
deleted file mode 100644
index 38af22e0..00000000
--- a/app/Model/Setting.php
+++ /dev/null
@@ -1,113 +0,0 @@
-<?php
-
-namespace Kanboard\Model;
-
-use Kanboard\Core\Base;
-
-/**
- * Application Settings
- *
- * @package model
- * @author Frederic Guillot
- */
-abstract class Setting extends Base
-{
- /**
- * SQL table name
- *
- * @var string
- */
- const TABLE = 'settings';
-
- /**
- * Prepare data before save
- *
- * @abstract
- * @access public
- * @param array $values
- * @return array
- */
- abstract public function prepare(array $values);
-
- /**
- * Get all settings
- *
- * @access public
- * @return array
- */
- public function getAll()
- {
- return $this->db->hashtable(self::TABLE)->getAll('option', 'value');
- }
-
- /**
- * Get a setting value
- *
- * @access public
- * @param string $name
- * @param string $default
- * @return mixed
- */
- public function getOption($name, $default = '')
- {
- $value = $this->db
- ->table(self::TABLE)
- ->eq('option', $name)
- ->findOneColumn('value');
-
- return $value === null || $value === false || $value === '' ? $default : $value;
- }
-
- /**
- * Return true if a setting exists
- *
- * @access public
- * @param string $name
- * @return boolean
- */
- public function exists($name)
- {
- return $this->db
- ->table(self::TABLE)
- ->eq('option', $name)
- ->exists();
- }
-
- /**
- * Update or insert new settings
- *
- * @access public
- * @param array $values
- * @return boolean
- */
- 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);
- }
-}