<?php
// @deprecated
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Trait\TimestampableEntity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
/**
* The most generic type of item.
*
* @see https://schema.org/Thing
*
* @author Jordi Fernandes Alves <jfadev@gmail.com>
*/
#[ORM\Entity]
#[ApiResource(
iri: 'Dashboard',
itemOperations: [
'get' => ['normalization_context' => ['groups' => 'dashboard:item:get', 'enable_max_depth' => true]],
'put' => [
'normalization_context' => ['groups' => 'dashboard:item:put', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'dashboard:item:put', 'enable_max_depth' => true],
],
'delete' => [],
],
collectionOperations: [
'get' => [
'normalization_context' => [
'groups' => ['dashboard:collection:get', 'createdAt'],
'enable_max_depth' => true,
],
],
'post' => [
'normalization_context' => ['groups' => 'dashboard:collection:post', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'dashboard:collection:post', 'enable_max_depth' => true],
],
],
)]
class Dashboard
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'NONE')]
#[ORM\Column(type: 'uuid', unique: true)]
#[ApiProperty(iri: 'https://schema.org/identifier')]
private ?UuidInterface $id = null;
/**
* The user associated with the dashboard.
*
* @var User|null
*
* @see _:user
*/
#[ORM\ManyToOne(targetEntity: 'App\Entity\User')]
#[ApiProperty(iri: 'https://schema.org/Person')]
#[Groups(['dashboard:collection:get', 'dashboard:collection:post', 'dashboard:item:get', 'dashboard:item:put'])]
#[Assert\NotNull]
private ?User $user = null;
/**
* The widgets associated with the dashboard.
*
* @see _:widgets
*/
#[ORM\ManyToMany(targetEntity: 'App\Entity\Widget')]
#[ORM\InverseJoinColumn(nullable: false, unique: true)]
#[ApiProperty(iri: 'https://schema.org/hasPart')]
#[Groups(['dashboard:collection:get', 'dashboard:collection:post', 'dashboard:item:get', 'dashboard:item:put'])]
private ?Collection $widgets = null;
public function __construct()
{
$this->id = Uuid::uuid4();
$this->widgets = new ArrayCollection();
}
public function getId(): ?UuidInterface
{
return $this->id;
}
/**
* @param User|null $user
*/
public function setUser(?User $user): void
{
$this->user = $user;
}
/**
* @return User|null
*/
public function getUser(): ?User
{
return $this->user;
}
public function addWidget(Widget $widget): void
{
$this->widgets[] = $widget;
}
public function removeWidget(Widget $widget): void
{
$this->widgets->removeElement($widget);
}
public function getWidgets(): Collection
{
return $this->widgets;
}
}