Failed Conditions
Pull Request — master (#6)
by Sander
01:53
created

controller/ownnoteajaxcontroller.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Nextcloud - ownnote
4
 *
5
 * @copyright Copyright (c) 2015, Ben Curtis <[email protected]>
6
 * @copyright Copyright (c) 2017, Sander Brand ([email protected])
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\OwnNote\Controller;
25
26
use OC\User\Manager;
27
use OCA\OwnNote\Db\OwnNote;
28
use OCA\OwnNote\Service\OwnNoteGroupService;
29
use OCA\OwnNote\Service\OwnNoteService;
30
use \OCP\AppFramework\ApiController;
31
use \OCP\AppFramework\Http\JSONResponse;
32
use \OCP\AppFramework\Http\Response;
33
use \OCP\AppFramework\Http;
34
use OCP\IConfig;
35
use OCP\ILogger;
36
use \OCP\IRequest;
37
use \OCA\OwnNote\Lib\Backend;
38
use \OCP\App;
39
40
41
class OwnnoteAjaxController extends ApiController {
42
43
	private $backend;
44
	private $config;
45
	private $noteService;
46
	private $uid;
47
	private $noteGroupService;
48
49 View Code Duplication
	public function __construct($appName, IRequest $request, ILogger $logger, IConfig $config, OwnNoteService $noteService, OwnNoteGroupService $groupService) {
1 ignored issue
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
		parent::__construct($appName, $request);
51
		$this->config = $config;
52
		$this->noteService = $noteService;
53
		$this->backend = new Backend($config);
54
		$this->noteGroupService = $groupService;
55
		$this->uid = \OC::$server->getUserSession()->getUser()->getUID();
56
	}
57
58
	/**
59
	 * AJAX FUNCTIONS
60
	 */
61
62
	/**
63
	 * @NoAdminRequired
64
	 * @NoCSRFRequired
65
	 */
66
	public function ajaxindex() {
67
		$FOLDER = $this->config->getAppValue($this->appName, 'folder', '');
68
		return $this->noteService->getListing($FOLDER, false);
69
	}
70
71
72
	/**
73
	 * @NoAdminRequired
74
	 */
75 View Code Duplication
	public function ajaxcreate($name, $group) {
1 ignored issue
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
		$FOLDER = $this->config->getAppValue($this->appName, 'folder', '');
77
		if (isset($name) && isset($group)) {
78
			$note = [
79
				'name' => $name,
80
				'group' => $group
81
			];
82
			return $this->noteService->create($FOLDER, $note, $this->uid);
83
		}
84
	}
85
86
	/**
87
	 * @NoAdminRequired
88
	 */
89
	public function ajaxdel($nid) {
90
		$FOLDER = $this->config->getAppValue($this->appName, 'folder', '');
91
		if (isset($nid)) {
92
			return $this->noteService->delete($FOLDER, $nid);
93
		}
94
	}
95
96
	/**
97
	 * @NoAdminRequired
98
	 */
99
	public function ajaxedit($nid) {
100
		if (isset($nid)) {
101
			/**
102
			 * @param OwnNote $note
103
			 */
104
			$note = $this->noteService->find($nid);
105
			if($note) {
106
				return $note->getNote();
107
			}
108
			return '';
109
		}
110
	}
111
112
	/**
113
	 * @NoAdminRequired
114
	 */
115
	public function ajaxsave($id, $content) {
116
		$FOLDER = $this->config->getAppValue($this->appName, 'folder', '');
117
		if (isset($id) && isset($content)) {
118
			$note = [
119
				'id' => $id,
120
				'note' => $content
121
			];
122
123
			return ($this->noteService->update($FOLDER, $note));
124
		}
125
	}
126
127
	/**
128
	 * @NoAdminRequired
129
	 */
130
	public function ajaxren($id, $newname, $newgroup) {
131
		$FOLDER = $this->config->getAppValue($this->appName, 'folder', '');
132 View Code Duplication
		if (isset($id) && isset($newname) && isset($newgroup))
133
			return $this->noteService->renameNote($FOLDER, $id, $newname, $newgroup, $this->uid);
134
	}
135
136
	/**
137
	 * @NoAdminRequired
138
	 */
139
	public function ajaxdelgroup($group) {
140
		$FOLDER = $this->config->getAppValue($this->appName, 'folder', '');
141
		if (isset($group))
142
			return $this->noteGroupService->deleteGroup($FOLDER, $group);
143
	}
144
145
	/**
146
	 * @NoAdminRequired
147
	 */
148
	public function ajaxrengroup($group, $newgroup) {
149
		$FOLDER = $this->config->getAppValue($this->appName, 'folder', '');
150
		if (isset($group) && isset($newgroup))
151
			return $this->noteGroupService->renameGroup($FOLDER, $group, $newgroup);
152
	}
153
154
	/**
155
	 * @NoAdminRequired
156
	 */
157
	public function ajaxversion() {
158
		$AppInstance = new App();
159
		return $AppInstance->getAppInfo($this->appName)["version"];
160
	}
161
162
	/**
163
	 */
164
	public function ajaxsetval($field, $value) {
165
		$this->config->setAppValue($this->appName, $field, $value);
166
		return true;
167
	}
168
169
	/**
170
	 * @NoAdminRequired
171
	 * @NoCSRFRequired
172
	 */
173
	public function ajaxgetsharemode() {
174
		return $this->config->getAppValue($this->appName, 'sharemode', '');
175
	}
176
}
177