ogcore/src/Dto/Output/SoftwareProfileOutput.php

86 lines
2.6 KiB
PHP

<?php
namespace App\Dto\Output;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\Get;
use App\Entity\Software;
use App\Entity\SoftwareProfile;
use Symfony\Component\Serializer\Annotation\Groups;
#[Get(shortName: 'SoftwareProfile')]
final class SoftwareProfileOutput extends AbstractOutput
{
#[Groups(['software-profile:read', 'image:read'])]
#[ApiProperty(
description: 'La descripción del perfil de software',
example: 'Perfil estándar para aula de informática'
)]
public ?string $description = '';
#[Groups(['software-profile:read'])]
#[ApiProperty(
description: 'Comentarios adicionales sobre el perfil',
example: 'Incluye software educativo básico'
)]
public ?string $comments = '';
#[Groups(['software-profile:read'])]
#[ApiProperty(
description: 'La imagen asociada al perfil de software',
example: null
)]
public ?ImageOutput $image = null;
#[Groups(['software-profile:read'])]
#[ApiProperty(
description: 'El sistema operativo base del perfil',
example: null
)]
public ?OperativeSystemOutput $operativeSystem = null;
#[Groups(['software-profile:item:get'])]
#[ApiProperty(
description: 'La colección de software incluido en el perfil',
example: []
)]
public ?array $softwareCollection = [];
#[Groups(['software-profile:read'])]
#[ApiProperty(
description: 'Fecha de creación del perfil de software',
example: '2024-01-15T10:30:00+00:00'
)]
public \DateTime $createdAt;
#[Groups(['software-profile:read'])]
#[ApiProperty(
description: 'Usuario que creó este registro',
example: 'admin'
)]
public ?string $createdBy = null;
public function __construct(SoftwareProfile $softwareProfile, bool $includeImage = true)
{
parent::__construct($softwareProfile);
$this->description = $softwareProfile->getDescription();
$this->comments = $softwareProfile->getComments();
if ($includeImage && $softwareProfile->getImage()) {
$this->image = new ImageOutput($softwareProfile->getImage());
}
if ($softwareProfile->getOperativeSystem()) {
$this->operativeSystem = new OperativeSystemOutput($softwareProfile->getOperativeSystem());
}
$this->softwareCollection = $softwareProfile->getSoftwareCollection()->map(
fn(Software $hardware) => new SoftwareOutput($hardware)
)->toArray();
$this->createdAt = $softwareProfile->getCreatedAt();
$this->createdBy = $softwareProfile->getCreatedBy();
}
}