More fixes

This commit is contained in:
Julius Haertl
2016-07-08 08:44:53 +02:00
parent 731ac1af68
commit 89dd772111
13 changed files with 219 additions and 31 deletions

32
db/acl.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
// db/author.php
namespace OCA\Deck\Db;
use JsonSerializable;
class Acl extends Entity implements JsonSerializable {
public $id;
protected $participant;
protected $type;
protected $boardId;
protected $permissionWrite;
protected $permissionInvite;
protected $permissionManage;
public function __construct() {
$this->addType('id','integer');
$this->addType('boardId','integer');
}
public function jsonSerialize() {
return [
'id' => $this->id,
'participant' => $this->participant,
'type' => $this->type,
'boardId' => $this->boardId,
'permissionWrite' => $this->permissionWrite,
'permissionInvite' => $this->permissionInvite,
'permissionManage' => $this->permissionManage,
];
}
}

21
db/aclmapper.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
namespace OCA\Deck\Db;
use OCP\AppFramework\Db\Entity;
use OCP\IDb;
use OCP\AppFramework\Db\Mapper;
class AclMapper extends DeckMapper {
public function __construct(IDb $db) {
parent::__construct($db, 'deck_board_acl', '\OCA\Deck\Db\Acl');
}
public function findAll($boardId, $limit=null, $offset=null) {
$sql = 'SELECT * FROM `*PREFIX*deck_board_acl` WHERE `board_id` = ?';
return $this->findEntities($sql, [$boardId], $limit, $offset);
}
}

View File

@@ -11,11 +11,13 @@ class Board extends \OCA\Deck\Db\Entity implements JsonSerializable {
protected $owner;
protected $color;
protected $archived;
public $acl = array();
protected $labels;
public function __construct() {
$this->addType('id','integer');
$this->addRelation('labels');
$this->addRelation('acl');
}
public function jsonSerialize() {
@@ -25,6 +27,7 @@ class Board extends \OCA\Deck\Db\Entity implements JsonSerializable {
'owner' => $this->owner,
'color' => $this->color,
'labels' => $this->labels,
'acl' => $this->acl,
];
}
}

View File

@@ -15,9 +15,10 @@ class BoardMapper extends Mapper {
$this->_relationMappers[$name] = $mapper;
}
public function __construct(IDb $db, LabelMapper $labelMapper) {
public function __construct(IDb $db, LabelMapper $labelMapper, AclMapper $aclMapper) {
parent::__construct($db, 'deck_boards', '\OCA\Deck\Db\Board');
$this->labelMapper = $labelMapper;
$this->aclMapper = $aclMapper;
}
@@ -29,12 +30,22 @@ class BoardMapper extends Mapper {
$sql = 'SELECT * FROM `*PREFIX*deck_boards` ' .
'WHERE `id` = ?';
$board = $this->findEntity($sql, [$id]);
// Add labels
$labels = $this->labelMapper->findAll($id);
$board->setLabels($labels);
// Add sharees
$acl = $this->aclMapper->findAll($id);
$board->setAcl($acl);
return $board;
}
/**
* Find all boards for a given user
* @param $userId
* @param null $limit
* @param null $offset
* @return array
*/
public function findAll($userId, $limit=null, $offset=null) {
$sql = 'SELECT * FROM `*PREFIX*deck_boards` WHERE `owner` = ? ORDER BY `title`';
return $this->findEntities($sql, [$userId], $limit, $offset);

View File

@@ -24,12 +24,12 @@ class LabelMapper extends DeckMapper {
}
public function findAssignedLabelsForCard($cardId) {
$sql = 'SELECT l.* FROM `*PREFIX*deck_assigned_labels` as al INNER JOIN *PREFIX*deck_labels as l ON l.id = al.label_id WHERE `card_id` = ?';
$sql = 'SELECT l.* FROM `*PREFIX*deck_assigned_labels` as al INNER JOIN *PREFIX*deck_labels as l ON l.id = al.label_id WHERE `card_id` = ? ORDER BY l.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, l.color as color FROM oc_deck_cards as c " .
" INNER JOIN oc_deck_assigned_labels as al ON al.card_id = c.id INNER JOIN oc_deck_labels as l ON al.label_id = l.id WHERE board_id=?";
" INNER JOIN oc_deck_assigned_labels as al ON al.card_id = c.id INNER JOIN oc_deck_labels as l ON al.label_id = l.id WHERE board_id=? ORDER BY l.id";
$entities = $this->findEntities($sql, [$boardId], $limit, $offset);
return $entities;
}