258 lines
6.1 KiB
PHP
Executable File
258 lines
6.1 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Entity;
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
class KanbanBoard implements \JsonSerializable
|
|
{
|
|
const PRIO_MAP = [
|
|
'Trivial' => 0,
|
|
'Minor' => 1,
|
|
'Major' => 2,
|
|
'Critical' => 3,
|
|
'Blocker' => 4,
|
|
];
|
|
|
|
/**
|
|
* @var KanbanEntry[]|ArrayCollection
|
|
*/
|
|
private $inbox;
|
|
|
|
/**
|
|
* @var KanbanEntry[]|ArrayCollection
|
|
*/
|
|
private $inProgress;
|
|
|
|
/**
|
|
* @var KanbanEntry[]|ArrayCollection
|
|
*/
|
|
private $verification;
|
|
|
|
/**
|
|
* @var KanbanEntry[]|ArrayCollection
|
|
*/
|
|
private $done;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->inbox = new ArrayCollection();
|
|
$this->inProgress = new ArrayCollection();
|
|
$this->verification = new ArrayCollection();
|
|
$this->done = new ArrayCollection();
|
|
}
|
|
|
|
/**
|
|
* @return KanbanEntry[]|ArrayCollection
|
|
*/
|
|
public function getInbox(): ArrayCollection
|
|
{
|
|
return $this->inbox;
|
|
}
|
|
|
|
/**
|
|
* @param KanbanEntry[]|ArrayCollection $inbox
|
|
* @return KanbanBoard
|
|
*/
|
|
public function setInbox(ArrayCollection $inbox): KanbanBoard
|
|
{
|
|
$this->inbox = $inbox;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @param KanbanEntry $inbox
|
|
* @return KanbanBoard
|
|
*/
|
|
public function addInbox(KanbanEntry $inbox): KanbanBoard
|
|
{
|
|
if (!$this->inbox->contains($inbox)) {
|
|
$this->inbox->add($inbox);
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @param KanbanEntry $inbox
|
|
* @return KanbanBoard
|
|
*/
|
|
public function removeInbox(KanbanEntry $inbox): KanbanBoard
|
|
{
|
|
if ($this->inbox->contains($inbox)) {
|
|
$this->inbox->removeElement($inbox);
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return KanbanEntry[]|ArrayCollection
|
|
*/
|
|
public function getInProgress(): ArrayCollection
|
|
{
|
|
return $this->inProgress;
|
|
}
|
|
|
|
/**
|
|
* @param KanbanEntry[]|ArrayCollection $inProgress
|
|
* @return KanbanBoard
|
|
*/
|
|
public function setInProgress(ArrayCollection $inProgress): KanbanBoard
|
|
{
|
|
$this->inProgress = $inProgress;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @param KanbanEntry $inProgress
|
|
* @return KanbanBoard
|
|
*/
|
|
public function addInProgress(KanbanEntry $inProgress): KanbanBoard
|
|
{
|
|
if (!$this->inProgress->contains($inProgress)) {
|
|
$this->inProgress->add($inProgress);
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @param KanbanEntry $inProgress
|
|
* @return KanbanBoard
|
|
*/
|
|
public function removeInProgress(KanbanEntry $inProgress): KanbanBoard
|
|
{
|
|
if ($this->inProgress->contains($inProgress)) {
|
|
$this->inProgress->removeElement($inProgress);
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return KanbanEntry[]|ArrayCollection
|
|
*/
|
|
public function getVerification(): ArrayCollection
|
|
{
|
|
return $this->verification;
|
|
}
|
|
|
|
/**
|
|
* @param KanbanEntry[]|ArrayCollection $verification
|
|
* @return KanbanBoard
|
|
*/
|
|
public function setVerification(ArrayCollection $verification): KanbanBoard
|
|
{
|
|
$this->verification = $verification;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @param KanbanEntry $verification
|
|
* @return KanbanBoard
|
|
*/
|
|
public function addVerification(KanbanEntry $verification): KanbanBoard
|
|
{
|
|
if (!$this->verification->contains($verification)) {
|
|
$this->verification->add($verification);
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @param KanbanEntry $verification
|
|
* @return KanbanBoard
|
|
*/
|
|
public function removeVerification(KanbanEntry $verification): KanbanBoard
|
|
{
|
|
if ($this->verification->contains($verification)) {
|
|
$this->verification->removeElement($verification);
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return KanbanEntry[]|ArrayCollection
|
|
*/
|
|
public function getDone(): ArrayCollection
|
|
{
|
|
return $this->done;
|
|
}
|
|
|
|
/**
|
|
* @param KanbanEntry[]|ArrayCollection $verification
|
|
* @return KanbanBoard
|
|
*/
|
|
public function setDone(ArrayCollection $verification): KanbanBoard
|
|
{
|
|
$this->done = $verification;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @param KanbanEntry $verification
|
|
* @return KanbanBoard
|
|
*/
|
|
public function addDone(KanbanEntry $verification): KanbanBoard
|
|
{
|
|
if (!$this->done->contains($verification)) {
|
|
$this->done->add($verification);
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @param KanbanEntry $verification
|
|
* @return KanbanBoard
|
|
*/
|
|
public function removeDone(KanbanEntry $verification): KanbanBoard
|
|
{
|
|
if ($this->done->contains($verification)) {
|
|
$this->done->removeElement($verification);
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @param KanbanEntry[] $toSort
|
|
* @return KanbanEntry[]
|
|
*/
|
|
private function prioSort(array $toSort): array
|
|
{
|
|
usort($toSort, function (KanbanEntry $a, KanbanEntry $b) {
|
|
// if (null !== $a->getTaurusPrio()) {
|
|
return $a->getTaurusPrio() <=> $b->getTaurusPrio();
|
|
// }
|
|
// return self::PRIO_MAP[$b->getIssuePriority()] <=> self::PRIO_MAP[$a->getIssuePriority()];
|
|
});
|
|
return $toSort;
|
|
}
|
|
|
|
/**
|
|
* @param KanbanEntry[] $toSort
|
|
* @return KanbanEntry[]
|
|
*/
|
|
private function updatedAtReverseSort(array $toSort): array
|
|
{
|
|
$toSort = array_filter($toSort, function (KanbanEntry $item) {
|
|
return $item->getAssignee() != null && empty($item->getFixVersions());
|
|
});
|
|
usort($toSort, function (KanbanEntry $a, KanbanEntry $b) {
|
|
return $b->getUpdatedAt() <=> $a->getUpdatedAt();
|
|
});
|
|
return $toSort;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
function jsonSerialize()
|
|
{
|
|
return [
|
|
'inbox' => $this->prioSort($this->inbox->getValues()),
|
|
'inProgress' => $this->prioSort($this->inProgress->getValues()),
|
|
'verification' => $this->prioSort($this->verification->getValues()),
|
|
'done' => $this->updatedAtReverseSort($this->done->getValues()),
|
|
];
|
|
}
|
|
}
|