Passed
Push — more-settings ( 65bbdc )
by Matias
07:33
created

SettingController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 7
dl 0
loc 15
ccs 0
cts 15
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace OCA\FaceRecognition\Controller;
4
5
use OCA\FaceRecognition\Db\FaceMapper;
6
use OCA\FaceRecognition\Db\ImageMapper;
7
use OCA\FaceRecognition\Db\PersonMapper;
8
9
use OCP\AppFramework\Controller;
10
use OCP\AppFramework\Http\JSONResponse;
11
use OCP\IRequest;
12
use OCP\IConfig;
13
14
class SettingController extends Controller {
15
16
	/** @var IConfig */
17
	private $config;
18
19
	/** @var FaceMapper */
20
	private $faceMapper;
21
22
	/** @var ImageMapper */
23
	private $imageMapper;
24
25
	/** @var PersonMapper */
26
	private $personMapper;
27
28
	/** @var string */
29
	private $userId;
30
31
	public function __construct ($appName,
32
	                             IRequest     $request,
33
	                             IConfig      $config,
34
	                             FaceMapper   $faceMapper,
35
	                             ImageMapper  $imageMapper,
36
	                             PersonMapper $personMapper,
37
	                             $userId)
38
	{
39
		parent::__construct($appName, $request);
40
		$this->appName = $appName;
41
		$this->config = $config;
42
		$this->faceMapper = $faceMapper;
43
		$this->imageMapper = $imageMapper;
44
		$this->personMapper = $personMapper;
45
		$this->userId = $userId;
46
	}
47
48
	/**
49
	 * @param $type
50
	 * @param $value
51
	 * @return JSONResponse
52
	 * @throws \OCP\PreConditionNotMetException
53
	 */
54
	public function setAppValue($type, $value) {
55
		$this->config->setAppValue('facerecognition', $type, $value);
56
		$result = [
57
			'success' => 'true',
58
			'value' => $value
59
		];
60
		return new JSONResponse($result);
61
	}
62
63
	/**
64
	 * @param $type
65
	 * @return JSONResponse
66
	 */
67
	public function getAppValue($type) {
68
		$value = $this->config->getAppValue('facerecognition', $type);
69
		if ($value !== '') {
70
			$result = [
71
				'status' => 'success',
72
				'value' => $value
73
			];
74
		} else {
75
			$result = [
76
				'status' => 'false',
77
				'value' =>'nodata'
78
			];
79
		}
80
		$response = new JSONResponse();
81
		$response->setData($result);
82
		return $response;
83
	}
84
85
}
86