You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
3.5 KiB
PHP
135 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\Repository\MaterialRepository;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
/**
|
|
* A material
|
|
*/
|
|
#[ORM\Entity(repositoryClass: MaterialRepository::class)]
|
|
#[UniqueEntity(fields: ['name'], message: 'Il existe déjà un matériau avec ce nom')]
|
|
class Material {
|
|
use TBaseEntity;
|
|
use TNamedEntity;
|
|
|
|
/**
|
|
* @var MaterialType|null The type
|
|
*/
|
|
#[ORM\ManyToOne]
|
|
#[ORM\JoinColumn(nullable: false)]
|
|
#[Assert\NotNull(message: 'Veuillez sélectionner un type de matériau')]
|
|
#[Assert\Valid]
|
|
private ?MaterialType $type = null;
|
|
|
|
/**
|
|
* @var bool|null Is the material craftable by default?
|
|
*/
|
|
#[ORM\Column]
|
|
#[Assert\Type(type: 'bool', message: 'L\'indicateur de si le matériau est craftable par défaut doit être un booléen')]
|
|
#[Assert\NotNull(message: 'Veuillez indiquer si le matériau est craftable par défaut')]
|
|
private ?bool $isCraftableByDefault = null;
|
|
|
|
/**
|
|
* @var Collection<int, OutputRecipeMaterial> The recipes
|
|
*/
|
|
#[ORM\OneToMany(targetEntity: OutputRecipeMaterial::class, mappedBy: 'material', orphanRemoval: true)]
|
|
#[Assert\Valid]
|
|
private Collection $recipes;
|
|
|
|
/**
|
|
* Initialization
|
|
*/
|
|
public function __construct () {
|
|
$this->recipes = new ArrayCollection();
|
|
}
|
|
|
|
/**
|
|
* The type
|
|
*
|
|
* @return MaterialType|null The type
|
|
*/
|
|
public function getType (): ?MaterialType {
|
|
return $this->type;
|
|
}
|
|
/**
|
|
* Set the type
|
|
*
|
|
* @param MaterialType|null $type The type
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function setType (?MaterialType $type): static {
|
|
$this->type = $type;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Is the material craftable by default?
|
|
*
|
|
* @return bool|null Is the material craftable by default?
|
|
*/
|
|
public function isCraftableByDefault (): ?bool {
|
|
return $this->isCraftableByDefault;
|
|
}
|
|
/**
|
|
* Set if the material craftable by default
|
|
*
|
|
* @param bool $isCraftableByDefault Is the material craftable by default?
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function setIsCraftableByDefault (bool $isCraftableByDefault): static {
|
|
$this->isCraftableByDefault = $isCraftableByDefault;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* The recipes
|
|
*
|
|
* @return Collection<int, OutputRecipeMaterial> The recipes
|
|
*/
|
|
public function getRecipes (): Collection {
|
|
return $this->recipes;
|
|
}
|
|
/**
|
|
* Add a recipe
|
|
*
|
|
* @param OutputRecipeMaterial $recipe The recipe
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function addRecipe (OutputRecipeMaterial $recipe): static {
|
|
if (!$this->recipes->contains($recipe)) {
|
|
$this->recipes->add($recipe);
|
|
$recipe->setMaterial($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
/**
|
|
* Remove a recipe
|
|
*
|
|
* @param OutputRecipeMaterial $recipe The recipe
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function removeRecipe (OutputRecipeMaterial $recipe): static {
|
|
if ($this->recipes->removeElement($recipe)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($recipe->getMaterial() === $this) {
|
|
$recipe->setMaterial(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
}
|