mirror of
https://github.com/JanGross/quicknotes.git
synced 2025-12-01 07:37:18 +01:00
Put color on own database. Umm.. Any relationship placed on the note controller.
This commit is contained in:
19
db/color.php
Normal file
19
db/color.php
Normal 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
db/colormapper.php
Normal file
39
db/colormapper.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace OCA\QuickNotes\Db;
|
||||
|
||||
use OCP\IDb;
|
||||
use OCP\AppFramework\Db\Mapper;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
|
||||
class ColorMapper extends Mapper {
|
||||
|
||||
public function __construct(IDb $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;
|
||||
}
|
||||
|
||||
}
|
||||
11
db/note.php
11
db/note.php
@@ -9,14 +9,23 @@ class Note extends Entity implements JsonSerializable {
|
||||
|
||||
protected $title;
|
||||
protected $content;
|
||||
protected $color;
|
||||
protected $timestamp;
|
||||
protected $colorId;
|
||||
protected $userId;
|
||||
|
||||
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
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ namespace OCA\QuickNotes\Db;
|
||||
|
||||
use OCP\IDb;
|
||||
use OCP\AppFramework\Db\Mapper;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
|
||||
class NoteMapper extends Mapper {
|
||||
|
||||
@@ -20,4 +21,12 @@ class NoteMapper extends Mapper {
|
||||
return $this->findEntities($sql, [$userId]);
|
||||
}
|
||||
|
||||
public function colorIdCount($colorid) {
|
||||
$sql = 'SELECT COUNT(*) as `count` FROM *PREFIX*quicknotes WHERE color_id = ?';
|
||||
$result = $this->execute($sql, [$colorid]);
|
||||
$row = $result->fetch();
|
||||
$result->closeCursor();
|
||||
return $row['count'];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user