<?php
namespace App\Controller;
use App\Entity\Image;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Doctrine\ORM\EntityManagerInterface;
class EntriesController extends AbstractController
{
public array $entries;
public function index($status, EntityManagerInterface $entityManager , $option = null): Response
{
/*
:returns a render of an entries array matching the request
-> status can be a processing status of images
-> OR it can be a special status
first special statuses are checked, defaulting back to processing category
Could be changed in future Versions to treat category as a status just like the rest
*/
switch ($status) {
case 'tag':
//tags are given as option parameter via url seperated by plus (+)
$tagsarray = explode("+",$option);
$entries = $entityManager->getRepository(Image::class)->findAllByTags($tagsarray);
break;
case 'id':
//id is given as option parameter via url
$entries[] = $entityManager->getRepository(Image::class)->findById($option);
break;
default:
//return Files with a given Category
$entries = $entityManager->getRepository(Image::class)->findAllByCategory($status);
$countAllEntries = ($entityManager->getRepository(Image::class)->countAll());
$countStatus = ($entityManager->getRepository(Image::class)->countAllByCategory($status));
$count_Status_Name = $this->translate_status($status);
break;
}
//returns dummys to template
return $this->render('backend/entries.html.twig', [
'entries' => $entries,
"status" => $status,
"counts" => ["countAllEntries"=>$countAllEntries, "countStatus"=>$countStatus, "name"=>$count_Status_Name ]
]);
}
public function translate_status($status){
switch($status){
case "new":
return "neue";
break;
case "read":
return "gesichtete";
break;
case "downloaded";
return "heruntergeladene";
break;
case "deleted";
return "gelöschte";
break;
}
}
}