ogcore/src/Dto/Output/ImageOutput.php

67 lines
1.9 KiB
PHP

<?php
namespace App\Dto\Output;
use ApiPlatform\Metadata\Get;
use App\Entity\Image;
use App\Entity\ImageImageRepository;
use App\Entity\ImageRepository;
use App\Entity\Software;
use Symfony\Component\Serializer\Annotation\Groups;
#[Get(shortName: 'Image')]
final class ImageOutput extends AbstractOutput
{
#[Groups(['image:read', 'image-image-repository:read'])]
public ?string $name = '';
#[Groups(['image:read'])]
public ?string $description = '';
#[Groups(['image:read'])]
public ?string $comments = '';
#[Groups(['image:read'])]
public ?bool $remotePc = null;
#[Groups(['image:read'])]
public ?bool $isGlobal = null;
#[Groups(['image:read'])]
public ?SoftwareProfileOutput $softwareProfile = null;
/**
* @var ImageRepositoryOutput[]|null
*/
#[Groups(['image:read'])]
public ?array $imageRepositories = [];
#[Groups(['image:read'])]
public ?array $partitionInfo = null;
#[Groups(['image:read'])]
public \DateTime $createdAt;
#[Groups(['image:read'])]
public ?string $createdBy = null;
public function __construct(Image $image)
{
parent::__construct($image);
$this->name = $image->getName();
$this->description = $image->getDescription();
$this->comments = $image->getComments();
$this->softwareProfile = $image->getSoftwareProfile() ? new SoftwareProfileOutput($image->getSoftwareProfile()) : null;
$this->imageRepositories = $image->getImageImageRepositories()->map(
fn(ImageImageRepository $image) => new ImageImageRepositoryOutput($image)
)->toArray();
$this->partitionInfo = json_decode($image->getPartitionInfo(), true);
$this->remotePc = $image->isRemotePc();
$this->isGlobal = $image->isGlobal();
$this->createdAt = $image->getCreatedAt();
$this->createdBy = $image->getCreatedBy();
}
}