SettingsService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 44
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A get() 0 13 1
A set() 0 4 1
1
<?php
2
/**
3
 * ownCloud - Tasks
4
 *
5
 * @author Raimund Schlüßler
6
 * @copyright 2017 Raimund Schlüßler <[email protected]>
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
 * License as published by the Free Software Foundation; either
11
 * version 3 of the License, or any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public
19
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
23
namespace OCA\Tasks\Service;
24
25
use OCP\IConfig;
26
27
class SettingsService {
28
29
	private $userId;
30
	private $settings;
31
	private $appName;
32
33
	public function __construct($userId, IConfig $settings, $appName) {
34
		$this->userId = $userId;
35
		$this->settings = $settings;
36
		$this->appName = $appName;
37
	}
38
39
	/**
40
	 * get the current settings
41
	 *
42
	 * @return array
43
	 */
44
	public function get() {
45
		$settings = array(
46
			array(
47
				'id' => 'various',
48
				'showHidden' => (int)$this->settings->getUserValue($this->userId, $this->appName,'various_showHidden'),
49
				'startOfWeek' => (int)$this->settings->getUserValue($this->userId, $this->appName,'various_startOfWeek'),
50
				'sortOrder' => (string)$this->settings->getUserValue($this->userId, $this->appName,'various_sortOrder'),
51
				'sortDirection' => (bool)$this->settings->getUserValue($this->userId, $this->appName,'various_sortDirection'),
52
				'userID' => $this->userId
53
			)
54
		);
55
		return $settings;
56
	}
57
58
	/**
59
	 * set setting of type to new value
60
	 *
61
	 * @param $setting
62
	 * @param $type
63
	 * @param $value
64
	 * @return bool
65
	 */
66
	public function set($setting, $type, $value) {
67
		$this->settings->setUserValue($this->userId, $this->appName, $type.'_'.$setting, $value);
68
		return true;
69
	}
70
}
71