diff --git a/src/Controller/ManufacturerController.php b/src/Controller/ManufacturerController.php new file mode 100644 index 00000000..c3f841f3 --- /dev/null +++ b/src/Controller/ManufacturerController.php @@ -0,0 +1,112 @@ +_edit($entity, $request, $em); + } + + /** + * @Route("/new", name="manufacturer_new") + * @Route("/") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function new(Request $request, EntityManagerInterface $em, EntityImporter $importer) + { + return $this->_new($request, $em, $importer); + } + + /** + * @Route("/{id}", name="manufacturer_delete", methods={"DELETE"}) + */ + public function delete(Request $request, Manufacturer $entity, StructuralElementRecursionHelper $recursionHelper) + { + return $this->_delete($request, $entity, $recursionHelper); + } + + /** + * @Route("/export", name="manufacturer_export_all") + * @param Request $request + * @param SerializerInterface $serializer + * @param EntityManagerInterface $em + * @return Response + */ + public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request) + { + return $this->_exportAll($em, $exporter, $request); + } + + /** + * @Route("/{id}/export", name="manufacturer_export") + * @param Request $request + * @param Supplier $entity + */ + public function exportEntity(Manufacturer $entity, EntityExporter $exporter, Request $request) + { + return $this->_exportEntity($entity, $exporter, $request); + } + +} \ No newline at end of file diff --git a/src/Controller/SupplierController.php b/src/Controller/SupplierController.php new file mode 100644 index 00000000..00b7751c --- /dev/null +++ b/src/Controller/SupplierController.php @@ -0,0 +1,111 @@ +_edit($entity, $request, $em); + } + + /** + * @Route("/new", name="supplier_new") + * @Route("/") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function new(Request $request, EntityManagerInterface $em, EntityImporter $importer) + { + return $this->_new($request, $em, $importer); + } + + /** + * @Route("/{id}", name="supplier_delete", methods={"DELETE"}) + */ + public function delete(Request $request, Supplier $entity, StructuralElementRecursionHelper $recursionHelper) + { + return $this->_delete($request, $entity, $recursionHelper); + } + + /** + * @Route("/export", name="supplier_export_all") + * @param Request $request + * @param SerializerInterface $serializer + * @param EntityManagerInterface $em + * @return Response + */ + public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request) + { + return $this->_exportAll($em, $exporter, $request); + } + + /** + * @Route("/{id}/export", name="supplier_export") + * @param Request $request + * @param Supplier $entity + */ + public function exportEntity(Supplier $entity, EntityExporter $exporter, Request $request) + { + return $this->_exportEntity($entity, $exporter, $request); + } + +} \ No newline at end of file diff --git a/src/Entity/Company.php b/src/Entity/Company.php index 757c6600..fef3954d 100644 --- a/src/Entity/Company.php +++ b/src/Entity/Company.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace App\Entity; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints as Assert; /** * This abstract class is used for companies like suppliers or manufacturers. @@ -36,37 +37,39 @@ abstract class Company extends StructuralDBElement * @var string The address of the company * @ORM\Column(type="string") */ - protected $address; + protected $address = ""; /** * @var string The phone number of the company * @ORM\Column(type="string") */ - protected $phone_number; + protected $phone_number = ""; /** * @var string The fax number of the company * @ORM\Column(type="string") */ - protected $fax_number; + protected $fax_number = ""; /** * @var string The email address of the company * @ORM\Column(type="string") + * @Assert\Email() */ - protected $email_address; + protected $email_address = ""; /** * @var string The website of the company * @ORM\Column(type="string") + * @Assert\Url() */ - protected $website; + protected $website = ""; /** * @var string * @ORM\Column(type="string") */ - protected $auto_product_url; + protected $auto_product_url = ""; /******************************************************************************** * diff --git a/src/Form/CompanyForm.php b/src/Form/CompanyForm.php new file mode 100644 index 00000000..60fbcda1 --- /dev/null +++ b/src/Form/CompanyForm.php @@ -0,0 +1,86 @@ +getID() === null; + + $builder->add('address', TextareaType::class, ['label' => 'company.address.label', + 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), + 'attr' => ['placeholder' => 'company.address.placeholder'], 'required' => false, + 'empty_data' => '' + ]); + + $builder->add('phone_number', TelType::class, ['label' => 'company.phone_number.label', + 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), + 'attr' => ['placeholder' => 'company.phone_number.placeholder'], 'required' => false, + 'empty_data' => '' + ]); + + $builder->add('fax_number', TelType::class, ['label' => 'company.fax_number.label', + 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), + 'attr' => ['placeholder' => 'company.fax_number.placeholder'], 'required' => false, + 'empty_data' => '' + ]); + + $builder->add('email_address', EmailType::class, ['label' => 'company.email.label', + 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), + 'attr' => ['placeholder' => 'company.email.placeholder'], 'required' => false, + 'empty_data' => '' + ]); + + $builder->add('website', UrlType::class, ['label' => 'company.website.label', + 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), + 'attr' => ['placeholder' => 'company.website.placeholder'], 'required' => false, + 'empty_data' => '' + ]); + + $builder->add('auto_product_url', UrlType::class, ['label' => 'company.auto_product_url.label', + 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), + 'attr' => ['placeholder' => 'company.auto_product_url.placeholder'], 'required' => false, + 'empty_data' => '' + ]); + } +} \ No newline at end of file diff --git a/src/Services/EntityURLGenerator.php b/src/Services/EntityURLGenerator.php index 7661f29a..9e56e471 100644 --- a/src/Services/EntityURLGenerator.php +++ b/src/Services/EntityURLGenerator.php @@ -32,8 +32,10 @@ namespace App\Services; use App\Entity\AttachmentType; use App\Entity\Category; use App\Entity\Device; +use App\Entity\Manufacturer; use App\Entity\NamedDBElement; use App\Entity\Part; +use App\Entity\Supplier; use App\Exceptions\EntityNotSupported; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -123,6 +125,14 @@ class EntityURLGenerator return $this->urlGenerator->generate("device_edit", ['id' => $entity->getID()]); } + if ($entity instanceof Supplier) { + return $this->urlGenerator->generate("supplier_edit", ['id' => $entity->getID()]); + } + + if ($entity instanceof Manufacturer) { + return $this->urlGenerator->generate("manufacturer_edit", ['id' => $entity->getID()]); + } + //Otherwise throw an error throw new EntityNotSupported('The given entity is not supported yet!'); } @@ -152,6 +162,14 @@ class EntityURLGenerator return $this->urlGenerator->generate('device_new'); } + if ($entity instanceof Supplier) { + return $this->urlGenerator->generate('supplier_new'); + } + + if ($entity instanceof Manufacturer) { + return $this->urlGenerator->generate('manufacturer_new'); + } + throw new EntityNotSupported('The given entity is not supported yet!'); } @@ -202,6 +220,14 @@ class EntityURLGenerator return $this->urlGenerator->generate('device_delete', ['id' => $entity->getID()]); } + if ($entity instanceof Supplier) { + return $this->urlGenerator->generate('supplier_delete', ['id' => $entity->getID()]); + } + + if ($entity instanceof Manufacturer) { + return $this->urlGenerator->generate('manufacturer_new', ['id' => $entity->getID()]); + } + throw new EntityNotSupported('The given entity is not supported yet!'); } diff --git a/templates/AdminPages/CompanyAdminBase.html.twig b/templates/AdminPages/CompanyAdminBase.html.twig new file mode 100644 index 00000000..03547f9c --- /dev/null +++ b/templates/AdminPages/CompanyAdminBase.html.twig @@ -0,0 +1,23 @@ +{% extends "AdminPages/EntityAdminBase.html.twig" %} + +{% block additional_controls %} + {{ form_row(form.address) }} + {{ form_row(form.phone_number) }} + {{ form_row(form.fax_number) }} + {{ form_row(form.email_address) }} + {{ form_row(form.website) }} + {{ form_row(form.auto_product_url) }} +{% endblock %} + +{% block comment %}{% endblock %} + +{% block additional_pills %} + +{% endblock %} + +{% block additional_panes %} +
+ {{ form_row(form.comment) }} +
+ +{% endblock %} \ No newline at end of file diff --git a/templates/AdminPages/EntityAdminBase.html.twig b/templates/AdminPages/EntityAdminBase.html.twig index 6dcb1ebc..5537a622 100644 --- a/templates/AdminPages/EntityAdminBase.html.twig +++ b/templates/AdminPages/EntityAdminBase.html.twig @@ -66,7 +66,13 @@
{{ form_row(form.name) }} {{ form_row(form.parent) }} + + {% block additional_controls %}{% endblock %} + + {% block comment %} {{ form_row(form.comment) }} + {% endblock %} +
{% block additional_panes %}{% endblock %} diff --git a/templates/AdminPages/ManufacturerAdmin.html.twig b/templates/AdminPages/ManufacturerAdmin.html.twig new file mode 100644 index 00000000..9d5db787 --- /dev/null +++ b/templates/AdminPages/ManufacturerAdmin.html.twig @@ -0,0 +1,5 @@ +{% extends "AdminPages/CompanyAdminBase.html.twig" %} + +{% block card_title %} + {% trans %}manufacturer.caption{% endtrans %} +{% endblock %} \ No newline at end of file diff --git a/templates/AdminPages/SupplierAdmin.html.twig b/templates/AdminPages/SupplierAdmin.html.twig new file mode 100644 index 00000000..a5aa3059 --- /dev/null +++ b/templates/AdminPages/SupplierAdmin.html.twig @@ -0,0 +1,5 @@ +{% extends "AdminPages/CompanyAdminBase.html.twig" %} + +{% block card_title %} + {% trans %}supplier.caption{% endtrans %} +{% endblock %} \ No newline at end of file