src/Core/Entity/Categoria.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Core\Entity;
  3. use App\Core\Entity\CategoriaUsuario;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Symfony\Component\HttpFoundation\File\UploadedFile;
  9. /**
  10. * @ORM\Entity(repositoryClass="App\Core\Repository\CategoriaRepository")
  11. */
  12. class Categoria
  13. {
  14. CONST JSON_FIELDS = ['id', 'nombre', 'nombreCompletoEs', 'nombreCompletoEn', 'imageName'];
  15. /**
  16. * @ORM\Id()
  17. * @ORM\GeneratedValue()
  18. * @ORM\Column(type="integer")
  19. */
  20. private $id;
  21. /**
  22. * @ORM\Column(type="string", length=30, unique=true)
  23. */
  24. private $nombre;
  25. /**
  26. * @ORM\Column(type="string", length=50, nullable=true)
  27. */
  28. private $nombreCompletoEs;
  29. /**
  30. * @ORM\Column(type="string", length=50, nullable=true)
  31. */
  32. private $nombreCompletoEn;
  33. /**
  34. * @ORM\Column(type="string", length=200, nullable=false)
  35. *
  36. * @var string|null
  37. */
  38. private $imageName;
  39. /**
  40. * @ORM\OneToMany(targetEntity="App\Core\Entity\CategoriaCurso", mappedBy="categoria")
  41. */
  42. private $cursosCategoria;
  43. /**
  44. * @ORM\OneToMany(targetEntity="App\Core\Entity\CategoriaUsuario", mappedBy="categoria", orphanRemoval=true)
  45. */
  46. private $categoriaUsuarios;
  47. public function __construct()
  48. {
  49. $this->cursosCategoria = new ArrayCollection();
  50. $this->categoriaUsuarios = new ArrayCollection();
  51. }
  52. public function getId(): ?int
  53. {
  54. return $this->id;
  55. }
  56. public function getNombre(): ?string
  57. {
  58. return $this->nombre;
  59. }
  60. public function setNombre(string $nombre): self
  61. {
  62. $this->nombre = $nombre;
  63. return $this;
  64. }
  65. /**
  66. * @return Collection|CategoriaCurso[]
  67. */
  68. public function getCursosCategoria(): Collection
  69. {
  70. return $this->cursosCategoria;
  71. }
  72. public function addCategoriaCurso(CategoriaCurso $categoriaCurso): self
  73. {
  74. if (!$this->cursosCategoria->contains($categoriaCurso)) {
  75. $this->cursosCategoria[] = $categoriaCurso;
  76. $categoriaCurso->setCategoria($this);
  77. }
  78. return $this;
  79. }
  80. public function removeCategoriaCurso(CategoriaCurso $categoriaCurso): self
  81. {
  82. if ($this->cursosCategoria->contains($categoriaCurso)) {
  83. $this->cursosCategoria->removeElement($categoriaCurso);
  84. // set the owning side to null (unless already changed)
  85. if ($categoriaCurso->getCategoria() === $this) {
  86. $categoriaCurso->setCategoria(null);
  87. }
  88. }
  89. return $this;
  90. }
  91. /**
  92. * @return Collection|CategoriaUsuario[]
  93. */
  94. public function getCategoriaUsuarios(): Collection
  95. {
  96. return $this->categoriaUsuarios;
  97. }
  98. public function addCategoriaUsuario(CategoriaUsuario $categoriaUsuario): self
  99. {
  100. if (!$this->categoriaUsuarios->contains($categoriaUsuario)) {
  101. $this->categoriaUsuarios[] = $categoriaUsuario;
  102. $categoriaUsuario->setCategoria($this);
  103. }
  104. return $this;
  105. }
  106. public function removeCategoriaUsuario(CategoriaUsuario $categoriaUsuario): self
  107. {
  108. if ($this->categoriaUsuarios->contains($categoriaUsuario)) {
  109. $this->categoriaUsuarios->removeElement($categoriaUsuario);
  110. // set the owning side to null (unless already changed)
  111. if ($categoriaUsuario->getCategoria() === $this) {
  112. $categoriaUsuario->setCategoria(null);
  113. }
  114. }
  115. return $this;
  116. }
  117. public function setImageName(?string $imageName): void
  118. {
  119. $this->imageName = $imageName;
  120. }
  121. public function getImageName(): ?string
  122. {
  123. return $this->imageName;
  124. }
  125. public function getNombreCompleto(): ?string
  126. {
  127. if($GLOBALS['request']->getLocale() === 'es')
  128. return $this->nombreCompletoEs;
  129. elseif ($GLOBALS['request']->getLocale() === 'en')
  130. return $this->nombreCompletoEn;
  131. else
  132. return $this->nombreCompletoEn;
  133. }
  134. public function getNombreCompletoEs(): ?string
  135. {
  136. return $this->nombreCompletoEs;
  137. }
  138. public function setNombreCompletoEs(string $nombreCompletoEs): self
  139. {
  140. $this->nombreCompletoEs = $nombreCompletoEs;
  141. return $this;
  142. }
  143. public function getNombreCompletoEn(): ?string
  144. {
  145. return $this->nombreCompletoEn;
  146. }
  147. public function setNombreCompletoEn(string $nombreCompletoEn): self
  148. {
  149. $this->nombreCompletoEn = $nombreCompletoEn;
  150. return $this;
  151. }
  152. }