Inital backend support to pinned notes

This commit is contained in:
Matias De lellis
2020-06-04 13:39:58 -03:00
parent 0845127458
commit c70c87a20d
10 changed files with 126 additions and 124 deletions

View File

@@ -9,6 +9,7 @@ class Note extends Entity implements JsonSerializable {
protected $title;
protected $content;
protected $pinned;
protected $timestamp;
protected $colorId;
protected $userId;
@@ -17,16 +18,23 @@ class Note extends Entity implements JsonSerializable {
protected $tags;
protected $color;
protected $isPinned;
public function setColor($color) {
$this->color = $color;
}
public function setIsPinned($pinned) {
$this->isPinned = $pinned;
}
public function jsonSerialize() {
return [
'id' => $this->id,
'title' => $this->title,
'content' => $this->content,
'pinned' => $this->pinned,
'ispinned' => $this->isPinned,
'timestamp' => $this->timestamp,
'colorid' => $this->colorId,
'color' => $this->color,

View File

@@ -1,14 +1,16 @@
<?php
<?php declare(strict_types=1);
namespace OCA\QuickNotes\Db;
use OCP\IDBConnection;
use OCP\AppFramework\Db\Mapper;
use OCP\AppFramework\Db\QBMapper;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\DB\QueryBuilder\IQueryBuilder;
class NoteMapper extends Mapper {
class NoteMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'quicknotes_notes', '\OCA\QuickNotes\Db\Note');
parent::__construct($db, 'quicknotes_notes');
}
/**
@@ -19,26 +21,34 @@ class NoteMapper extends Mapper {
* @return Note
*/
public function find($id, $userId) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_notes WHERE id = ? AND user_id = ?';
return $this->findEntity($sql, [$id, $userId]);
}
public function findById($id) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_notes WHERE id = ?';
return $this->findEntity($sql, [$id]);
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->tableName)
->where(
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))
);
return $this->findEntity($qb);
}
public function findAll($userId) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_notes WHERE user_id = ?';
return $this->findEntities($sql, [$userId]);
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->tableName)
->where(
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
);
return $this->findEntities($qb);
}
public function colorIdCount($colorid) {
$sql = 'SELECT COUNT(*) as `count` FROM *PREFIX*quicknotes_notes WHERE color_id = ?';
$result = $this->execute($sql, [$colorid]);
$row = $result->fetch();
$result->closeCursor();
return $row['count'];
$qb = $this->db->getQueryBuilder();
$qb->select('id')
->from($this->tableName)
->where(
$qb->expr()->eq('color_id', $qb->createNamedParameter($colorid, IQueryBuilder::PARAM_INT))
);
return count($this->findEntities($qb));
}
}