Upgrade to some new nextcloud standards

This commit is contained in:
Matias De lellis
2020-05-30 18:33:01 -03:00
parent d417902d94
commit f7ab295a6c
21 changed files with 192 additions and 207 deletions

44
lib/Db/NoteMapper.php Normal file
View File

@@ -0,0 +1,44 @@
<?php
namespace OCA\QuickNotes\Db;
use OCP\IDBConnection;
use OCP\AppFramework\Db\Mapper;
use OCP\AppFramework\Db\DoesNotExistException;
class NoteMapper extends Mapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'quicknotes_notes', '\OCA\QuickNotes\Db\Note');
}
/**
* @param int $id
* @param string $userId
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
* @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]);
}
public function findAll($userId) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_notes WHERE user_id = ?';
return $this->findEntities($sql, [$userId]);
}
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'];
}
}