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){ |
|
68 | 3 | ||
69 | |||
70 | /** |
||
71 | * Used to get a single note by id |
||
72 | * @param int $id the id of the note to get |
||
73 | * @param string $userId |
||
74 | * @throws NoteDoesNotExistException if note does not exist |
||
75 | * @return Note |
||
76 | */ |
||
77 | public function get ($id, $userId) { |
||
81 | |||
82 | |||
83 | /** |
||
84 | * Creates a note and returns the empty note |
||
85 | 2 | * @param string $userId |
|
86 | 2 | * @see update for setting note content |
|
87 | * @return Note the newly created note |
||
88 | 2 | */ |
|
89 | public function create ($userId) { |
||
101 | 2 | ||
102 | 2 | ||
103 | 2 | /** |
|
104 | * Updates a note. Be sure to check the returned note since the title is |
||
105 | * dynamically generated and filename conflicts are resolved |
||
106 | 2 | * @param int $id the id of the note used to update |
|
107 | 2 | * @param string $content the content which will be written into the note |
|
108 | * the title is generated from the first line of the content |
||
109 | 2 | * @throws NoteDoesNotExistException if note does not exist |
|
110 | 1 | * @return \OCA\Notes\Db\Note the updated note |
|
111 | 1 | */ |
|
112 | public function update ($id, $content, $userId){ |
||
147 | 3 | ||
148 | 1 | ||
149 | 1 | /** |
|
150 | * Set or unset a note as favorite. |
||
151 | * @param int $id the id of the note used to update |
||
152 | * @param boolean $favorite whether the note should be a favorite or not |
||
153 | * @throws NoteDoesNotExistException if note does not exist |
||
154 | * @return boolean the new favorite state of the note |
||
155 | */ |
||
156 | public function favorite ($id, $favorite, $userId){ |
||
171 | |||
172 | |||
173 | 11 | /** |
|
174 | 11 | * Deletes a note |
|
175 | 11 | * @param int $id the id of the note which should be deleted |
|
176 | 11 | * @param string $userId |
|
177 | 11 | * @throws NoteDoesNotExistException if note does not |
|
178 | * exist |
||
179 | */ |
||
180 | 11 | public function delete ($id, $userId) { |
|
185 | |||
186 | |||
187 | /** |
||
188 | * @param Folder $folder |
||
189 | * @param int $id |
||
190 | * @throws NoteDoesNotExistException |
||
191 | * @return \OCP\Files\File |
||
192 | */ |
||
193 | private function getFileById ($folder, $id) { |
||
206 | 3 | ||
207 | 3 | ||
208 | 3 | /** |
|
209 | 3 | * @param string $userId the user id |
|
210 | 3 | * @return Folder |
|
211 | 3 | */ |
|
212 | 3 | private function getFolderForUser ($userId) { |
|
221 | |||
222 | |||
223 | /** |
||
224 | 7 | * get path of file and the title.txt and check if they are the same |
|
225 | 7 | * file. If not the title needs to be renamed |
|
226 | * |
||
227 | 7 | * @param Folder $folder a folder to the notes directory |
|
228 | 7 | * @param string $title the filename which should be used |
|
229 | 7 | * @param string $extension the extension which should be used |
|
230 | * @param int $id the id of the note for which the title should be generated |
||
231 | 7 | * used to see if the file itself has the title and not a different file for |
|
232 | * checking for filename collisions |
||
233 | 5 | * @return string the resolved filename to prevent overwriting different |
|
234 | * files with the same title |
||
235 | */ |
||
236 | private function generateFileName (Folder $folder, $title, $extension, $id) { |
||
256 | |||
257 | /** |
||
258 | * test if file is a note |
||
259 | * |
||
260 | * @param \OCP\Files\File $file |
||
261 | * @return bool |
||
262 | */ |
||
263 | private function isNote($file) { |
||
274 | |||
275 | } |
||
276 |