Added very basic possibility to add an association

This commit is contained in:
Jan Böhmer 2023-11-13 00:11:58 +01:00
parent b7cfdebad5
commit 8ab9cf1417
8 changed files with 143 additions and 6 deletions

View file

@ -29,6 +29,7 @@ use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartAssociation;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\StorageLocation;
use App\Entity\Parts\Supplier;
@ -63,6 +64,8 @@ enum LogTargetType: int
case PARAMETER = 18;
case LABEL_PROFILE = 19;
case PART_ASSOCIATION = 20;
/**
* Returns the class name of the target type or null if the target type is NONE.
* @return string|null
@ -90,6 +93,7 @@ enum LogTargetType: int
self::MEASUREMENT_UNIT => MeasurementUnit::class,
self::PARAMETER => AbstractParameter::class,
self::LABEL_PROFILE => LabelProfile::class,
self::PART_ASSOCIATION => PartAssociation::class,
};
}

View file

@ -26,7 +26,7 @@ namespace App\Entity\Parts;
/**
* The values of this enums are used to describe how two parts are associated with each other.
*/
enum PartAssociationType: int
enum AssociationType: int
{
/** A user definable association type, which can be described in the comment field */
case OTHER = 0;

View file

@ -41,10 +41,10 @@ class PartAssociation extends AbstractDBElement
use TimestampTrait;
/**
* @var PartAssociationType The type of this association (how the two parts are related)
* @var AssociationType The type of this association (how the two parts are related)
*/
#[ORM\Column(type: Types::SMALLINT, enumType: PartAssociationType::class)]
protected PartAssociationType $type = PartAssociationType::OTHER;
#[ORM\Column(type: Types::SMALLINT, enumType: AssociationType::class)]
protected AssociationType $type = AssociationType::OTHER;
/**
* @var string|null A comment describing this association further. Can also be used to specify the OTHER type
@ -69,12 +69,12 @@ class PartAssociation extends AbstractDBElement
#[Assert\NotNull]
protected ?Part $other = null;
public function getType(): PartAssociationType
public function getType(): AssociationType
{
return $this->type;
}
public function setType(PartAssociationType $type): PartAssociation
public function setType(AssociationType $type): PartAssociation
{
$this->type = $type;
return $this;

View file

@ -0,0 +1,57 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2023 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Form\Part;
use App\Entity\Parts\AssociationType;
use App\Entity\Parts\PartAssociation;
use App\Form\Type\PartSelectType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class PartAssociationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('type', EnumType::class, [
'class' => AssociationType::class,
])
->add('other', PartSelectType::class)
->add('comment', TextType::class, [
'required' => false,
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => PartAssociation::class,
]);
}
}

View file

@ -245,6 +245,16 @@ class PartBaseType extends AbstractType
],
]);
//Part associations
$builder->add('associated_parts_as_owner', CollectionType::class, [
'entry_type' => PartAssociationType::class,
'allow_add' => true,
'allow_delete' => true,
'reindex_enable' => true,
'label' => false,
'by_reference' => false,
]);
$builder->add('log_comment', TextType::class, [
'label' => 'edit.log_comment',
'mapped' => false,