diff --git a/src/App/Entity/KanbanBoard.php b/src/App/Entity/KanbanBoard.php index fba7f94..e933440 100644 --- a/src/App/Entity/KanbanBoard.php +++ b/src/App/Entity/KanbanBoard.php @@ -6,6 +6,20 @@ 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 */ @@ -202,16 +216,28 @@ class KanbanBoard implements \JsonSerializable return $this; } + /** + * @param KanbanEntry[] $toSort + * @return KanbanEntry[] + */ + private function prioSort(array $toSort): array + { + usort($toSort, function(KanbanEntry $a, KanbanEntry $b){ + return $this->priorityMap[$b->getIssuePriority()] <=> $this->priorityMap[$a->getIssuePriority()]; + }); + return $toSort; + } + /** * @return array */ function jsonSerialize() { return [ - 'inbox' => $this->inbox->getValues(), - 'inProgress' => $this->inProgress->getValues(), - 'verification' => $this->verification->getValues(), - 'done' => $this->done->getValues(), + 'inbox' => $this->prioSort($this->inbox->getValues()), + 'inProgress' => $this->prioSort($this->inProgress->getValues()), + 'verification' => $this->prioSort($this->verification->getValues()), + 'done' => $this->prioSort($this->done->getValues()), ]; } }