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

controller/ownnoteapicontroller.php (3 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\Service\OwnNoteGroupService;
28
use OCA\OwnNote\Service\OwnNoteService;
29
use \OCP\AppFramework\ApiController;
30
use \OCP\App;
31
use OCP\IConfig;
32
use OCP\ILogger;
33
use \OCP\IRequest;
34
use \OCA\OwnNote\Lib\Backend;
35
36
37
class OwnnoteApiController extends ApiController {
38
39
	private $backend;
40
	private $config;
41
	private $noteService;
42
	private $noteGroupService;
43
	private $uid;
44
45 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...
46
		parent::__construct($appName, $request);
47
		$this->backend = new Backend($config);
48
		$this->config = $config;
49
		$this->appName = $appName;
50
		$this->noteService = $noteService;
51
		$this->noteGroupService = $groupService;
52
		$this->uid = \OC::$server->getUserSession()->getUser()->getUID();
53
	}
54
55
	/**
56
	* MOBILE FUNCTIONS
57
	*/
58
59
	/**
60
	* @NoAdminRequired
61
	* @NoCSRFRequired
62
	*/
63
	public function index() {
64
		$FOLDER = $this->config->getAppValue($this->appName, 'folder', '');
65
		return $this->noteService->getListing($FOLDER, false);
66
	}
67
68
	/**
69
	* @NoAdminRequired
70
	* @NoCSRFRequired
71
	*/
72
	public function mobileindex() {
73
		$FOLDER = $this->config->getAppValue($this->appName, 'folder', '');
74
		return $this->noteService->getListing($FOLDER, true);
75
	}
76
77
	/**
78
	* @NoAdminRequired
79
	* @NoCSRFRequired
80
	*/
81
	public function remoteindex() {
82
		$FOLDER = $this->config->getAppValue($this->appName, 'folder', '');
83
		return $this->noteService->getListing($FOLDER, true);
84
	}
85
86
	/**
87
	* @NoAdminRequired
88
	* @NoCSRFRequired
89
	*/
90 View Code Duplication
	public function create($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...
91
		$FOLDER = $this->config->getAppValue($this->appName, 'folder', '');
92
		if (isset($name) && isset($group)) {
93
			$note = [
94
				'name' => $name,
95
				'group' => $group
96
			];
97
			return $this->noteService->create($FOLDER, $note, $this->uid);
98
		}
99
	}
100
101
	/**
102
	* @NoAdminRequired
103
	* @NoCSRFRequired
104
	*/
105
	public function del($nid) {
106
		$FOLDER = $this->config->getAppValue($this->appName, 'folder', '');
107
		if (isset($nid))
108
			return $this->noteService->delete($FOLDER, $nid);
109
	}
110
111
	/**
112
	* @NoAdminRequired
113
	* @NoCSRFRequired
114
	*/
115
	public function edit($id) {
116
		if (isset($id)) {
117
			/**
118
			 * @param OwnNote $note
119
			 */
120
			$note = $this->noteService->find($id);
121
			return $note->getNote();
122
		}
123
	}
124
125
	/**
126
	* @NoAdminRequired
127
	* @NoCSRFRequired
128
	*/
129 View Code Duplication
	public function save($id, $content) {
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...
130
		$FOLDER = $this->config->getAppValue($this->appName, 'folder', '');
131
		if (isset($id) && isset($content)) {
132
			$note = [
133
				'id' => $id,
134
				'note' => $content,
135
				'mtime' => time()
136
			];
137
138
			return ($this->noteService->update($FOLDER, $note));
139
		}
140
	}
141
142
	/**
143
	* @NoAdminRequired
144
	* @NoCSRFRequired
145
	*/
146
	public function ren($id, $newname, $newgroup) {
147
		$FOLDER = $this->config->getAppValue($this->appName, 'folder', '');
148 View Code Duplication
		if (isset($id) && isset($newname) && isset($newgroup))
149
			return $this->noteService->renameNote($FOLDER, $id, $newname, $newgroup);
150
	}
151
152
	/**
153
	* @NoAdminRequired
154
	* @NoCSRFRequired
155
	*/
156
	public function delgroup($group) {
157
		$FOLDER = $this->config->getAppValue($this->appName, 'folder', '');
158
		if (isset($group))
159
			return $this->noteGroupService->deleteGroup($FOLDER, $group);
160
	}
161
162
	/**
163
	* @NoAdminRequired
164
	* @NoCSRFRequired
165
	*/
166
	public function rengroup($group, $newgroup) {
167
		$FOLDER = $this->config->getAppValue($this->appName, 'folder', '');
168
		if (isset($group) && isset($newgroup))
169
			return $this->noteGroupService->renameGroup($FOLDER, $group, $newgroup);
170
	}
171
172
	/**
173
	* @NoAdminRequired
174
	* @NoCSRFRequired
175
	*/
176
	public function version() {
177
		$AppInstance = new App();
178
		return $AppInstance->getAppInfo($this->appName)["version"];
179
	}
180
}
181