Completed
Push — antivirus-update ( fcda38...b6d85d )
by Victor
08:14
created

SettingsController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A index() 0 4 1
A save() 0 20 1
1
<?php
2
/**
3
 * Copyright (c) 2015 Victor Dubiniuk <[email protected]>
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later.
6
 * See the COPYING-README file.
7
 */
8
9
namespace OCA\Files_Antivirus\Controller;
10
11
use \OCP\AppFramework\Controller;
12
use \OCP\IRequest;
13
use \OCP\IL10N;
14
use \OCA\Files_Antivirus\AppConfig;
15
16
use \OCP\AppFramework\Http\TemplateResponse;
17
use \OCP\AppFramework\Http\JSONResponse;
18
19
class SettingsController extends Controller {
20
21
	/**
22
	 * @var AppConfig
23
	 */
24
	private $settings;
25
	
26
	/**
27
	 * @var IL10N
28
	 */
29
	private $l10n;
30
	
31
	public function __construct(IRequest $request, AppConfig $appconfig, IL10N $l10n) {
32
		$this->settings = $appconfig;
33
		$this->l10n = $l10n;
34
	}
35
	
36
	/**
37
	 * Print config section
38
	 * @return TemplateResponse
39
	 */
40
	public function index() {
41
		$data = $this->settings->getAllValues();
42
		return new TemplateResponse('files_antivirus', 'settings', $data, 'blank');
43
	}
44
	
45
	/**
46
	 * Save Parameters
47
	 * @param string $avMode - antivirus mode
48
	 * @param string $avSocket - path to socket (Socket mode)
49
	 * @param string $avHost - antivirus url
50
	 * @param int $avPort - port
51
	 * @param string $avCmdOptions - extra command line options
52
	 * @param int $avChunkSize - Size of one portion
53
	 * @param string $avPath - path to antivirus executable (Executable mode)
54
	 * @param string $avInfectedAction - action performed on infected files
55
	 * @return JSONResponse
56
	 */
57
	public function save($avMode, $avSocket, $avHost, $avPort, $avCmdOptions, $avChunkSize, $avPath, $avInfectedAction) {
58
		$this->settings->setAvMode($avMode);
59
		$this->settings->setAvSocket($avSocket);
60
		$this->settings->setAvHost($avHost);
61
		$this->settings->setAvPort($avPort);
62
		$this->settings->setAvCmdOptions($avCmdOptions);
63
		$this->settings->setAvChunkSize($avChunkSize);
64
		$this->settings->setAvPath($avPath);
65
		$this->settings->setAvInfectedAction($avInfectedAction);
66
		
67
		return new JSONResponse(
68
			array('data' =>
69
				array('message' =>
70
					(string) $this->l10n->t('Saved')
71
				),
72
				'status' => 'success',
73
				'settings' => $this->settings->getAllValues()
74
			)
75
		);
76
	}
77
}
78