1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Nextcloud - namespace OCA\Nextnote |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2016, Sander Brand ([email protected]) |
6
|
|
|
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([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\NextNote\Service; |
25
|
|
|
|
26
|
|
|
use OCA\NextNote\Db\Notebook; |
27
|
|
|
use OCA\NextNote\Db\Note; |
28
|
|
|
use OCA\NextNote\Fixtures\ShareFix; |
29
|
|
|
use OCA\NextNote\ShareBackend\NextNoteShareBackend; |
30
|
|
|
use OCA\NextNote\Utility\Utils; |
31
|
|
|
use OCA\NextNote\Db\NoteMapper; |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
class NoteService { |
35
|
|
|
|
36
|
|
|
private $noteMapper; |
37
|
|
|
private $utils; |
38
|
|
|
private $sharing; |
39
|
|
|
private $groupService; |
40
|
|
|
|
41
|
|
|
public function __construct(NoteMapper $noteMapper, Utils $utils, NextNoteShareBackend $shareBackend, NotebookService $groupService) { |
42
|
|
|
$this->noteMapper = $noteMapper; |
43
|
|
|
$this->utils = $utils; |
44
|
|
|
$this->sharing = $shareBackend; |
45
|
|
|
$this->groupService = $groupService; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get vaults from a user. |
50
|
|
|
* |
51
|
|
|
* @param $userId |
52
|
|
|
* @param int|bool $deleted |
53
|
|
|
* @param string|bool $grouping |
54
|
|
|
* @return Note[] |
55
|
|
|
*/ |
56
|
|
|
public function findNotesFromUser($userId, $deleted = false, $grouping = false) { |
57
|
|
|
// Get shares |
58
|
|
|
|
59
|
|
|
$dbNotes = $this->noteMapper->findNotesFromUser($userId, $deleted, $grouping); |
60
|
|
|
$sharedNotes = $this->sharing->getSharedNotes(); |
61
|
|
|
$notes = array_merge($dbNotes, $sharedNotes); |
62
|
|
|
return $notes; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get a single vault |
67
|
|
|
* |
68
|
|
|
* @param $note_id |
69
|
|
|
* @param $user_id |
70
|
|
|
* @param bool|int $deleted |
71
|
|
|
* @return Note |
72
|
|
|
* @internal param $vault_id |
73
|
|
|
*/ |
74
|
|
|
public function find($note_id, $user_id = null, $deleted = false) { |
75
|
|
|
$note = $this->noteMapper->find($note_id, $user_id, $deleted); |
76
|
|
|
return $note; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Creates a note |
81
|
|
|
* |
82
|
|
|
* @param Note $note |
83
|
|
|
* @return Note |
84
|
|
|
* @throws \Exception |
85
|
|
|
*/ |
86
|
|
|
public function create(Note $note) { |
87
|
|
|
if (!$note instanceof Note) { |
88
|
|
|
throw new \Exception("Expected Note object!"); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return $this->noteMapper->insert($note); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Update vault |
96
|
|
|
* |
97
|
|
|
* @param $note Note |
98
|
|
|
* @return Note|bool |
99
|
|
|
* @throws \Exception |
100
|
|
|
* @internal param $userId |
101
|
|
|
* @internal param $vault |
102
|
|
|
*/ |
103
|
|
|
public function update(Note $note) { |
104
|
|
|
if (!$note instanceof Note) { |
105
|
|
|
throw new \Exception("Expected Note object!"); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return $this->noteMapper->updateNote($note); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Delete a vault from user |
113
|
|
|
* |
114
|
|
|
* @param $note_id |
115
|
|
|
* @param string $user_id |
116
|
|
|
* @return bool |
117
|
|
|
* @internal param string $vault_guid |
118
|
|
|
*/ |
119
|
|
|
public function delete($note_id, $user_id = null) { |
120
|
|
|
$note = $this->noteMapper->find($note_id, $user_id); |
121
|
|
|
if ($note instanceof Note) { |
122
|
|
|
$this->noteMapper->deleteNote($note); |
123
|
|
|
return true; |
124
|
|
|
} else { |
125
|
|
|
return false; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param $FOLDER |
132
|
|
|
* @param boolean $showdel |
133
|
|
|
* @return array |
134
|
|
|
* @throws \Exception |
135
|
|
|
*/ |
136
|
|
|
public function getListing($FOLDER, $showdel) { |
137
|
|
|
throw new \Exception('Calling a deprecated method! (Folder' . $FOLDER . '. Showdel: ' . $showdel . ')'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
} |
141
|
|
|
|