Files
quicknotes/lib/Db/NoteTagMapper.php
Matias De lellis 53ed22172c More fixes
2021-09-20 21:33:26 -03:00

42 lines
1.1 KiB
PHP

<?php
namespace OCA\QuickNotes\Db;
use OCP\IDBConnection;
use OCP\AppFramework\Db\QBMapper;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCA\QuickNotes\Db\NoteTag;
class NoteTagMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'quicknotes_note_tags', NoteTag::class);
}
public function findNoteTag(string $userId, int $noteId, $tagId): NoteTag {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where(
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('note_id', $qb->createNamedParameter($noteId, IQueryBuilder::PARAM_INT)),
$qb->expr()->eq('tag_id', $qb->createNamedParameter($tagId, IQueryBuilder::PARAM_INT))
);
return $this->findEntity($qb);
}
/**
* @return bool
*/
public function noteTagExists(string $userId, int $noteId, int $tagId): bool {
try {
$this->findNoteTag($userId, $noteId, $tagId);
} catch (DoesNotExistException $e) {
return false;
}
return true;
}
}