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

19
lib/Db/Color.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
namespace OCA\QuickNotes\Db;
use JsonSerializable;
use OCP\AppFramework\Db\Entity;
class Color extends Entity implements JsonSerializable {
protected $color;
public function jsonSerialize() {
return [
'id' => $this->id,
'color' => $this->color
];
}
}

39
lib/Db/ColorMapper.php Normal file
View File

@@ -0,0 +1,39 @@
<?php
namespace OCA\QuickNotes\Db;
use OCP\IDBConnection;
use OCP\AppFramework\Db\Mapper;
use OCP\AppFramework\Db\DoesNotExistException;
class ColorMapper extends Mapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'quicknotes_colors', '\OCA\QuickNotes\Db\Color');
}
public function find($id) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_colors WHERE id = ?';
return $this->findEntity($sql, [$id]);
}
public function findAll() {
$sql = 'SELECT * FROM *PREFIX*quicknotes_colors';
return $this->findEntities($sql, []);
}
public function findByColor($color) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_colors WHERE color = ?';
return $this->findEntity($sql, [$color]);
}
public function colorExists($color) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_colors WHERE color = ?';
try {
$this->findEntity($sql, [$color]);
} catch (DoesNotExistException $e) {
return false;
}
return true;
}
}

39
lib/Db/Note.php Normal file
View File

@@ -0,0 +1,39 @@
<?php
namespace OCA\QuickNotes\Db;
use JsonSerializable;
use OCP\AppFramework\Db\Entity;
class Note extends Entity implements JsonSerializable {
protected $title;
protected $content;
protected $timestamp;
protected $colorId;
protected $userId;
protected $sharedWith;
protected $isShared;
protected $tags;
protected $color;
public function setColor($color) {
$this->color = $color;
}
public function jsonSerialize() {
return [
'id' => $this->id,
'title' => $this->title,
'content' => $this->content,
'timestamp' => $this->timestamp,
'colorid' => $this->colorId,
'color' => $this->color,
'userid' => $this->userId,
'sharedwith' => $this->sharedWith,
'isshared' => $this->isShared,
'tags' => $this->tags
];
}
}

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'];
}
}

22
lib/Db/NoteShare.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
namespace OCA\QuickNotes\Db;
use JsonSerializable;
use OCP\AppFramework\Db\Entity;
class NoteShare extends Entity implements JsonSerializable {
protected $noteId;
protected $sharedUser;
protected $sharedGroup;
public function jsonSerialize() {
return [
'id' => $this->id,
'noteid' => $this->noteId,
'shareduser' => $this->sharedUser,
'sharedgroup' => $this->sharedGroup
];
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace OCA\QuickNotes\Db;
use OCP\IDBConnection;
use OCP\AppFramework\Db\Mapper;
use OCP\AppFramework\Db\DoesNotExistException;
class NoteShareMapper extends Mapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'quicknotes_shares', '\OCA\QuickNotes\Db\NoteShare');
}
/*public function find($id, $userId) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE id = ? AND user_id = ?';
return $this->findEntity($sql, [$id, $userId]);
}*/
public function findForUser($userId) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE shared_user = ?';
return $this->findEntities($sql, [$userId]);
}
public function findForGroup($groupId) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE shared_group = ?';
return $this->findEntities($sql, [$groupId]);
}
public function findByNoteAndUser($noteId, $userId) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE shared_user = ? AND note_id = ?';
return $this->findEntity($sql, [$userId, $noteId]);
}
public function findByNoteAndGroup($noteId, $groupId) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE shared_group = ? AND note_id = ?';
return $this->findEntity($sql, [$groupId, $noteId]);
}
public function getSharesForNote($noteId) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE note_id = ?';
return $this->findEntities($sql, [$noteId]);
}
public function deleteByNoteId($noteId) {
$sql = 'DELETE FROM *PREFIX*quicknotes_shares WHERE note_id = ?';
$this->execute($sql, [$noteId]);
}
}

23
lib/Db/NoteTag.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
namespace OCA\QuickNotes\Db;
use JsonSerializable;
use OCP\AppFramework\Db\Entity;
class NoteTag extends Entity implements JsonSerializable {
protected $noteId;
protected $tagId;
protected $userId;
public function jsonSerialize() {
return [
'id' => $this->id,
'noteid' => $this->noteId,
'tagid' => $this->tagId,
'userid' => $this->userId
];
}
}

38
lib/Db/NoteTagMapper.php Normal file
View File

@@ -0,0 +1,38 @@
<?php
namespace OCA\QuickNotes\Db;
use OCP\IDBConnection;
use OCP\AppFramework\Db\Mapper;
class NoteTagMapper extends Mapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'quicknotes_note_tags', '\OCA\QuickNotes\Db\NoteTag');
}
public function find($id, $userId) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_note_tags WHERE id = ? AND user_id = ?';
return $this->findEntity($sql, [$id, $userId]);
}
public function findAll($userId) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_note_tags WHERE user_id = ?';
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;
}
}

21
lib/Db/Tag.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
namespace OCA\QuickNotes\Db;
use JsonSerializable;
use OCP\AppFramework\Db\Entity;
class Tag extends Entity implements JsonSerializable {
protected $name;
protected $userId;
public function jsonSerialize() {
return [
'id' => $this->id,
'name' => $this->name,
'userid' => $this->userId
];
}
}

51
lib/Db/TagMapper.php Normal file
View File

@@ -0,0 +1,51 @@
<?php
namespace OCA\QuickNotes\Db;
use OCP\IDBConnection;
use OCP\AppFramework\Db\Mapper;
class TagMapper extends Mapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'quicknotes_tags', '\OCA\QuickNotes\Db\Tag');
}
public function find($id, $userId) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_tags WHERE id = ? AND user_id = ?';
return $this->findEntity($sql, [$id, $userId]);
}
public function findAll($userId) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_tags WHERE user_id = ?';
return $this->findEntities($sql, [$userId]);
}
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.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;
}
public function dropOld () {
$sql = 'DELETE FROM *PREFIX*quicknotes_tags WHERE ';
$sql.= 'id NOT IN (SELECT tag_id FROM *PREFIX*quicknotes_note_tags)';
return $this->execute($sql, []);
}
}

24
lib/Db/Task.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
namespace OCA\QuickNotes\Db;
use JsonSerializable;
use OCP\AppFramework\Db\Entity;
class Note extends Entity implements JsonSerializable {
protected $description;
protected $done;
protected $ordering;
protected $noteId;
public function jsonSerialize() {
return [
'id' => $this->id,
'description' => $this->description,
'done' => $this->done,
'ordering' => $this->ordering,
'noteId' => $this->noteId
];
}
}

23
lib/Db/TaskMapper.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
namespace OCA\QuickNotes\Db;
use OCP\IDBConnection;
use OCP\AppFramework\Db\Mapper;
class TaskMapper extends Mapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'quicknotes_tasks', '\OCA\QuickNotes\Db\Tasks');
}
public function find($id, $noteId) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_tasks WHERE id = ? AND note_id = ?';
return $this->findEntity($sql, [$id, $noteId]);
}
public function findAll($noteId) {
$sql = 'SELECT * FROM *PREFIX*quicknotes_tasks WHERE note_id = ?';
return $this->findEntities($sql, [$noteId]);
}
}