Add more
This commit is contained in:
@@ -12,6 +12,7 @@ class Board extends Entity implements JsonSerializable {
|
||||
protected $owner;
|
||||
protected $color;
|
||||
protected $archived;
|
||||
protected $labels;
|
||||
public function __construct() {
|
||||
$this->addType('id','integer');
|
||||
}
|
||||
@@ -20,7 +21,8 @@ class Board extends Entity implements JsonSerializable {
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'owner' => $this->owner,
|
||||
'color' => $this->color
|
||||
'color' => $this->color,
|
||||
'labels' => $this->labels,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,11 @@ use OCP\AppFramework\Db\Mapper;
|
||||
|
||||
class BoardMapper extends Mapper {
|
||||
|
||||
public function __construct(IDb $db) {
|
||||
private $labelMapper;
|
||||
|
||||
public function __construct(IDb $db, LabelMapper $labelMapper) {
|
||||
parent::__construct($db, 'deck_boards', '\OCA\Deck\Db\Board');
|
||||
$this->labelMapper = $labelMapper;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +24,10 @@ class BoardMapper extends Mapper {
|
||||
public function find($id) {
|
||||
$sql = 'SELECT * FROM `*PREFIX*deck_boards` ' .
|
||||
'WHERE `id` = ?';
|
||||
return $this->findEntity($sql, [$id]);
|
||||
$board = $this->findEntity($sql, [$id]);
|
||||
$labels = $this->labelMapper->findAll($id);
|
||||
$board->setLabels($labels);
|
||||
return $board;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,10 +9,12 @@ class Card extends Entity implements JsonSerializable {
|
||||
|
||||
public $id;
|
||||
protected $title;
|
||||
protected $description;
|
||||
protected $stackId;
|
||||
protected $type;
|
||||
protected $lastModified;
|
||||
protected $createdAt;
|
||||
protected $labels;
|
||||
protected $owner;
|
||||
protected $order;
|
||||
public function __construct() {
|
||||
@@ -25,12 +27,14 @@ class Card extends Entity implements JsonSerializable {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'description' => $this->description,
|
||||
'type' => $this->type,
|
||||
'lastModified' => $this->lastModified,
|
||||
'createdAt' => $this->createdAt,
|
||||
'owner' => $this->owner,
|
||||
'order' => $this->order,
|
||||
'stackId' => $this->stackId,
|
||||
'labels' => $this->labels,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,21 @@ class CardMapper extends Mapper {
|
||||
public function __construct(IDb $db) {
|
||||
parent::__construct($db, 'deck_cards', '\OCA\Deck\Db\Card');
|
||||
}
|
||||
|
||||
public function insert(Entity $entity) {
|
||||
$entity->setCreatedAt(time());
|
||||
$entity->setLastModified(time());
|
||||
return parent::insert($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Entity $entity
|
||||
* @return Entity
|
||||
*/
|
||||
public function update(Entity $entity) {
|
||||
$entity->setLastModified(time());
|
||||
return parent::update($entity);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -25,10 +40,14 @@ class CardMapper extends Mapper {
|
||||
return $this->findEntity($sql, [$id]);
|
||||
}
|
||||
|
||||
public function findAllByBoard($boardId, $limit=null, $offset=null) {
|
||||
|
||||
}
|
||||
|
||||
public function findAll($stackId, $limit=null, $offset=null) {
|
||||
$sql = 'SELECT * FROM `*PREFIX*deck_cards` WHERE `stack_id` = ? ORDER BY `order`';
|
||||
return $this->findEntities($sql, [$stackId], $limit, $offset);
|
||||
$entities = $this->findEntities($sql, [$stackId], $limit, $offset);
|
||||
return $entities;
|
||||
}
|
||||
|
||||
public function delete(Entity $entity) {
|
||||
|
||||
32
db/deckmapper.php
Normal file
32
db/deckmapper.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace OCA\Deck\Db;
|
||||
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
use OCP\AppFramework\Db\Mapper;
|
||||
|
||||
abstract class DeckMapper extends Mapper {
|
||||
|
||||
/**
|
||||
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
|
||||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
|
||||
*/
|
||||
public function find($id) {
|
||||
$sql = 'SELECT * FROM `' . $this->tableName . '` ' . 'WHERE `id` = ?';
|
||||
return $this->findEntity($sql, [$id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add relational data to an Entity by calling the related Mapper
|
||||
* @param $entities
|
||||
* @param $entityType
|
||||
* @param $property
|
||||
* addRelation($cards, $labels, function($one, $many) {
|
||||
* if($one->id == $many->cardId)
|
||||
* }
|
||||
*/
|
||||
public function addRelation($entities, $entityType, $property) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
27
db/label.php
Normal file
27
db/label.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// db/author.php
|
||||
namespace OCA\Deck\Db;
|
||||
|
||||
use JsonSerializable;
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
|
||||
class Label extends Entity implements JsonSerializable {
|
||||
|
||||
public $id;
|
||||
protected $title;
|
||||
protected $color;
|
||||
protected $boardId;
|
||||
protected $cardId;
|
||||
public function __construct() {
|
||||
$this->addType('id','integer');
|
||||
}
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'boardId' => $this->boardId,
|
||||
'cardId' => $this->cardId,
|
||||
'color' => $this->color,
|
||||
];
|
||||
}
|
||||
}
|
||||
48
db/labelmapper.php
Normal file
48
db/labelmapper.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace OCA\Deck\Db;
|
||||
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
use OCP\IDb;
|
||||
use OCP\AppFramework\Db\Mapper;
|
||||
|
||||
|
||||
class LabelMapper extends DeckMapper {
|
||||
|
||||
public function __construct(IDb $db) {
|
||||
parent::__construct($db, 'deck_labels', '\OCA\Deck\Db\Label');
|
||||
}
|
||||
|
||||
public function findAll($boardId, $limit=null, $offset=null) {
|
||||
$sql = 'SELECT * FROM `*PREFIX*deck_labels` WHERE `board_id` = ?';
|
||||
return $this->findEntities($sql, [$boardId], $limit, $offset);
|
||||
}
|
||||
|
||||
public function delete(Entity $entity) {
|
||||
// FIXME: delete linked elements, because owncloud doesn't support foreign keys for apps
|
||||
return parent::delete($entity);
|
||||
}
|
||||
|
||||
public function findAssignedLabelsForCard($cardId) {
|
||||
$sql = 'SELECT * FROM `*PREFIX*deck_assigned_labels` as al JOIN *PREFIX*deck_labels as l ON l.id = al.label_id WHERE `card_id` = ?';
|
||||
return $this->findEntities($sql, [$cardId], $limit, $offset);
|
||||
}
|
||||
public function findAssignedLabelsForBoard($boardId, $limit=null, $offset=null) {
|
||||
$sql = "SELECT c.id as card_id, l.id as id, l.title as title, color FROM oc_deck_cards as c " .
|
||||
"JOIN oc_deck_assigned_labels as al, oc_deck_labels as l ON al.card_id = c.id AND al.label_id = l.id WHERE board_id=?";
|
||||
$entities = $this->findEntities($sql, [$boardId], $limit, $offset);
|
||||
return $entities;
|
||||
}
|
||||
|
||||
public function getAssignedLabelsForBoard($boardId) {
|
||||
$labels = $this->findAssignedLabelsForBoard($boardId);
|
||||
$result = array();
|
||||
foreach ($labels as $label) {
|
||||
if(!is_array($result[$label->getCardId()])) {
|
||||
$result[$label->getCardId()] = array();
|
||||
}
|
||||
$result[$label->getCardId()][] = $label;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user