mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-03 15:04:32 +02:00
Use enum for manufacturing status
This commit is contained in:
parent
6336b38cfc
commit
9e3cb4d694
7 changed files with 88 additions and 30 deletions
53
src/Entity/Parts/ManufacturingStatus.php
Normal file
53
src/Entity/Parts/ManufacturingStatus.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?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\Entity\Parts;
|
||||
|
||||
enum ManufacturingStatus: string
|
||||
{
|
||||
/** Part has been announced, but is not in production yet */
|
||||
case ANNOUNCED = 'announced';
|
||||
/** Part is in production and will be for the foreseeable future */
|
||||
case ACTIVE = 'active';
|
||||
/** Not recommended for new designs. */
|
||||
case NRFND = 'nrfnd';
|
||||
/** End of life: Part will become discontinued soon */
|
||||
case EOL = 'eol';
|
||||
/** Part is obsolete/discontinued by the manufacturer. */
|
||||
case DISCONTINUED = 'discontinued';
|
||||
|
||||
/** Status not set */
|
||||
case NOT_SET = '';
|
||||
|
||||
public function toTranslationKey(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::ANNOUNCED => 'm_status.announced',
|
||||
self::ACTIVE => 'm_status.active',
|
||||
self::NRFND => 'm_status.nrfnd',
|
||||
self::EOL => 'm_status.eol',
|
||||
self::DISCONTINUED => 'm_status.discontinued',
|
||||
self::NOT_SET => '',
|
||||
};
|
||||
}
|
||||
}
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Parts\PartTraits;
|
||||
|
||||
use App\Entity\Parts\ManufacturingStatus;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use App\Entity\Parts\Manufacturer;
|
||||
use App\Entity\Parts\Part;
|
||||
|
@ -60,12 +61,11 @@ trait ManufacturerTrait
|
|||
protected string $manufacturer_product_number = '';
|
||||
|
||||
/**
|
||||
* @var string|null The production status of this part. Can be one of the specified ones.
|
||||
* @var ManufacturingStatus|null The production status of this part. Can be one of the specified ones.
|
||||
*/
|
||||
#[Assert\Choice(['announced', 'active', 'nrfnd', 'eol', 'discontinued', ''])]
|
||||
#[Groups(['extended', 'full', 'import'])]
|
||||
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
|
||||
protected ?string $manufacturing_status = '';
|
||||
#[ORM\Column(type: Types::STRING, length: 255, nullable: true, enumType: ManufacturingStatus::class)]
|
||||
protected ?ManufacturingStatus $manufacturing_status = ManufacturingStatus::NOT_SET;
|
||||
|
||||
/**
|
||||
* Get the link to the website of the article on the manufacturers website
|
||||
|
@ -113,9 +113,9 @@ trait ManufacturerTrait
|
|||
* * "eol": Part will become discontinued soon
|
||||
* * "discontinued": Part is obsolete/discontinued by the manufacturer.
|
||||
*
|
||||
* @return string
|
||||
* @return ManufacturingStatus|null
|
||||
*/
|
||||
public function getManufacturingStatus(): ?string
|
||||
public function getManufacturingStatus(): ?ManufacturingStatus
|
||||
{
|
||||
return $this->manufacturing_status;
|
||||
}
|
||||
|
@ -124,9 +124,9 @@ trait ManufacturerTrait
|
|||
* Sets the manufacturing status for this part
|
||||
* See getManufacturingStatus() for valid values.
|
||||
*
|
||||
* @return Part
|
||||
* @return $this
|
||||
*/
|
||||
public function setManufacturingStatus(string $manufacturing_status): self
|
||||
public function setManufacturingStatus(ManufacturingStatus $manufacturing_status): self
|
||||
{
|
||||
$this->manufacturing_status = $manufacturing_status;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue