src/Entity/Media.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\MediaRepository;
  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 Vich\UploaderBundle\Mapping\Annotation as Vich;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Component\Serializer\Annotation\Ignore;
  11. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  12. /**
  13. * @ORM\Entity(repositoryClass=MediaRepository::class)
  14. * @Vich\Uploadable
  15. */
  16. class Media
  17. {
  18. const TYPE_CANDIDATURE = "candidature";
  19. const TYPE_POST_CANDIDATURE = "postCandidature";
  20. const TYPE_CUSTOMER = "parent";
  21. const TYPE_EMPLOYE = "employé";
  22. const ENTITY_TRANSLATION = [
  23. 'sejour' => 'App\Entity\Sejour',
  24. 'sejour_session' => 'App\Entity\SejourSession',
  25. 'inscription' => 'App\Entity\Inscription',
  26. 'enfant' => 'enfant'
  27. ];
  28. /**
  29. * @ORM\Id
  30. * @ORM\GeneratedValue
  31. * @ORM\Column(type="integer")
  32. */
  33. private $id;
  34. /**
  35. * @ORM\Column(type="string", length=255, nullable=true)
  36. */
  37. private $name;
  38. /**
  39. * @ORM\Column(type="string", length=512, nullable=true)
  40. */
  41. private $description;
  42. /**
  43. * @ORM\Column(type="string", length=512, nullable=true)
  44. */
  45. private $filePath;
  46. /**
  47. * @ORM\OneToMany(targetEntity=Media::class, mappedBy="mediaParent")
  48. */
  49. private $mediaChildren;
  50. /**
  51. * @Vich\UploadableField(mapping="frontend_image", fileNameProperty="filePath")
  52. * @var File|null
  53. *
  54. */
  55. private $imgFile;
  56. /**
  57. * @Ignore()
  58. * @Vich\UploadableField(mapping="private_file", fileNameProperty="filePath") *
  59. * @var File|null
  60. *
  61. */
  62. private $privateFile;
  63. /**
  64. * @ORM\Column(type="json", nullable=true)
  65. */
  66. private $attributes = [];
  67. /**
  68. * @ORM\Column(type="string", length=511 , nullable=true)
  69. */
  70. private $altAttribute;
  71. /**
  72. * @ORM\Column(type="boolean")
  73. */
  74. private $isStandalone;
  75. /**
  76. * @ORM\Column(type="boolean",options={"default": false})
  77. */
  78. private $isMigrated;
  79. /**
  80. * @ORM\OneToMany(targetEntity=SejourSessionMediaCategorie::class, mappedBy="media",cascade={"persist"})
  81. */
  82. private $sejourSessionMediaCategories;
  83. /**
  84. * @ORM\ManyToOne(targetEntity=MediaCategorie::class, inversedBy="media", fetch="EAGER")
  85. * @ORM\JoinColumn(nullable=false)
  86. */
  87. private $mediaCategorie;
  88. /**
  89. * @ORM\ManyToOne(targetEntity=Media::class, inversedBy="mediaParent", fetch="EAGER")
  90. * @ORM\JoinColumn(nullable=true)
  91. */
  92. private $mediaParent;
  93. /**
  94. * @ORM\Column(type="integer", nullable=true)
  95. */
  96. private $position;
  97. /**
  98. * @ORM\OneToMany(targetEntity=ContactMediaCategorie::class, mappedBy="media")
  99. */
  100. private $contactMediaCategories;
  101. /**
  102. * @ORM\OneToMany(targetEntity=ArticleMediaCategorie::class, mappedBy="media")
  103. */
  104. private $articleMediaCategories;
  105. /**
  106. * @ORM\ManyToOne(targetEntity=Sejour::class, inversedBy="medias",cascade={"persist"})
  107. */
  108. private $sejour;
  109. /**
  110. * @ORM\ManyToOne(targetEntity=Candidature::class, inversedBy="medias")
  111. */
  112. private $candidature;
  113. /**
  114. * @ORM\ManyToOne(targetEntity=Contact::class, inversedBy="medias")
  115. */
  116. private $contact;
  117. /**
  118. * @ORM\ManyToOne(targetEntity=SejourSession::class, inversedBy="medias",cascade={"persist"})
  119. */
  120. private $sejourSession;
  121. /**
  122. * @ORM\ManyToOne(targetEntity=Inscription::class, inversedBy="medias")
  123. */
  124. private $inscription;
  125. /**
  126. * @ORM\Column(type="datetime", nullable=true)
  127. */
  128. private $updatedDate;
  129. /**
  130. * @ORM\ManyToMany(targetEntity=EmailInfo::class, mappedBy="attachments")
  131. */
  132. private $emailInfos;
  133. /**
  134. * @ORM\Column(type="integer", nullable=true)
  135. */
  136. private $legacyId;
  137. /**
  138. * @ORM\ManyToOne(targetEntity=Saison::class, inversedBy="medias")
  139. */
  140. private $saison;
  141. /**
  142. * @ORM\Column(type="boolean", nullable=true)
  143. */
  144. private $isValidated;
  145. /**
  146. * @ORM\Column(type="string", length=255, nullable=true)
  147. */
  148. private $rejectedReason;
  149. public function __construct()
  150. {
  151. $this->sejourSessionMediaCategories = new ArrayCollection();
  152. $this->isStandalone = true;
  153. $this->isMigrated = false;
  154. $this->updatedDate = new \Datetime();
  155. $this->contactMediaCategories = new ArrayCollection();
  156. $this->articleMediaCategories = new ArrayCollection();
  157. $this->emailInfos = new ArrayCollection();
  158. $this->mediaChildren = new ArrayCollection();
  159. }
  160. /**
  161. * @return Collection|self[]
  162. */
  163. public function getMediaChildren(): Collection
  164. {
  165. return $this->mediaChildren;
  166. }
  167. public function addMediaChild(self $child): self
  168. {
  169. if (!$this->mediaChildren->contains($child)) {
  170. $this->mediaChildren[] = $child;
  171. $child->setMediaParent($this);
  172. }
  173. return $this;
  174. }
  175. public function removeMediaChild(self $child): self
  176. {
  177. if ($this->mediaChildren->removeElement($child)) {
  178. // set the owning side to null (unless already changed)
  179. if ($child->getMediaParent() === $this) {
  180. $child->setMediaParent(null);
  181. }
  182. }
  183. return $this;
  184. }
  185. public function getId(): ?int
  186. {
  187. return $this->id;
  188. }
  189. public function getName(): ?string
  190. {
  191. return $this->name;
  192. }
  193. public function setName(?string $name): self
  194. {
  195. $this->name = $name;
  196. return $this;
  197. }
  198. public function getRejectedReason(): ?string
  199. {
  200. return $this->rejectedReason;
  201. }
  202. public function setRejectedReason(?string $rejectedReason): self
  203. {
  204. $this->rejectedReason = $rejectedReason;
  205. return $this;
  206. }
  207. public function getDescription(): ?string
  208. {
  209. return $this->description;
  210. }
  211. public function setDescription(string $description): self
  212. {
  213. $this->description = $description;
  214. return $this;
  215. }
  216. public function getFilePath(): ?string
  217. {
  218. return $this->filePath;
  219. }
  220. public function setFilePath(?string $filePath): self
  221. {
  222. $this->filePath = $filePath;
  223. return $this;
  224. }
  225. public function getAttributes(): ?array
  226. {
  227. return $this->attributes;
  228. }
  229. public function setAttributes(?array $attributes): self
  230. {
  231. $this->attributes = $attributes;
  232. return $this;
  233. }
  234. public function getAltAttribute(): ?string
  235. {
  236. return $this->altAttribute;
  237. }
  238. public function setAltAttribute(string $altAttribute): self
  239. {
  240. $this->altAttribute = $altAttribute;
  241. return $this;
  242. }
  243. public function getIsStandalone(): ?bool
  244. {
  245. return $this->isStandalone;
  246. }
  247. public function setIsStandalone(bool $isStandalone): self
  248. {
  249. $this->isStandalone = $isStandalone;
  250. return $this;
  251. }
  252. public function getIsMigrated(): ?bool
  253. {
  254. return $this->isMigrated;
  255. }
  256. public function setIsMigrated(bool $isMigrated): self
  257. {
  258. $this->isMigrated = $isMigrated;
  259. return $this;
  260. }
  261. /**
  262. * @return Collection|SejourSessionMediaCategorie[]
  263. */
  264. public function getSejourSessionMediaCategories(): Collection
  265. {
  266. return $this->sejourSessionMediaCategories;
  267. }
  268. public function addSejourSessionMediaCategorie(SejourSessionMediaCategorie $sejourSessionMediaCategorie): self
  269. {
  270. if (!$this->sejourSessionMediaCategories->contains($sejourSessionMediaCategorie)) {
  271. $this->sejourSessionMediaCategories[] = $sejourSessionMediaCategorie;
  272. $sejourSessionMediaCategorie->setMedia($this);
  273. }
  274. return $this;
  275. }
  276. public function removeSejourSessionMediaCategorie(SejourSessionMediaCategorie $sejourSessionMediaCategorie): self
  277. {
  278. if ($this->sejourSessionMediaCategories->removeElement($sejourSessionMediaCategorie)) {
  279. // set the owning side to null (unless already changed)
  280. if ($sejourSessionMediaCategorie->getMedia() === $this) {
  281. $sejourSessionMediaCategorie->setMedia(null);
  282. }
  283. }
  284. return $this;
  285. }
  286. public function getMediaCategorie(): ?MediaCategorie
  287. {
  288. return $this->mediaCategorie;
  289. }
  290. public function setMediaCategorie(?MediaCategorie $MediaCategorie): self
  291. {
  292. $this->mediaCategorie = $MediaCategorie;
  293. return $this;
  294. }
  295. public function getMediaParent(): ?Media
  296. {
  297. return $this->mediaParent;
  298. }
  299. public function setMediaParent(?Media $mediaParent): self
  300. {
  301. $this->mediaParent = $mediaParent;
  302. return $this;
  303. }
  304. public function getPosition(): ?int
  305. {
  306. return $this->position;
  307. }
  308. public function setPosition(?int $position): self
  309. {
  310. $this->position = $position;
  311. return $this;
  312. }
  313. public function setImgFile(?File $imageFile = null)
  314. {
  315. $this->imgFile = $imageFile;
  316. if ($imageFile) {
  317. // if 'updatedAt' is not defined in your entity, use another property
  318. $this->legacyId = 1;
  319. if (file_exists($imageFile->getPathname()))
  320. return(in_array($imageFile->guessExtension(),$this->mediaCategorie->getAllowedFormat()));
  321. }
  322. return true;
  323. }
  324. public function getImgFile(): ?File
  325. {
  326. return $this->imgFile;
  327. }
  328. public function setPrivateFile(?File $imageFile = null)
  329. {
  330. $this->privateFile = $imageFile;
  331. if ($imageFile) {
  332. // if 'updatedAt' is not defined in your entity, use another property
  333. $this->updatedDate = new \DateTime('now');
  334. if (file_exists($imageFile->getPathname()))
  335. return(in_array($imageFile->guessExtension(),$this->mediaCategorie->getAllowedFormat()));
  336. }
  337. return true;
  338. }
  339. public function isFileOk()
  340. {
  341. if($this->imgFile == null) return true;
  342. return(in_array($this->imgFile->getExtension(),$this->mediaCategorie->getAllowedFormat()));
  343. }
  344. public function getPrivateFile(): ?File
  345. {
  346. return $this->privateFile;
  347. }
  348. /**
  349. * @return Collection|ContactMediaCategorie[]
  350. */
  351. public function getContactMediaCategories(): Collection
  352. {
  353. return $this->contactMediaCategories;
  354. }
  355. public function addContactMediaCategory(ContactMediaCategorie $contactMediaCategory): self
  356. {
  357. if (!$this->contactMediaCategories->contains($contactMediaCategory)) {
  358. $this->contactMediaCategories[] = $contactMediaCategory;
  359. $contactMediaCategory->setMedia($this);
  360. }
  361. return $this;
  362. }
  363. public function removeContactMediaCategory(ContactMediaCategorie $contactMediaCategory): self
  364. {
  365. if ($this->contactMediaCategories->removeElement($contactMediaCategory)) {
  366. // set the owning side to null (unless already changed)
  367. if ($contactMediaCategory->getMedia() === $this) {
  368. $contactMediaCategory->setMedia(null);
  369. }
  370. }
  371. return $this;
  372. }
  373. /**
  374. * @return Collection|ArticleMediaCategorie[]
  375. */
  376. public function getArticleMediaCategories(): Collection
  377. {
  378. return $this->articleMediaCategories;
  379. }
  380. public function addArticleMediaCategory(ArticleMediaCategorie $articleMediaCategory): self
  381. {
  382. if (!$this->articleMediaCategories->contains($articleMediaCategory)) {
  383. $this->articleMediaCategories[] = $articleMediaCategory;
  384. $articleMediaCategory->setMedia($this);
  385. }
  386. return $this;
  387. }
  388. public function removeArticleMediaCategory(ArticleMediaCategorie $articleMediaCategory): self
  389. {
  390. if ($this->articleMediaCategories->removeElement($articleMediaCategory)) {
  391. // set the owning side to null (unless already changed)
  392. if ($articleMediaCategory->getMedia() === $this) {
  393. $articleMediaCategory->setMedia(null);
  394. }
  395. }
  396. return $this;
  397. }
  398. public function getSejour(): ?Sejour
  399. {
  400. return $this->sejour;
  401. }
  402. public function setSejour(?Sejour $sejour): self
  403. {
  404. $this->sejour = $sejour;
  405. return $this;
  406. }
  407. public function getCandidature(): ?Candidature
  408. {
  409. return $this->candidature;
  410. }
  411. public function setCandidature(?Candidature $candidature): self
  412. {
  413. $this->candidature = $candidature;
  414. return $this;
  415. }
  416. public function getContact(): ?Contact
  417. {
  418. return $this->contact;
  419. }
  420. public function setContact(?Contact $contact): self
  421. {
  422. $this->contact = $contact;
  423. return $this;
  424. }
  425. public function getSejourSession(): ?SejourSession
  426. {
  427. return $this->sejourSession;
  428. }
  429. public function setSejourSession(?SejourSession $sejourSession): self
  430. {
  431. $this->sejourSession = $sejourSession;
  432. return $this;
  433. }
  434. public function getInscription(): ?Inscription
  435. {
  436. return $this->inscription;
  437. }
  438. public function setInscription(?Inscription $inscription): self
  439. {
  440. $this->inscription = $inscription;
  441. return $this;
  442. }
  443. public function getUpdatedDate(): ?\DateTimeInterface
  444. {
  445. return $this->updatedDate;
  446. }
  447. public function setUpdatedDate(?\DateTimeInterface $updatedDate): self
  448. {
  449. $this->updatedDate = $updatedDate;
  450. return $this;
  451. }
  452. /**
  453. * @return Collection|EmailInfo[]
  454. */
  455. public function getEmailInfos(): Collection
  456. {
  457. return $this->emailInfos;
  458. }
  459. public function addEmailInfo(EmailInfo $emailInfo): self
  460. {
  461. if (!$this->emailInfos->contains($emailInfo)) {
  462. $this->emailInfos[] = $emailInfo;
  463. $emailInfo->addAttachment($this);
  464. }
  465. return $this;
  466. }
  467. public function removeEmailInfo(EmailInfo $emailInfo): self
  468. {
  469. if ($this->emailInfos->removeElement($emailInfo)) {
  470. $emailInfo->removeAttachment($this);
  471. }
  472. return $this;
  473. }
  474. public function getLegacyId(): ?int
  475. {
  476. return $this->legacyId;
  477. }
  478. public function setLegacyId(?int $legacyId): self
  479. {
  480. $this->legacyId = $legacyId;
  481. return $this;
  482. }
  483. public function getSaison(): ?Saison
  484. {
  485. return $this->saison;
  486. }
  487. public function setSaison(?Saison $saison): self
  488. {
  489. $this->saison = $saison;
  490. return $this;
  491. }
  492. public function getIsValidated(): ?bool
  493. {
  494. return $this->isValidated;
  495. }
  496. public function setIsValidated(?bool $isValidated): self
  497. {
  498. $this->isValidated = $isValidated;
  499. return $this;
  500. }
  501. }