diff --git a/composer.lock b/composer.lock index 0d7ba1c..019489d 100644 --- a/composer.lock +++ b/composer.lock @@ -853,23 +853,23 @@ }, { "name": "doctrine/inflector", - "version": "2.0.5", + "version": "2.0.6", "source": { "type": "git", "url": "https://github.com/doctrine/inflector.git", - "reference": "ade2b3bbfb776f27f0558e26eed43b5d9fe1b392" + "reference": "d9d313a36c872fd6ee06d9a6cbcf713eaa40f024" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/inflector/zipball/ade2b3bbfb776f27f0558e26eed43b5d9fe1b392", - "reference": "ade2b3bbfb776f27f0558e26eed43b5d9fe1b392", + "url": "https://api.github.com/repos/doctrine/inflector/zipball/d9d313a36c872fd6ee06d9a6cbcf713eaa40f024", + "reference": "d9d313a36c872fd6ee06d9a6cbcf713eaa40f024", "shasum": "" }, "require": { "php": "^7.2 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^9", + "doctrine/coding-standard": "^10", "phpstan/phpstan": "^1.8", "phpstan/phpstan-phpunit": "^1.1", "phpstan/phpstan-strict-rules": "^1.3", @@ -924,7 +924,7 @@ ], "support": { "issues": "https://github.com/doctrine/inflector/issues", - "source": "https://github.com/doctrine/inflector/tree/2.0.5" + "source": "https://github.com/doctrine/inflector/tree/2.0.6" }, "funding": [ { @@ -940,7 +940,7 @@ "type": "tidelift" } ], - "time": "2022-09-07T09:01:28+00:00" + "time": "2022-10-20T09:10:12+00:00" }, { "name": "doctrine/instantiator", @@ -6472,12 +6472,12 @@ "source": { "type": "git", "url": "https://github.com/Roave/SecurityAdvisories.git", - "reference": "c8e297691dcc30deef58efddd6765c8b7821be56" + "reference": "4ed057f00e70bf1a45434fbc6fe14790684ff3c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/c8e297691dcc30deef58efddd6765c8b7821be56", - "reference": "c8e297691dcc30deef58efddd6765c8b7821be56", + "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/4ed057f00e70bf1a45434fbc6fe14790684ff3c5", + "reference": "4ed057f00e70bf1a45434fbc6fe14790684ff3c5", "shasum": "" }, "conflict": { @@ -6750,6 +6750,7 @@ "phpmailer/phpmailer": "<6.5", "phpmussel/phpmussel": ">=1,<1.6", "phpmyadmin/phpmyadmin": "<5.1.3", + "phpmyfaq/phpmyfaq": "<=3.1.7", "phpoffice/phpexcel": "<1.8", "phpoffice/phpspreadsheet": "<1.16", "phpseclib/phpseclib": "<2.0.31|>=3,<3.0.7", @@ -6880,6 +6881,7 @@ "thelia/thelia": ">=2.1-beta.1,<2.1.3", "theonedemon/phpwhois": "<=4.2.5", "thinkcmf/thinkcmf": "<=5.1.7", + "thorsten/phpmyfaq": "<=3.1.7", "tinymce/tinymce": "<5.10", "titon/framework": ">=0,<9.9.99", "topthink/framework": "<=6.0.13", @@ -6991,7 +6993,7 @@ "type": "tidelift" } ], - "time": "2022-10-18T22:04:50+00:00" + "time": "2022-10-19T23:05:04+00:00" }, { "name": "sebastian/cli-parser", diff --git a/src/Controller/SocketController.php b/src/Controller/SocketController.php new file mode 100644 index 0000000..af454a4 --- /dev/null +++ b/src/Controller/SocketController.php @@ -0,0 +1,84 @@ +getRepository(Socket::class) + ->findAll(); + + return $this->render('socket/index.html.twig', [ + 'sockets' => $sockets, + ]); + } + + #[Route('/new', name: 'socket_new', methods: ['GET', 'POST'])] + public function new(Request $request, EntityManagerInterface $entityManager): Response + { + $socket = new Socket(); + $form = $this->createForm(SocketType::class, $socket); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $entityManager->persist($socket); + $entityManager->flush(); + + return $this->redirectToRoute('socket_index', [], Response::HTTP_SEE_OTHER); + } + + return $this->renderForm('socket/new.html.twig', [ + 'socket' => $socket, + 'form' => $form, + ]); + } + + #[Route('/{id}', name: 'socket_show', methods: ['GET'])] + public function show(Socket $socket): Response + { + return $this->render('socket/show.html.twig', [ + 'socket' => $socket, + ]); + } + + #[Route('/{id}/edit', name: 'socket_edit', methods: ['GET', 'POST'])] + public function edit(Request $request, Socket $socket, EntityManagerInterface $entityManager): Response + { + $form = $this->createForm(SocketType::class, $socket); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $entityManager->flush(); + + return $this->redirectToRoute('socket_index', [], Response::HTTP_SEE_OTHER); + } + + return $this->renderForm('socket/edit.html.twig', [ + 'socket' => $socket, + 'form' => $form, + ]); + } + + #[Route('/{id}', name: 'socket_delete', methods: ['POST'])] + public function delete(Request $request, Socket $socket, EntityManagerInterface $entityManager): Response + { + if ($this->isCsrfTokenValid('delete'.$socket->getId(), $request->request->get('_token'))) { + $entityManager->remove($socket); + $entityManager->flush(); + } + + return $this->redirectToRoute('socket_index', [], Response::HTTP_SEE_OTHER); + } +} diff --git a/src/Entity/Brand.php b/src/Entity/Brand.php index 71e8e04..a0f1f22 100644 --- a/src/Entity/Brand.php +++ b/src/Entity/Brand.php @@ -2,13 +2,12 @@ namespace App\Entity; -use App\Repository\BrandRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; #[ORM\Table(name: 'brand', schema: 'collection')] -#[ORM\Entity]//(repositoryClass: BrandRepository::class)] +#[ORM\Entity] #[ORM\UniqueConstraint(name: 'brand_unq', columns: ["name"])] class Brand { @@ -20,12 +19,15 @@ class Brand #[ORM\SequenceGenerator(sequenceName: 'brand_id_seq', allocationSize: 1, initialValue: 1)] private int $id; + /** + * @var Collection + */ #[ORM\ManyToMany(targetEntity: BrandCategory::class)] #[ORM\JoinTable(name: 'collection.brand_category_link')] #[ORM\JoinColumn(name: 'brand_id', referencedColumnName: 'id')] #[ORM\InverseJoinColumn(name: 'brand_category', referencedColumnName: 'category_name')] #[ORM\OrderBy(['name' => 'asc'])] - private $categories; + private Collection $categories; #[ORM\Column(name: 'name', unique: TRUE, nullable: FALSE)] private string $name; @@ -40,14 +42,6 @@ class Brand return $this->name; } - /** - * @return Collection - */ - public function getCategories(): Collection - { - return $this->categories; - } - public function addCategory(BrandCategory $category): self { if (!$this->categories->contains($category)) { diff --git a/src/Entity/Cpu.php b/src/Entity/Cpu.php index f394194..fb7d456 100644 --- a/src/Entity/Cpu.php +++ b/src/Entity/Cpu.php @@ -2,6 +2,7 @@ namespace App\Entity; +use Doctrine\Common\Collections\{Collection, ArrayCollection}; use Doctrine\ORM\Mapping as ORM; #[ORM\Table(name: 'cpu', schema: 'collection')] @@ -18,4 +19,36 @@ class Cpu { #[ORM\OrderBy(['name' => 'asc'])] #[ORM\JoinColumn(name: 'brand_id', referencedColumnName: 'id', nullable: FALSE)] private Brand $brand; + + /** + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: Socket::class)] + #[ORM\JoinTable(name: 'collection.cpu_socket_link')] + #[ORM\JoinColumn(name: 'socket_id', referencedColumnName: 'id')] + #[ORM\InverseJoinColumn(name: 'cpu_id', referencedColumnName: 'id')] + #[ORM\OrderBy(['name' => 'asc'])] + private Collection $sockets; + + public function __construct() + { + $this->sockets = new ArrayCollection(); + } + + public function addSocket(Socket $socket): self + { + if ( ! $this->sockets->contains($socket)) + { + $this->sockets->add($socket); + } + + return $this; + } + + public function removeSocket(Socket $socket): self + { + $this->sockets->removeElement($socket); + + return $this; + } } diff --git a/src/Entity/Socket.php b/src/Entity/Socket.php new file mode 100644 index 0000000..ae2458a --- /dev/null +++ b/src/Entity/Socket.php @@ -0,0 +1,43 @@ +otherName)) ? "$this->name/$this->otherName" : $this->name; + + return "$name ($this->type->value $this->pinCount)"; + } +} diff --git a/src/Enum/SocketTypeEnum.php b/src/Enum/SocketTypeEnum.php new file mode 100644 index 0000000..b765da9 --- /dev/null +++ b/src/Enum/SocketTypeEnum.php @@ -0,0 +1,12 @@ + + $e->createQueryBuilder('b') + ->join('b.categories', 'bc') + ->where('bc.name=:name') + ->orderBy('b.name', 'ASC') + ->setParameter('name', $filter); + } +} diff --git a/src/Form/GPUCoreType.php b/src/Form/GPUCoreType.php index e596e76..d603591 100644 --- a/src/Form/GPUCoreType.php +++ b/src/Form/GPUCoreType.php @@ -10,12 +10,14 @@ use Symfony\Component\OptionsResolver\OptionsResolver; class GPUCoreType extends AbstractType { + use BrandCategoryTrait; + public function buildForm(FormBuilderInterface $builder, array $options): void - { + { $builder ->add('brand', EntityType::class, [ 'class' => Brand::class, - 'query_builder' => static fn (EntityRepository $e) => $e->createQueryBuilder('b')->orderBy('b.name', 'ASC'), + 'query_builder' => self::filterBrands('gpu_core'), ]) ->add('name') ->add('variant') @@ -33,3 +35,4 @@ class GPUCoreType extends AbstractType ]); } } + diff --git a/src/Form/GpuType.php b/src/Form/GpuType.php index e30c643..258890e 100644 --- a/src/Form/GpuType.php +++ b/src/Form/GpuType.php @@ -12,14 +12,14 @@ use Symfony\Component\OptionsResolver\OptionsResolver; use UnitEnum; class GpuType extends AbstractType { + use BrandCategoryTrait; + public function buildForm(FormBuilderInterface $builder, array $options): void { - $brandQueryBuilder = static fn(EntityRepository $e) => $e->createQueryBuilder('b')->orderBy('b.name', 'ASC'); - $builder ->add('gpuBrand', EntityType::class, [ 'class' => Brand::class, - 'query_builder' => $brandQueryBuilder, + 'query_builder' => self::filterBrands('gpu_core'), ]) ->add('modelName') ->add('gpuCore', EntityType::class, [ @@ -31,7 +31,7 @@ class GpuType extends AbstractType { ]) ->add('boardBrand', EntityType::class, [ 'class' => Brand::class, - 'query_builder' => $brandQueryBuilder, + 'query_builder' => self::filterBrands('graphics_card'), 'empty_data' => NULL, 'placeholder' => 'Unknown', 'required' => FALSE, diff --git a/src/Form/SocketType.php b/src/Form/SocketType.php new file mode 100644 index 0000000..f2b312e --- /dev/null +++ b/src/Form/SocketType.php @@ -0,0 +1,32 @@ +add('name') + ->add('otherName') + ->add('pinCount') + ->add('type', EnumType::class,[ + 'class' => SocketTypeEnum::class, + ]) + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => Socket::class, + ]); + } +} diff --git a/src/Migrations/Version20221019183925.php b/src/Migrations/Version20221019183925.php new file mode 100644 index 0000000..17e60a7 --- /dev/null +++ b/src/Migrations/Version20221019183925.php @@ -0,0 +1,32 @@ +addSql('CREATE TABLE collection.socket (id SERIAL NOT NULL, name VARCHAR(255) NOT NULL, other_name VARCHAR(255) DEFAULT NULL, pin_count INT NOT NULL, socket_type VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('DROP TABLE collection.socket'); + } +} diff --git a/src/Repository/BrandRepository.php b/src/Repository/BrandRepository.php deleted file mode 100644 index f439a85..0000000 --- a/src/Repository/BrandRepository.php +++ /dev/null @@ -1,21 +0,0 @@ -getEntityManager(); - $query = $em->createQuery(" - SELECT b FROM App\Entity\Brand b - INNER JOIN b.categories c WHERE c.name = ?1 - ORDER BY b.name ASC - "); - $query->setParameter(1, $category); - - return $query->execute(); - } -} diff --git a/templates/header.html.twig b/templates/header.html.twig index 9f0b5ed..e20dcb1 100644 --- a/templates/header.html.twig +++ b/templates/header.html.twig @@ -9,7 +9,9 @@
  • 💃 Brand Categories
  • - +
  • + 📍Sockets +
  • 🐏 Ram Types
  • @@ -58,7 +60,13 @@ 🎮 Graphics Cards
  • - 🧮 CPUs + 🧠 CPUs +
  • +
  • + 🧮 FPUs +
  • +
  • + 🤰 Motherboards
  • diff --git a/templates/socket/edit.html.twig b/templates/socket/edit.html.twig new file mode 100644 index 0000000..6460bdd --- /dev/null +++ b/templates/socket/edit.html.twig @@ -0,0 +1,27 @@ +{% extends 'form.html.twig' %} + +{% block title %}Edit Socket{% endblock %} + +{% block form %} +

    Edit Socket

    + +
    + +
    + +
    + {{ form_start(form) }} + {{ form_widget(form) }} + + {{ form_end(form) }} + +
    + + +
    +
    +{% endblock %} diff --git a/templates/socket/index.html.twig b/templates/socket/index.html.twig new file mode 100644 index 0000000..d9db568 --- /dev/null +++ b/templates/socket/index.html.twig @@ -0,0 +1,54 @@ +{% extends 'form.html.twig' %} + +{% block title %}Socket{% endblock %} + +{% block form %} +

    Sockets

    + +
    + +
    + + + + + + + + + + + + + + + {% for socket in sockets %} + + + + + + + + + {% else %} + + + + {% endfor %} + +
     IdNameOtherNamePinCountType
    + + {{ socket.id }}{{ socket.name }}{{ socket.otherName }}{{ socket.pinCount }}{{ socket.type.value }}
    no records found
    +{% endblock %} diff --git a/templates/socket/new.html.twig b/templates/socket/new.html.twig new file mode 100644 index 0000000..09724d6 --- /dev/null +++ b/templates/socket/new.html.twig @@ -0,0 +1,22 @@ +{% extends 'form.html.twig' %} + +{% block title %}New Socket{% endblock %} + +{% block form %} +

    Add a Socket

    + +
    + +
    + +
    + {{ form_start(form) }} + {{ form_widget(form) }} + + {{ form_end(form) }} +
    +{% endblock %} diff --git a/templates/socket/show.html.twig b/templates/socket/show.html.twig new file mode 100644 index 0000000..5d1b7be --- /dev/null +++ b/templates/socket/show.html.twig @@ -0,0 +1,55 @@ +{% extends 'form.html.twig' %} + +{% block title %}Socket{% endblock %} + +{% block form %} +

    Socket

    + +
    + + + +
    + + +
    + + +
    +
    + +
    + + + + + + + + + + + + + + + + + + + + + + + + +
    Id{{ socket.id }}
    Name{{ socket.name }}
    OtherName{{ socket.otherName }}
    PinCount{{ socket.pinCount }}
    Type{{ socket.type.value }}
    +
    +{% endblock %}