entityManager->getRepository(self::ENTITY)->findBy([], [ 'productLine' => 'ASC', 'model' => 'ASC', ]); $compare = static fn (Cpu $cpu1, Cpu $cpu2) => $cpu1->getId() <=> $cpu2->getId(); $filterByVendor = static function(array $items, CpuVendorString $vendorString): array { return array_filter($items, static fn (Cpu $cpu) => $cpu->getVendorString() === $vendorString); }; $notReceived = array_filter($items, static fn (CPU $cpu) => $cpu->isReceived() === FALSE); $items = array_udiff($items, $notReceived, $compare); $noVendor = array_filter($items, static fn (Cpu $cpu) => $cpu->getVendorString() === null || $cpu->getVendorString() === ''); $items = array_udiff($items, $noVendor, $compare); $amd = $filterByVendor($items, CpuVendorString::AMD); $intel = $filterByVendor($items, CpuVendorString::INTEL); $centaur = $filterByVendor($items, CpuVendorString::CENTAUR); $cyrix = $filterByVendor($items, CpuVendorString::CYRIX); $others = array_udiff($items, $amd, $intel, $centaur, $cyrix, $compare); $sort = static function (Cpu $cpu1, Cpu $cpu2) { $brandSort = $cpu1->getBrand()->getName() <=> $cpu2->getBrand()->getName(); $modelSort = $cpu1->getProductLine() <=> $cpu2->getProductLine(); return ($brandSort !== 0) ? $brandSort : $modelSort; }; usort($notReceived, $sort); usort($noVendor, $sort); usort($amd, $sort); usort($intel, $sort); usort($centaur, $sort); usort($cyrix, $sort); usort($others, $sort); return $this->render($template, [ 'all' => [ 'not_acquired' => $notReceived, 'amd' => $amd, 'intel' => $intel, 'centaur' => $centaur, 'cyrix' => $cyrix, 'no_vendor' => $noVendor, 'others' => $others, ], ]); } #[Route('/new', name: 'cpu_new', methods: ['GET', 'POST'])] public function new(Request $request): Response { return $this->itemCreate($request, 'cpu'); } #[Route('/{id}', name: 'cpu_show', methods: ['GET'])] public function show(Cpu $cpu): Response { return $this->itemView($cpu, 'cpu'); } #[Route('/{id}/edit', name: 'cpu_edit', methods: ['GET', 'POST'])] public function edit(Request $request, Cpu $cpu): Response { return $this->itemUpdate($request, $cpu, 'cpu'); } #[Route('/{id}', name: 'cpu_delete', methods: ['POST'])] public function delete(Request $request, Cpu $cpu): Response { return $this->deleteCSRF($request, $cpu); } /** * Moves a cpu to the previouslyOwned table */ #[Route(path: '/{id}/deacquire', name: 'cpu_deacquire', methods: ['POST'])] public function reacquireAction(Request $request, Cpu $cpu): RedirectResponse { return $this->itemDeacquire($request, $cpu, 'previously_owned_cpu_index'); } /** * Creates a form to move * * @param cpu $cpu The cpu entity */ private function createDeacquireForm(cpu $cpu): FormInterface { return $this->buildForm($cpu, 'cpu_deacquire'); } }