@@ -23,6 +23,14 @@
|
|||||||
|
|
||||||
namespace OCA\Deck\Db;
|
namespace OCA\Deck\Db;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method int getId()
|
||||||
|
* @method string getTitle()
|
||||||
|
* @method int getShared()
|
||||||
|
* @method bool getArchived()
|
||||||
|
* @method int getDeletedAt()
|
||||||
|
* @method int getLastModified()
|
||||||
|
*/
|
||||||
class Board extends RelationalEntity {
|
class Board extends RelationalEntity {
|
||||||
protected $title;
|
protected $title;
|
||||||
protected $owner;
|
protected $owner;
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ class Card extends RelationalEntity {
|
|||||||
protected $relatedStack = null;
|
protected $relatedStack = null;
|
||||||
protected $relatedBoard = null;
|
protected $relatedBoard = null;
|
||||||
|
|
||||||
protected $databaseType = 'sqlite';
|
private $databaseType = 'sqlite';
|
||||||
|
|
||||||
public const DUEDATE_FUTURE = 0;
|
public const DUEDATE_FUTURE = 0;
|
||||||
public const DUEDATE_NEXT = 1;
|
public const DUEDATE_NEXT = 1;
|
||||||
@@ -108,6 +108,7 @@ class Card extends RelationalEntity {
|
|||||||
$this->addType('archived', 'boolean');
|
$this->addType('archived', 'boolean');
|
||||||
$this->addType('notified', 'boolean');
|
$this->addType('notified', 'boolean');
|
||||||
$this->addType('deletedAt', 'integer');
|
$this->addType('deletedAt', 'integer');
|
||||||
|
$this->addType('duedate', 'string');
|
||||||
$this->addRelation('labels');
|
$this->addRelation('labels');
|
||||||
$this->addRelation('assignedUsers');
|
$this->addRelation('assignedUsers');
|
||||||
$this->addRelation('attachments');
|
$this->addRelation('attachments');
|
||||||
|
|||||||
@@ -24,11 +24,10 @@ namespace OCA\Deck\Model;
|
|||||||
|
|
||||||
use OCA\Deck\Db\Board;
|
use OCA\Deck\Db\Board;
|
||||||
|
|
||||||
class BoardSummary extends Board
|
class BoardSummary extends Board {
|
||||||
{
|
|
||||||
private Board $board;
|
private Board $board;
|
||||||
|
|
||||||
public function __construct(Board $board = null) {
|
public function __construct(Board $board) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->board = $board;
|
$this->board = $board;
|
||||||
}
|
}
|
||||||
@@ -40,7 +39,7 @@ class BoardSummary extends Board
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getter($name) {
|
public function __call($name, $arguments) {
|
||||||
return $this->board->getter($name);
|
return $this->board->__call($name, $arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ use DateTime;
|
|||||||
use OCA\Deck\Db\Board;
|
use OCA\Deck\Db\Board;
|
||||||
use OCA\Deck\Db\Card;
|
use OCA\Deck\Db\Card;
|
||||||
|
|
||||||
class CardDetails extends Card
|
class CardDetails extends Card {
|
||||||
{
|
|
||||||
private Card $card;
|
private Card $card;
|
||||||
private ?Board $board;
|
private ?Board $board;
|
||||||
|
|
||||||
@@ -42,14 +41,10 @@ class CardDetails extends Card
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function jsonSerialize(array $extras = []): array {
|
public function jsonSerialize(array $extras = []): array {
|
||||||
$array = parent::jsonSerialize();
|
$array = $this->card->jsonSerialize();
|
||||||
|
unset($array['notified'], $array['descriptionPrev'], $array['relatedStack'], $array['relatedBoard']);
|
||||||
|
|
||||||
$array['overdue'] = $this->getDueStatus();
|
$array['overdue'] = $this->getDueStatus();
|
||||||
|
|
||||||
unset($array['notified']);
|
|
||||||
unset($array['descriptionPrev']);
|
|
||||||
unset($array['relatedStack']);
|
|
||||||
unset($array['relatedBoard']);
|
|
||||||
|
|
||||||
$this->appendBoardDetails($array);
|
$this->appendBoardDetails($array);
|
||||||
|
|
||||||
return $array;
|
return $array;
|
||||||
@@ -59,23 +54,27 @@ class CardDetails extends Card
|
|||||||
$today = new DateTime();
|
$today = new DateTime();
|
||||||
$today->setTime(0, 0);
|
$today->setTime(0, 0);
|
||||||
|
|
||||||
$match_date = $this->getDueDateTime() ?? new DateTime();
|
$match_date = $this->card->getDueDateTime();
|
||||||
|
if (!$match_date) {
|
||||||
|
return Card::DUEDATE_FUTURE;
|
||||||
|
}
|
||||||
$match_date->setTime(0, 0);
|
$match_date->setTime(0, 0);
|
||||||
|
|
||||||
$diff = $today->diff($match_date);
|
$diff = $today->diff($match_date);
|
||||||
$diffDays = (integer) $diff->format('%R%a'); // Extract days count in interval
|
$diffDays = (int) $diff->format('%R%a'); // Extract days count in interval
|
||||||
|
|
||||||
|
|
||||||
if ($diffDays === 1) {
|
if ($diffDays === 1) {
|
||||||
return static::DUEDATE_NEXT;
|
return Card::DUEDATE_NEXT;
|
||||||
}
|
}
|
||||||
if ($diffDays === 0) {
|
if ($diffDays === 0) {
|
||||||
return static::DUEDATE_NOW;
|
return Card::DUEDATE_NOW;
|
||||||
}
|
}
|
||||||
if ($diffDays < 0) {
|
if ($diffDays < 0) {
|
||||||
return static::DUEDATE_OVERDUE;
|
return Card::DUEDATE_OVERDUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return static::DUEDATE_FUTURE;
|
return Card::DUEDATE_FUTURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function appendBoardDetails(&$array): void {
|
private function appendBoardDetails(&$array): void {
|
||||||
@@ -87,7 +86,7 @@ class CardDetails extends Card
|
|||||||
$array['board'] = (new BoardSummary($this->board))->jsonSerialize();
|
$array['board'] = (new BoardSummary($this->board))->jsonSerialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getter($name) {
|
public function __call($name, $arguments) {
|
||||||
return $this->card->getter($name);
|
return $this->card->__call($name, $arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace OCA\Deck\Db;
|
|||||||
|
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
use OCA\Deck\Model\CardDetails;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class CardTest extends TestCase {
|
class CardTest extends TestCase {
|
||||||
@@ -59,7 +60,7 @@ class CardTest extends TestCase {
|
|||||||
public function testDuedate(DateTime $duedate, $state) {
|
public function testDuedate(DateTime $duedate, $state) {
|
||||||
$card = $this->createCard();
|
$card = $this->createCard();
|
||||||
$card->setDuedate($duedate->format('Y-m-d H:i:s'));
|
$card->setDuedate($duedate->format('Y-m-d H:i:s'));
|
||||||
$this->assertEquals($state, $card->jsonSerialize()['overdue']);
|
$this->assertEquals($state, (new CardDetails($card))->jsonSerialize()['overdue']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testJsonSerialize() {
|
public function testJsonSerialize() {
|
||||||
@@ -86,7 +87,7 @@ class CardTest extends TestCase {
|
|||||||
'commentsCount' => 0,
|
'commentsCount' => 0,
|
||||||
'lastEditor' => null,
|
'lastEditor' => null,
|
||||||
'ETag' => $card->getETag(),
|
'ETag' => $card->getETag(),
|
||||||
], $card->jsonSerialize());
|
], (new CardDetails($card))->jsonSerialize());
|
||||||
}
|
}
|
||||||
public function testJsonSerializeLabels() {
|
public function testJsonSerializeLabels() {
|
||||||
$card = $this->createCard();
|
$card = $this->createCard();
|
||||||
@@ -113,7 +114,7 @@ class CardTest extends TestCase {
|
|||||||
'commentsCount' => 0,
|
'commentsCount' => 0,
|
||||||
'lastEditor' => null,
|
'lastEditor' => null,
|
||||||
'ETag' => $card->getETag(),
|
'ETag' => $card->getETag(),
|
||||||
], $card->jsonSerialize());
|
], (new CardDetails($card))->jsonSerialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMysqlDateFallback() {
|
public function testMysqlDateFallback() {
|
||||||
@@ -150,6 +151,6 @@ class CardTest extends TestCase {
|
|||||||
'commentsCount' => 0,
|
'commentsCount' => 0,
|
||||||
'lastEditor' => null,
|
'lastEditor' => null,
|
||||||
'ETag' => $card->getETag(),
|
'ETag' => $card->getETag(),
|
||||||
], $card->jsonSerialize());
|
], (new CardDetails($card))->jsonSerialize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user