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

SettingsController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 0
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