src/Core/Entity/Maestro.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Core\Entity;
  3. use App\Core\Entity\PuntuacionMaestro;
  4. use App\Core\Entity\Subscripciones\PagoSubscripcion;
  5. use App\Core\Entity\Subscripciones\HistorialPagoSubscripcion;
  6. use App\Entity\CampusMaestro;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. /**
  11. * @ORM\Entity(repositoryClass="App\Core\Repository\MaestroRepository")
  12. */
  13. class Maestro
  14. {
  15. const JSON_FIELDS = [
  16. 'id', 'user' => ['id'], 'maestroCursos' => ['id'], 'descripcionProfesional', 'profesion', 'sitioWeb', 'alias', 'puntuacionPromedio'
  17. ];
  18. /**
  19. * @ORM\Id()
  20. * @ORM\GeneratedValue()
  21. * @ORM\Column(type="integer")
  22. */
  23. private $id;
  24. /**
  25. * @ORM\OneToOne(targetEntity="App\Core\Entity\User", inversedBy="maestro", cascade={"persist", "remove"})
  26. * @ORM\JoinColumn(nullable=false)
  27. */
  28. private $user;
  29. /**
  30. * @ORM\OneToMany(targetEntity="App\Core\Entity\MaestroCurso", mappedBy="maestro")
  31. */
  32. private $maestroCursos;
  33. /**
  34. * @ORM\Column(type="text", nullable=true)
  35. */
  36. private $descripcionProfesional;
  37. /**
  38. * @ORM\Column(type="string", length=100, nullable=true)
  39. */
  40. private $profesion;
  41. /**
  42. * @ORM\Column(type="string", length=255, nullable=true)
  43. */
  44. private $sitioWeb;
  45. /**
  46. * @ORM\Column(type="string", length=50, nullable=true)
  47. */
  48. private $alias;
  49. /**
  50. * @ORM\OneToMany(targetEntity=PuntuacionMaestro::class, mappedBy="maestro", orphanRemoval=true)
  51. */
  52. private $puntuacionesMaestro;
  53. /**
  54. * @ORM\OneToMany(targetEntity=PagoSubscripcion::class, mappedBy="maestro")
  55. */
  56. private $pagosSubscripcion;
  57. /**
  58. * @ORM\OneToMany(targetEntity=HistorialPagoSubscripcion::class, mappedBy="maestro")
  59. */
  60. private $historialPagosSubscripcion;
  61. /**
  62. * @ORM\Column(type="float", nullable=true)
  63. */
  64. private $puntuacionPromedio;
  65. /**
  66. * @ORM\OneToMany(targetEntity=CampusMaestro::class, mappedBy="maestro")
  67. */
  68. private $campusMaestros;
  69. public function __construct()
  70. {
  71. $this->maestroCursos = new ArrayCollection();
  72. $this->puntuacionesMaestro = new ArrayCollection();
  73. $this->pagosSubscripcion = new ArrayCollection();
  74. $this->historialPagosSubscripcion = new ArrayCollection();
  75. $this->campusMaestros = new ArrayCollection();
  76. }
  77. public function getId(): ?int
  78. {
  79. return $this->id;
  80. }
  81. public function getUser(): ?User
  82. {
  83. return $this->user;
  84. }
  85. public function setUser(User $user): self
  86. {
  87. $this->user = $user;
  88. return $this;
  89. }
  90. /**
  91. * @return Collection|MaestroCurso[]
  92. */
  93. public function getMaestroCursos(): Collection
  94. {
  95. return $this->maestroCursos;
  96. }
  97. public function addMaestroCurso(MaestroCurso $maestroCurso): self
  98. {
  99. if (!$this->maestroCursos->contains($maestroCurso)) {
  100. $this->maestroCursos[] = $maestroCurso;
  101. $maestroCurso->setMaestro($this);
  102. }
  103. return $this;
  104. }
  105. public function removeMaestroCurso(MaestroCurso $maestroCurso): self
  106. {
  107. if ($this->maestroCursos->contains($maestroCurso)) {
  108. $this->maestroCursos->removeElement($maestroCurso);
  109. // set the owning side to null (unless already changed)
  110. if ($maestroCurso->getMaestro() === $this) {
  111. $maestroCurso->setMaestro(null);
  112. }
  113. }
  114. return $this;
  115. }
  116. public function getCantidadCursosActivos() {
  117. $relaciones = $this->getMaestroCursos();
  118. $cantidad = 0;
  119. for ($i = 0; $i < count($relaciones); $i++) {
  120. $curso = $relaciones[$i]->getCurso();
  121. if($curso->getEstado()) {
  122. $cantidad++;
  123. }
  124. }
  125. return $cantidad;
  126. }
  127. public function getCantidadCursosArchivados() {
  128. return count($this->getMaestroCursos()) - $this->getCantidadCursosActivos();
  129. }
  130. public function getCantidadCursosActivosPrivados() {
  131. $relaciones = $this->getMaestroCursos();
  132. $cantidad = 0;
  133. for ($i = 0; $i < count($relaciones); $i++) {
  134. $curso = $relaciones[$i]->getCurso();
  135. if($curso->getEstado() === 1 && $curso->getPrivado()) {
  136. $cantidad++;
  137. }
  138. }
  139. return $cantidad;
  140. }
  141. public function getCantidadCursosActivosAbiertos() {
  142. $relaciones = $this->getMaestroCursos();
  143. $cantidad = 0;
  144. for ($i = 0; $i < count($relaciones); $i++) {
  145. $curso = $relaciones[$i]->getCurso();
  146. if($curso->getEstado() === 1 && !$curso->getPrivado()) {
  147. $cantidad++;
  148. }
  149. }
  150. return $cantidad;
  151. }
  152. public function getDescripcionProfesional(): ?string
  153. {
  154. return $this->descripcionProfesional;
  155. }
  156. public function setDescripcionProfesional(string $descripcionProfesional): self
  157. {
  158. if (trim($descripcionProfesional) === '') $descripcionProfesional = null;
  159. $this->descripcionProfesional = $descripcionProfesional;
  160. return $this;
  161. }
  162. public function getProfesion(): ?string
  163. {
  164. return $this->profesion;
  165. }
  166. public function setProfesion(?string $profesion): self
  167. {
  168. if (trim($profesion) === '') $profesion = null;
  169. $this->profesion = $profesion;
  170. return $this;
  171. }
  172. public function getSitioWeb(): ?string
  173. {
  174. return $this->sitioWeb;
  175. }
  176. public function setSitioWeb(string $sitioWeb): self
  177. {
  178. if (trim($sitioWeb) === '') $sitioWeb = null;
  179. $this->sitioWeb = $sitioWeb;
  180. return $this;
  181. }
  182. public function getAlias(): ?string
  183. {
  184. return $this->alias;
  185. }
  186. public function setAlias(string $alias): self
  187. {
  188. $this->alias = $alias;
  189. return $this;
  190. }
  191. /**
  192. * @return Collection|PuntuacionMaestro[]
  193. */
  194. public function getPuntuacionesMaestro(): Collection
  195. {
  196. return $this->puntuacionesMaestro;
  197. }
  198. public function addPuntuacionesMaestro(PuntuacionMaestro $puntuacionesMaestro): self
  199. {
  200. if (!$this->puntuacionesMaestro->contains($puntuacionesMaestro)) {
  201. $this->puntuacionesMaestro[] = $puntuacionesMaestro;
  202. $puntuacionesMaestro->setMaestro($this);
  203. }
  204. return $this;
  205. }
  206. public function removePuntuacionesMaestro(PuntuacionMaestro $puntuacionesMaestro): self
  207. {
  208. if ($this->puntuacionesMaestro->removeElement($puntuacionesMaestro)) {
  209. // set the owning side to null (unless already changed)
  210. if ($puntuacionesMaestro->getMaestro() === $this) {
  211. $puntuacionesMaestro->setMaestro(null);
  212. }
  213. }
  214. return $this;
  215. }
  216. /**
  217. * @return Collection|PagoSubscripcion[]
  218. */
  219. public function getPagosSubscripcion(): Collection
  220. {
  221. return $this->pagosSubscripcion;
  222. }
  223. public function addPagosSubscripcion(PagoSubscripcion $pagosSubscripcion): self
  224. {
  225. if (!$this->pagosSubscripcion->contains($pagosSubscripcion)) {
  226. $this->pagosSubscripcion[] = $pagosSubscripcion;
  227. $pagosSubscripcion->setMaestro($this);
  228. }
  229. return $this;
  230. }
  231. public function removePagosSubscripcion(PagoSubscripcion $pagosSubscripcion): self
  232. {
  233. if ($this->pagosSubscripcion->removeElement($pagosSubscripcion)) {
  234. // set the owning side to null (unless already changed)
  235. if ($pagosSubscripcion->getMaestro() === $this) {
  236. $pagosSubscripcion->setMaestro(null);
  237. }
  238. }
  239. return $this;
  240. }
  241. /**
  242. * @return Collection|HistorialPagoSubscripcion[]
  243. */
  244. public function getHistorialPagosSubscripcion(): Collection
  245. {
  246. return $this->historialPagosSubscripcion;
  247. }
  248. /**
  249. * @return ?float
  250. */
  251. public function getPuntuacionPromedio(): ?float
  252. {
  253. return $this->puntuacionPromedio;
  254. }
  255. /**
  256. * @param float $puntuacionPromedio
  257. */
  258. public function setPuntuacionPromedio(float $puntuacionPromedio): void
  259. {
  260. $this->puntuacionPromedio = $puntuacionPromedio;
  261. }
  262. /**
  263. * @return Collection<int, CampusMaestro>
  264. */
  265. public function getCampusMaestros(): Collection
  266. {
  267. return $this->campusMaestros;
  268. }
  269. public function addCampusMaestro(CampusMaestro $campusMaestro): self
  270. {
  271. if (!$this->campusMaestros->contains($campusMaestro)) {
  272. $this->campusMaestros[] = $campusMaestro;
  273. $campusMaestro->setMaestro($this);
  274. }
  275. return $this;
  276. }
  277. public function removeCampusMaestro(CampusMaestro $campusMaestro): self
  278. {
  279. if ($this->campusMaestros->removeElement($campusMaestro)) {
  280. // set the owning side to null (unless already changed)
  281. if ($campusMaestro->getMaestro() === $this) {
  282. $campusMaestro->setMaestro(null);
  283. }
  284. }
  285. return $this;
  286. }
  287. }