diff --git a/src/Controller/AdminPages/MeasurementUnitController.php b/src/Controller/AdminPages/MeasurementUnitController.php new file mode 100644 index 00000000..86f8f49b --- /dev/null +++ b/src/Controller/AdminPages/MeasurementUnitController.php @@ -0,0 +1,110 @@ +_edit($entity, $request, $em); + } + + /** + * @Route("/new", name="measurement_unit_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="measurement_unit_delete", methods={"DELETE"}) + */ + public function delete(Request $request, MeasurementUnit $entity, StructuralElementRecursionHelper $recursionHelper) + { + return $this->_delete($request, $entity, $recursionHelper); + } + + /** + * @Route("/export", name="measurement_unit_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="measurement_unit_export") + * @param Request $request + * @param AttachmentType $entity + */ + public function exportEntity(AttachmentType $entity, EntityExporter $exporter, Request $request) + { + return $this->_exportEntity($entity, $exporter, $request); + } + +} \ No newline at end of file diff --git a/src/Entity/Parts/MeasurementUnit.php b/src/Entity/Parts/MeasurementUnit.php index 04cd2b9a..06e4d1c7 100644 --- a/src/Entity/Parts/MeasurementUnit.php +++ b/src/Entity/Parts/MeasurementUnit.php @@ -32,9 +32,11 @@ namespace App\Entity\Parts; +use App\Entity\Base\PartsContainingDBElement; use App\Entity\Base\StructuralDBElement; use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; +use Symfony\Component\Validator\Constraints as Assert; /** * This unit represents the unit in which the amount of parts in stock are measured. @@ -45,13 +47,14 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; * @ORM\Table(name="`measurement_units`") * @UniqueEntity("unit") */ -class MeasurementUnit extends StructuralDBElement +class MeasurementUnit extends PartsContainingDBElement { /** * @var string The unit symbol that should be used for the Unit. This could be something like "", g (for gramms) * or m (for meters). - * @ORM\Column(type="string", name="unit") + * @ORM\Column(type="string", name="unit", nullable=true) + * @Assert\Length(max=10) */ protected $unit; @@ -60,14 +63,14 @@ class MeasurementUnit extends StructuralDBElement * Set to false, to measure continuous sizes likes masses or lengthes. * @ORM\Column(type="boolean", name="is_integer") */ - protected $isInteger; + protected $is_integer = false; /** * @var bool Determines if the unit can be used with SI Prefixes (kilo, giga, milli, etc.). * Useful for sizes like meters. * @ORM\Column(type="boolean", name="use_si_prefix") */ - protected $usesSIPrefixes; + protected $use_si_prefix = false; /** * @ORM\OneToMany(targetEntity="MeasurementUnit", mappedBy="parent", cascade={"persist"}) @@ -95,7 +98,7 @@ class MeasurementUnit extends StructuralDBElement /** * @return string */ - public function getUnit(): string + public function getUnit(): ?string { return $this->unit; } @@ -104,7 +107,7 @@ class MeasurementUnit extends StructuralDBElement * @param string $unit * @return MeasurementUnit */ - public function setUnit(string $unit): MeasurementUnit + public function setUnit(?string $unit): MeasurementUnit { $this->unit = $unit; return $this; @@ -115,7 +118,7 @@ class MeasurementUnit extends StructuralDBElement */ public function isInteger(): bool { - return $this->isInteger; + return $this->is_integer; } /** @@ -131,21 +134,18 @@ class MeasurementUnit extends StructuralDBElement /** * @return bool */ - public function isUsesSIPrefixes(): bool + public function isUseSIPrefix(): bool { - return $this->usesSIPrefixes; + return $this->use_si_prefix; } /** * @param bool $usesSIPrefixes * @return MeasurementUnit */ - public function setUsesSIPrefixes(bool $usesSIPrefixes): MeasurementUnit + public function setUseSIPrefix(bool $usesSIPrefixes): MeasurementUnit { - $this->usesSIPrefixes = $usesSIPrefixes; + $this->useSIPrefixes = $usesSIPrefixes; return $this; } - - - } \ No newline at end of file diff --git a/src/Form/AdminPages/MeasurementUnitAdminForm.php b/src/Form/AdminPages/MeasurementUnitAdminForm.php new file mode 100644 index 00000000..48afb9a7 --- /dev/null +++ b/src/Form/AdminPages/MeasurementUnitAdminForm.php @@ -0,0 +1,62 @@ +getID() === null; + + $builder->add('is_integer', CheckboxType::class, ['required' => false, + 'label' => 'measurement_unit.is_integer.label', 'help' => 'measurement_unit.is_integer.help', + 'label_attr'=> ['class' => 'checkbox-custom'], + 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]); + + $builder->add('use_si_prefix', CheckboxType::class, ['required' => false, + 'label' => 'measurement_unit.use_si_prefix.label', 'help' => 'measurement_unit.use_si_prefix.help', + 'label_attr'=> ['class' => 'checkbox-custom'], + 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]); + + $builder->add('unit', TextType::class, ['required' => false, + 'label' => 'measurement_unit.unit.label', 'attr' => ['placeholder' => 'measurement_unit.unit.placeholder'], + 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]); + + } +} \ No newline at end of file diff --git a/src/Migrations/Version20190812154222.php b/src/Migrations/Version20190812154222.php index 5cc179f0..0356e07c 100644 --- a/src/Migrations/Version20190812154222.php +++ b/src/Migrations/Version20190812154222.php @@ -22,7 +22,7 @@ final class Version20190812154222 extends AbstractMigration // this up() migration is auto-generated, please modify it to your needs $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); - $this->addSql('CREATE TABLE `measurement_units` (id INT AUTO_INCREMENT NOT NULL, unit VARCHAR(255) NOT NULL, is_integer TINYINT(1) NOT NULL, use_si_prefix TINYINT(1) NOT NULL, comment LONGTEXT NOT NULL, parent_id INT DEFAULT NULL, not_selectable TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME NOT NULL, datetime_added DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); + $this->addSql('CREATE TABLE `measurement_units` (id INT AUTO_INCREMENT NOT NULL, unit VARCHAR(255) DEFAULT NULL, is_integer TINYINT(1) NOT NULL, use_si_prefix TINYINT(1) NOT NULL, comment LONGTEXT NOT NULL, parent_id INT DEFAULT NULL, not_selectable TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME NOT NULL, datetime_added DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); $this->addSql('CREATE TABLE part_lots (id INT AUTO_INCREMENT NOT NULL, id_store_location INT DEFAULT NULL, id_part INT DEFAULT NULL, description LONGTEXT NOT NULL, comment LONGTEXT NOT NULL, expiration_date DATETIME DEFAULT NULL, instock_unknown TINYINT(1) NOT NULL, instock INT DEFAULT NULL, amount DOUBLE PRECISION DEFAULT NULL, needs_refill TINYINT(1) NOT NULL, last_modified DATETIME NOT NULL, datetime_added DATETIME NOT NULL, INDEX IDX_EBC8F9435D8F4B37 (id_store_location), INDEX IDX_EBC8F943C22F6CC4 (id_part), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); $this->addSql('CREATE TABLE currencies (id INT AUTO_INCREMENT NOT NULL, iso_code VARCHAR(255) NOT NULL, exchange_rate NUMERIC(11, 5) DEFAULT NULL, comment LONGTEXT NOT NULL, parent_id INT DEFAULT NULL, not_selectable TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME NOT NULL, datetime_added DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); $this->addSql('ALTER TABLE part_lots ADD CONSTRAINT FK_EBC8F9435D8F4B37 FOREIGN KEY (id_store_location) REFERENCES `storelocations` (id)'); diff --git a/src/Security/Voter/StructureVoter.php b/src/Security/Voter/StructureVoter.php index 8f0ea031..3d1c7a6b 100644 --- a/src/Security/Voter/StructureVoter.php +++ b/src/Security/Voter/StructureVoter.php @@ -37,6 +37,7 @@ use App\Entity\Devices\Device; use App\Entity\Parts\Category; use App\Entity\Parts\Footprint; use App\Entity\Parts\Manufacturer; +use App\Entity\Parts\MeasurementUnit; use App\Entity\Parts\Storelocation; use App\Entity\Parts\Supplier; use App\Entity\PriceInformations\Currency; @@ -87,6 +88,9 @@ class StructureVoter extends ExtendedVoter case Currency::class: //TODO: Implement own permission return 'suppliers'; + case MeasurementUnit::class: + //TODO: Implement own permission + return 'suppliers'; } //When the class is not supported by this class return null return null; diff --git a/src/Services/EntityURLGenerator.php b/src/Services/EntityURLGenerator.php index 15f77c70..726f3f35 100644 --- a/src/Services/EntityURLGenerator.php +++ b/src/Services/EntityURLGenerator.php @@ -36,6 +36,7 @@ use App\Entity\Devices\Device; use App\Entity\Parts\Footprint; use App\Entity\Parts\Manufacturer; use App\Entity\Base\NamedDBElement; +use App\Entity\Parts\MeasurementUnit; use App\Entity\Parts\Part; use App\Entity\Parts\Storelocation; use App\Entity\Parts\Supplier; @@ -185,6 +186,10 @@ class EntityURLGenerator return $this->urlGenerator->generate('currency_edit', ['id' => $entity->getID()]); } + if ($entity instanceof MeasurementUnit) { + return $this->urlGenerator->generate('measurement_unit_edit', ['id' => $entity->getID()]); + } + //Otherwise throw an error throw new EntityNotSupported('The given entity is not supported yet!'); } @@ -238,6 +243,10 @@ class EntityURLGenerator return $this->urlGenerator->generate('currency_new'); } + if ($entity instanceof MeasurementUnit) { + return $this->urlGenerator->generate('measurement_unit_new'); + } + throw new EntityNotSupported('The given entity is not supported yet!'); } @@ -312,6 +321,10 @@ class EntityURLGenerator return $this->urlGenerator->generate('currency_delete', ['id' => $entity->getID()]); } + if ($entity instanceof MeasurementUnit) { + return $this->urlGenerator->generate('measurement_unit_delete', ['id' => $entity->getID()]); + } + throw new EntityNotSupported('The given entity is not supported yet!'); } diff --git a/src/Services/ToolsTreeBuilder.php b/src/Services/ToolsTreeBuilder.php index 9dbcb424..b02b24c1 100644 --- a/src/Services/ToolsTreeBuilder.php +++ b/src/Services/ToolsTreeBuilder.php @@ -79,6 +79,9 @@ class ToolsTreeBuilder $nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.currency'), $this->urlGenerator->generate('currency_new')); + $nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.measurement_unit'), + $this->urlGenerator->generate('measurement_unit_new')); + $nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.part'), $this->urlGenerator->generate('part_new')); diff --git a/templates/AdminPages/MeasurementUnitAdmin.html.twig b/templates/AdminPages/MeasurementUnitAdmin.html.twig new file mode 100644 index 00000000..288014c5 --- /dev/null +++ b/templates/AdminPages/MeasurementUnitAdmin.html.twig @@ -0,0 +1,11 @@ +{% extends "AdminPages/EntityAdminBase.html.twig" %} + +{% block card_title %} + {% trans %}measurement_unit.caption{% endtrans %} +{% endblock %} + +{% block additional_controls %} + {{ form_row(form.unit) }} + {{ form_row(form.is_integer) }} + {{ form_row(form.use_si_prefix)}} +{% endblock %} \ No newline at end of file