Put color on own database. Umm.. Any relationship placed on the note controller.

This commit is contained in:
Matias De lellis
2016-05-26 18:09:55 -03:00
parent b7264d4377
commit 6df7fc0ba8
7 changed files with 163 additions and 21 deletions

19
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
db/colormapper.php Normal file
View 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;
}
}

View File

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

View File

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