1 | <?php |
||
25 | class NotesService { |
||
26 | |||
27 | private $l10n; |
||
28 | private $root; |
||
29 | |||
30 | /** |
||
31 | * @param IRootFolder $root |
||
32 | * @param IL10N $l10n |
||
33 | */ |
||
34 | 11 | public function __construct (IRootFolder $root, IL10N $l10n) { |
|
38 | |||
39 | |||
40 | /** |
||
41 | * @param string $userId |
||
42 | * @return array with all notes in the current directory |
||
43 | */ |
||
44 | 1 | public function getAll ($userId){ |
|
45 | 1 | $folder = $this->getFolderForUser($userId); |
|
46 | 1 | $files = $folder->getDirectoryListing(); |
|
47 | 1 | $notes = []; |
|
48 | |||
49 | 1 | foreach($files as $file) { |
|
50 | 1 | if($this->isNote($file)) { |
|
51 | 1 | $notes[] = Note::fromFile($file); |
|
52 | 1 | } |
|
53 | 1 | } |
|
54 | |||
55 | 1 | return $notes; |
|
56 | } |
||
57 | |||
58 | |||
59 | /** |
||
60 | * Used to get a single note by id |
||
61 | * @param int $id the id of the note to get |
||
62 | * @param string $userId |
||
63 | * @throws NoteDoesNotExistException if note does not exist |
||
64 | * @return Note |
||
65 | */ |
||
66 | 3 | public function get ($id, $userId) { |
|
70 | |||
71 | |||
72 | /** |
||
73 | * Creates a note and returns the empty note |
||
74 | * @param string $userId |
||
75 | * @see update for setting note content |
||
76 | * @return Note the newly created note |
||
77 | */ |
||
78 | 2 | public function create ($userId) { |
|
90 | |||
91 | |||
92 | /** |
||
93 | * Updates a note. Be sure to check the returned note since the title is |
||
94 | * dynamically generated and filename conflicts are resolved |
||
95 | * @param int $id the id of the note used to update |
||
96 | * @param string $content the content which will be written into the note |
||
97 | * the title is generated from the first line of the content |
||
98 | * @throws NoteDoesNotExistException if note does not exist |
||
99 | * @return \OCA\Notes\Db\Note the updated note |
||
100 | */ |
||
101 | 2 | public function update ($id, $content, $userId){ |
|
138 | |||
139 | |||
140 | /** |
||
141 | * Deletes a note |
||
142 | * @param int $id the id of the note which should be deleted |
||
143 | * @param string $userId |
||
144 | * @throws NoteDoesNotExistException if note does not |
||
145 | * exist |
||
146 | */ |
||
147 | 3 | public function delete ($id, $userId) { |
|
152 | |||
153 | |||
154 | /** |
||
155 | * @param Folder $folder |
||
156 | * @param int $id |
||
157 | * @throws NoteDoesNotExistException |
||
158 | * @return \OCP\Files\File |
||
159 | */ |
||
160 | 8 | private function getFileById ($folder, $id) { |
|
169 | |||
170 | |||
171 | /** |
||
172 | * @param string $userId the user id |
||
173 | * @return Folder |
||
174 | */ |
||
175 | 11 | private function getFolderForUser ($userId) { |
|
184 | |||
185 | |||
186 | /** |
||
187 | * get path of file and the title.txt and check if they are the same |
||
188 | * file. If not the title needs to be renamed |
||
189 | * |
||
190 | * @param Folder $folder a folder to the notes directory |
||
191 | * @param string $title the filename which should be used |
||
192 | * @param string $extension the extension which should be used |
||
193 | * @param int $id the id of the note for which the title should be generated |
||
194 | * used to see if the file itself has the title and not a different file for |
||
195 | * checking for filename collisions |
||
196 | * @return string the resolved filename to prevent overwriting different |
||
197 | * files with the same title |
||
198 | */ |
||
199 | 4 | private function generateFileName (Folder $folder, $title, $extension, $id) { |
|
219 | |||
220 | /** |
||
221 | * test if file is a note |
||
222 | * |
||
223 | * @param \OCP\Files\File $file |
||
224 | * @return bool |
||
225 | */ |
||
226 | 7 | private function isNote($file) { |
|
237 | |||
238 | } |
||
239 |