* kanban service and stuff
This commit is contained in:
260
src/App/Entity/KanbanBoard.php
Normal file
260
src/App/Entity/KanbanBoard.php
Normal file
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
class KanbanBoard implements \JsonSerializable
|
||||
{
|
||||
// const PRIO_TRIVIAL = 0;
|
||||
// const PRIO_MINOR = 1;
|
||||
// const PRIO_MAJOR = 2;
|
||||
// const PRIO_CRITICAL = 3;
|
||||
// const PRIO_BLOCKER = 4;
|
||||
|
||||
// private $priorityMap = [
|
||||
// 'Trivial' => self::PRIO_TRIVIAL,
|
||||
// 'Minor' => self::PRIO_MINOR,
|
||||
// 'Major' => self::PRIO_MAJOR,
|
||||
// 'Critical' => self::PRIO_CRITICAL,
|
||||
// 'Blocker' => self::PRIO_BLOCKER,
|
||||
// ];
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
return $a->getTaurusPrio() <=> $b->getTaurusPrio();
|
||||
});
|
||||
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()),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user