mirror of
https://github.com/JanGross/quicknotes.git
synced 2025-12-01 07:37:18 +01:00
Implement create new note with tags.
This commit is contained in:
@@ -180,7 +180,6 @@ class NoteService {
|
|||||||
$hcolor = $this->colormapper->insert($hcolor);
|
$hcolor = $this->colormapper->insert($hcolor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Create note and insert it
|
// Create note and insert it
|
||||||
$note = new Note();
|
$note = new Note();
|
||||||
|
|
||||||
@@ -195,10 +194,31 @@ class NoteService {
|
|||||||
|
|
||||||
// TODO: Insert optional shares, tags and attachments.
|
// TODO: Insert optional shares, tags and attachments.
|
||||||
|
|
||||||
|
// Add new tags and update relations.
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
if (!$this->tagmapper->tagExists($userId, $tag['name'])) {
|
||||||
|
$htag = new Tag();
|
||||||
|
$htag->setName($tag['name']);
|
||||||
|
$htag->setUserId($userId);
|
||||||
|
$htag = $this->tagmapper->insert($htag);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$htag = $this->tagmapper->getTag($userId, $tag['name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->notetagmapper->noteTagExists($userId, $newNote->getId(), $htag->getId())) {
|
||||||
|
$noteTag = new NoteTag();
|
||||||
|
$noteTag->setNoteId($newNote->getId());
|
||||||
|
$noteTag->setTagId($htag->getId());
|
||||||
|
$noteTag->setUserId($userId);
|
||||||
|
$this->notetagmapper->insert($noteTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Insert true color pin and tags to response
|
// Insert true color pin and tags to response
|
||||||
$newNote->setColor($hcolor->getColor());
|
$newNote->setColor($hcolor->getColor());
|
||||||
$newNote->setIsPinned($isPinned);
|
$newNote->setIsPinned($isPinned);
|
||||||
$newNote->setTags([]);
|
$newNote->setTags($this->tagmapper->getTagsForNote($userId, $newNote->getId()));
|
||||||
$newNote->setAttachts([]);
|
$newNote->setAttachts([]);
|
||||||
|
|
||||||
return $newNote;
|
return $newNote;
|
||||||
|
|||||||
Reference in New Issue
Block a user