Moved getParts() and getPartsCount() to a repository (instead of a class method).

This commit is contained in:
Jan Böhmer 2020-05-16 20:53:35 +02:00
parent 350f1bb979
commit 14adb77a97
24 changed files with 421 additions and 71 deletions

View file

@ -45,6 +45,7 @@ namespace App\Controller\AdminPages;
use App\DataTables\LogDataTable;
use App\Entity\Base\AbstractNamedDBElement;
use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\Base\PartsContainingRepositoryInterface;
use App\Entity\LabelSystem\LabelProfile;
use App\Entity\UserSystem\User;
use App\Events\SecurityEvent;
@ -52,6 +53,7 @@ use App\Events\SecurityEvents;
use App\Exceptions\AttachmentDownloadException;
use App\Form\AdminPages\ImportType;
use App\Form\AdminPages\MassCreationForm;
use App\Repository\AbstractPartsContainingRepository;
use App\Services\Attachments\AttachmentSubmitHandler;
use App\Services\EntityExporter;
use App\Services\EntityImporter;
@ -100,11 +102,13 @@ abstract class BaseAdminController extends AbstractController
protected $labelGenerator;
protected $barcodeExampleGenerator;
protected $entityManager;
public function __construct(TranslatorInterface $translator, UserPasswordEncoderInterface $passwordEncoder,
AttachmentSubmitHandler $attachmentSubmitHandler,
EventCommentHelper $commentHelper, HistoryHelper $historyHelper, TimeTravel $timeTravel,
DataTableFactory $dataTableFactory, EventDispatcherInterface $eventDispatcher, BarcodeExampleElementsGenerator $barcodeExampleGenerator,
LabelGenerator $labelGenerator)
LabelGenerator $labelGenerator, EntityManagerInterface $entityManager)
{
if ('' === $this->entity_class || '' === $this->form_class || '' === $this->twig_template || '' === $this->route_base) {
throw new InvalidArgumentException('You have to override the $entity_class, $form_class, $route_base and $twig_template value in your subclasss!');
@ -128,6 +132,7 @@ abstract class BaseAdminController extends AbstractController
$this->eventDispatcher = $eventDispatcher;
$this->barcodeExampleGenerator = $barcodeExampleGenerator;
$this->labelGenerator = $labelGenerator;
$this->entityManager = $entityManager;
}
protected function _edit(AbstractNamedDBElement $entity, Request $request, EntityManagerInterface $em, ?string $timestamp = null): Response
@ -237,6 +242,10 @@ abstract class BaseAdminController extends AbstractController
$pdf_data = $this->labelGenerator->generateLabel($entity->getOptions(), $example);
}
/** @var AbstractPartsContainingRepository $repo */
$repo = $this->entityManager->getRepository($this->entity_class);
return $this->render($this->twig_template, [
'entity' => $entity,
'form' => $form->createView(),
@ -244,6 +253,7 @@ abstract class BaseAdminController extends AbstractController
'datatable' => $table,
'pdf_data' => $pdf_data ?? null,
'timeTravel' => $timeTravel_timestamp,
'repo' => $repo,
]);
}
@ -357,6 +367,7 @@ abstract class BaseAdminController extends AbstractController
$em->flush();
}
return $this->render($this->twig_template, [
'entity' => $new_entity,
'form' => $form->createView(),

View file

@ -48,6 +48,7 @@ use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use Doctrine\ORM\EntityManagerInterface;
use Omines\DataTablesBundle\DataTableFactory;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
@ -57,6 +58,13 @@ use Symfony\Component\Routing\Annotation\Route;
class PartListsController extends AbstractController
{
private $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
/**
* @Route("/category/{id}/parts", name="part_list_category")
*
@ -74,6 +82,7 @@ class PartListsController extends AbstractController
return $this->render('Parts/lists/category_list.html.twig', [
'datatable' => $table,
'entity' => $category,
'repo' => $this->entityManager->getRepository(Category::class),
]);
}
@ -94,6 +103,7 @@ class PartListsController extends AbstractController
return $this->render('Parts/lists/footprint_list.html.twig', [
'datatable' => $table,
'entity' => $footprint,
'repo' => $this->entityManager->getRepository(Footprint::class),
]);
}
@ -114,6 +124,7 @@ class PartListsController extends AbstractController
return $this->render('Parts/lists/manufacturer_list.html.twig', [
'datatable' => $table,
'entity' => $manufacturer,
'repo' => $this->entityManager->getRepository(Manufacturer::class),
]);
}
@ -134,6 +145,7 @@ class PartListsController extends AbstractController
return $this->render('Parts/lists/store_location_list.html.twig', [
'datatable' => $table,
'entity' => $storelocation,
'repo' => $this->entityManager->getRepository(Storelocation::class),
]);
}
@ -154,6 +166,7 @@ class PartListsController extends AbstractController
return $this->render('Parts/lists/supplier_list.html.twig', [
'datatable' => $table,
'entity' => $supplier,
'repo' => $this->entityManager->getRepository(Supplier::class),
]);
}