Allow to define manufacturing status for a part.

This commit is contained in:
Jan Böhmer 2019-09-02 18:41:57 +02:00
parent b14edfc3bd
commit d22f9da1f0
5 changed files with 84 additions and 4 deletions

View file

@ -246,8 +246,9 @@ class Part extends AttachmentContainingDBElement
/**
* @var string
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Choice({"announced", "active", "nrfnd", "eol", "discontinued", ""})
*/
protected $manufacturing_status;
protected $manufacturing_status = "";
/**
* @var bool Determines if this part entry needs review (for example, because it is work in progress)
@ -442,6 +443,37 @@ class Part extends AttachmentContainingDBElement
return $this->manufacturer_product_url;
}
/**
* Returns the manufacturing/production status for this part.
* The status can be one of the following:
* (Similar to https://designspark.zendesk.com/hc/en-us/articles/213584805-What-are-the-Lifecycle-Status-definitions-)
* * "": Status unknown
* * "announced": Part has been announced, but is not in production yet
* * "active": Part is in production and will be for the forseeable future
* * "nrfnd": Not recommended for new designs.
* * "eol": Part will become discontinued soon
* * "discontinued": Part is obsolete/discontinued by the manufacturer
* @return string
*/
public function getManufacturingStatus(): ?string
{
return $this->manufacturing_status;
}
/**
* Sets the manufacturing status for this part
* See getManufacturingStatus() for valid values.
* @param string $manufacturing_status
* @return Part
*/
public function setManufacturingStatus(string $manufacturing_status): Part
{
$this->manufacturing_status = $manufacturing_status;
return $this;
}
/**
* Get the category of this part.
*

View file

@ -48,6 +48,7 @@ use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
@ -58,14 +59,17 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
class PartBaseType extends AbstractType
{
protected $security;
protected $trans;
public function __construct(Security $security)
public function __construct(Security $security, TranslatorInterface $trans)
{
$this->security = $security;
$this->trans = $trans;
}
public function buildForm(FormBuilderInterface $builder, array $options)
@ -73,6 +77,15 @@ class PartBaseType extends AbstractType
/** @var Part $part */
$part = $builder->getData();
$status_choices = [
$this->trans->trans("m_status.unknown") => '',
$this->trans->trans('m_stauts.announced') => 'announced',
$this->trans->trans('m_status.active') => 'active',
$this->trans->trans('m_status.nrfnd') => 'nrfnd',
$this->trans->trans('m_status.eol') => 'eol',
$this->trans->trans('m_status.discontinued') => 'discontinued'
];
//Common section
$builder
->add('name', TextType::class, ['empty_data' => '', 'label' => 'name.label',
@ -105,7 +118,13 @@ class PartBaseType extends AbstractType
'disabled' => !$this->security->isGranted('manufacturer.edit', $part), ])
->add('manufacturer_product_number', TextType::class, ['required' => false,
'empty_data' => '', 'label' => 'part.mpn',
'disabled' => !$this->security->isGranted('manufacturer.edit', $part)]);
'disabled' => !$this->security->isGranted('manufacturer.edit', $part)])
->add('manufacturing_status', ChoiceType::class, [
'label' => 'part.manufacturing_status',
'choices' => $status_choices,
'required' => false,
'disabled' => !$this->security->isGranted('manufacturer.edit', $part)
]);
//Advanced section
$builder->add('needsReview', CheckboxType::class, ['label_attr'=> ['class' => 'checkbox-custom'],