Missiong update on note in grid, but now you can create tags in the modal.. =)

This commit is contained in:
Matias De lellis
2019-11-12 00:10:03 -03:00
parent 0192faae16
commit 9bf99436bc
5 changed files with 75 additions and 11 deletions

View File

@@ -8,7 +8,7 @@ use OCP\AppFramework\Db\Entity;
class NoteTag extends Entity implements JsonSerializable {
protected $noteId;
protected $tagId
protected $tagId;
protected $userId;
public function jsonSerialize() {

View File

@@ -7,7 +7,7 @@ use OCP\AppFramework\Db\Mapper;
class NoteTagMapper extends Mapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'quicknotes_note_tags', '\OCA\QuickNotes\Db\Tag');
parent::__construct($db, 'quicknotes_note_tags', '\OCA\QuickNotes\Db\NoteTag');
}
public function find($id, $userId) {
@@ -20,4 +20,19 @@ class NoteTagMapper extends Mapper {
return $this->findEntities($sql, [$userId]);
}
public function findNoteTag($userId, $noteId, $tagId) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_note_tags WHERE user_id = ? AND note_id = ? AND tag_id = ?';
return $this->findEntity($sql, [$userId, $noteId, $tagId]);
}
public function noteTagExists($userId, $noteId, $tagId) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_note_tags WHERE user_id = ? AND note_id = ? AND tag_id = ?';
try {
return $this->findEntities($sql, [$userId, $noteId, $tagId]);
} catch (DoesNotExistException $e) {
return false;
}
return true;
}
}

View File

@@ -20,12 +20,27 @@ class TagMapper extends Mapper {
return $this->findEntities($sql, [$userId]);
}
public function getTagsForNote ($noteId) {
public function getTagsForNote($userId, $noteId) {
$sql = 'SELECT T.id, T.name FROM *PREFIX*quicknotes_tags T ';
$sql.= 'INNER JOIN *PREFIX*quicknotes_note_tags NT ';
$sql.= 'ON T.id = NT.tag_id ';
$sql.= 'WHERE NT.note_id = ?';
return $this->findEntities($sql, [$noteId]);
$sql.= 'WHERE NT.user_id = ? AND NT.note_id = ?';
return $this->findEntities($sql, [$userId, $noteId]);
}
public function getTag($userId, $name) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_tags WHERE user_id = ? AND name = ?';
return $this->findEntity($sql, [$userId, $name]);
}
public function tagExists($userId, $name) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_tags WHERE user_id = ? AND name = ?';
try {
return $this->findEntities($sql, [$userId, $name]);
} catch (DoesNotExistException $e) {
return false;
}
return true;
}
}