51 lines
1.7 KiB
PHP
51 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Dto\Input;
|
|
|
|
use ApiPlatform\Metadata\ApiProperty;
|
|
use App\Dto\Output\OrganizationalUnitOutput;
|
|
use App\Entity\SoftwareProfile;
|
|
use Symfony\Component\Serializer\Annotation\Groups;
|
|
|
|
final class SoftwareProfileInput
|
|
{
|
|
#[Groups(['software-profile:write'])]
|
|
#[ApiProperty(description: 'The description of the software profile', example: "Software 1 description")]
|
|
public ?string $description = null;
|
|
|
|
#[Groups(['software-profile:write'])]
|
|
#[ApiProperty(description: 'Comments of the software profile', example: "Software 1")]
|
|
public ?string $comments = null;
|
|
|
|
#[Groups(['software-profile:write'])]
|
|
#[ApiProperty(description: 'The organizational unit of the software profile')]
|
|
public ?OrganizationalUnitOutput $organizationalUnit = null;
|
|
|
|
public function __construct(?SoftwareProfile $softwareProfile = null)
|
|
{
|
|
if (!$softwareProfile) {
|
|
return;
|
|
}
|
|
|
|
$this->description = $softwareProfile->getDescription();
|
|
$this->comments = $softwareProfile->getComments();
|
|
if($softwareProfile->getOrganizationalUnit()) {
|
|
$this->organizationalUnit = new OrganizationalUnitOutput($softwareProfile->getOrganizationalUnit());
|
|
}
|
|
}
|
|
|
|
public function createOrUpdateEntity(?SoftwareProfile $softwareProfile = null): SoftwareProfile
|
|
{
|
|
if (!$softwareProfile) {
|
|
$softwareProfile = new SoftwareProfile();
|
|
}
|
|
|
|
$softwareProfile->setDescription($this->description);
|
|
$softwareProfile->setComments($this->comments);
|
|
if ($this->organizationalUnit) {
|
|
$softwareProfile->setOrganizationalUnit($this->organizationalUnit->getEntity());
|
|
}
|
|
|
|
return $softwareProfile;
|
|
}
|
|
} |