Completed
Pull Request — master (#93)
by Janis
13:30
created

AdminSettingsController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 53
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getSettings() 0 5 1
A setSettings() 0 10 2
1
<?php
2
3
/**
4
 * Nextcloud - OCR
5
 *
6
 * This file is licensed under the Affero General Public License version 3 or
7
 * later. See the COPYING file.
8
 *
9
 * @author Janis Koehr <[email protected]>
10
 * @copyright Janis Koehr 2017
11
 */
12
namespace OCA\Ocr\Controller;
13
14
use OCP\AppFramework\Controller;
15
use OCP\IRequest;
16
use OCP\IL10N;
17
use OCA\Ocr\Config\AppConfig;
18
use OCP\AppFramework\Http\DataResponse;
19
use OCA\Ocr\Service\AppConfigService;
20
use OCA\Ocr\Service\NotFoundException;
21
22
class AdminSettingsController extends Controller {
23
	
24
	/** @var IL10N */
25
	private $l10n;
26
	
27
	/** @var AppConfigService */
28
	private $appConfig;
29
	
30
	use Errors;
31
	
32
	/**
33
	 * Constructor
34
	 *
35
	 * @param string $appName        	
36
	 * @param IRequest $request        	
37
	 * @param IL10N $l10n        	
38
	 * @param AppConfigService $appConfig        	
39
	 * @param string $userId        	
40
	 */
41
	public function __construct($appName, IRequest $request, IL10N $l10n, AppConfigService $appConfig, $userId) {
42
		parent::__construct ( $appName, $request );
43
		$this->l10n = $l10n;
44
		$this->appConfig = $appConfig;
45
	}
46
	
47
	/**
48
	 * @NoAdminRequired
49
	 *
50
	 * @return DataResponse
51
	 */
52
	public function getSettings() {
53
		return $this->handleNotFound ( function () {
54
			return [ 'languages' => $this->appConfig->getAppValue ( 'languages' )];
55
		} );
56
	}
57
	
58
	/**
59
	 * Sets the languages that are supported by the docker worker instance.
60
	 *
61
	 * @param string $languages        	
62
	 * @return DataResponse
63
	 */
64
	public function setSettings($languages) {
65
		return $this->handleNotFound ( function () use ($languages) {
66
			if ($languages !== null) {
67
				$this->appConfig->setAppValue ( 'languages', $languages );
68
				return $this->l10n->t ( 'Saved' );
69
			} else {
70
				throw new NotFoundException ( $this->l10n->t ( 'The languages are not specified in the correct format.' ) );
71
			}
72
		} );
73
	}
74
}