src/Entity/Core/AudioReference.php line 12

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Core;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Entity\Core\Quiz\Quiz;
  6. use App\Services\Admin\MediaEntityHelper;
  7. #[ORM\Table('audio_reference')]
  8. #[ORM\Entity]
  9. class AudioReference implements MediaInterface
  10. {
  11. public const UPLOAD_DIRECTORY = 'uploads/audio/';
  12. #[ORM\Column(name: 'id', type: 'integer')]
  13. #[ORM\Id]
  14. #[ORM\GeneratedValue(strategy: 'AUTO')]
  15. private $id;
  16. /**
  17. * @var string
  18. *
  19. * SHA1 hash of the file
  20. */
  21. #[ORM\Column(name: 'content_hash', type: 'string', length: 255, nullable: true)]
  22. private ?string $contentHash;
  23. /**
  24. * @var string
  25. *
  26. * Name for referencing the specific audio within a publication
  27. */
  28. #[ORM\Column(name: 'reference_name', type: 'string', length: 100, nullable: false)]
  29. private string $referenceName;
  30. /**
  31. * @var string
  32. */
  33. #[ORM\Column(name: 'file_path', type: 'string', length: 255, nullable: true)]
  34. private ?string $filePath;
  35. /**
  36. * @var string
  37. */
  38. #[ORM\Column(name: 'credit_text', type: 'string', length: 255, nullable: true)]
  39. private ?string $creditText;
  40. /**
  41. * @var string
  42. */
  43. #[ORM\Column(name: 'position', type: 'string', length: 255, nullable: true)]
  44. private ?string $position;
  45. /**
  46. * @var ?string
  47. */
  48. #[ORM\Column(name: 'alt_text', type: 'string', length: 255, nullable: true)]
  49. private ?string $altText;
  50. #[ORM\JoinColumn(name: 'publication', referencedColumnName: 'id', nullable: true)]
  51. #[ORM\ManyToOne(targetEntity: Publication::class)]
  52. private ?Publication $publication;
  53. #[ORM\OneToOne(targetEntity: Mathproblem::class, mappedBy: 'audioReference')]
  54. private ?Mathproblem $mathproblem;
  55. #[ORM\OneToOne(targetEntity: Quiz::class, mappedBy: 'audioReference')]
  56. private ?Quiz $quiz;
  57. #[ORM\OneToOne(targetEntity: Answer::class, mappedBy: 'audioReference')]
  58. private ?Answer $answer;
  59. #[ORM\OneToOne(targetEntity: ProblemDndBin::class, mappedBy: 'audioReference')]
  60. private ?ProblemDndBin $problemDndBin;
  61. /**
  62. * @var ?bool
  63. */
  64. #[ORM\Column(name: 'is_deleted', type: 'boolean', nullable: true)]
  65. private ?bool $isDeleted = false;
  66. public function __construct()
  67. {
  68. $this->mathproblem = null;
  69. $this->contentHash = null;
  70. $this->filePath = null;
  71. }
  72. public function getId(): ?int
  73. {
  74. return $this->id;
  75. }
  76. public function setId(int $id): void
  77. {
  78. $this->id = $id;
  79. }
  80. public function getContentHash(): ?string
  81. {
  82. return $this->contentHash;
  83. }
  84. public function setContentHash(?string $contentHash): void
  85. {
  86. $this->contentHash = $contentHash;
  87. }
  88. public function getFilePath(): ?string
  89. {
  90. return $this->filePath;
  91. }
  92. public function setFilePath(?string $filePath): void
  93. {
  94. $this->filePath = $filePath;
  95. }
  96. public function getCreditText(): ?string
  97. {
  98. return $this->creditText;
  99. }
  100. public function setCreditText(?string $creditText): void
  101. {
  102. $this->creditText = $creditText;
  103. }
  104. public function getPosition(): ?string
  105. {
  106. return $this->position;
  107. }
  108. public function setPosition(?string $position): void
  109. {
  110. $this->position = $position;
  111. }
  112. public function getAltText(): ?string
  113. {
  114. return $this->altText;
  115. }
  116. public function setAltText(?string $altText): void
  117. {
  118. $this->altText = $altText;
  119. }
  120. public function getPublication(): ?Publication
  121. {
  122. return $this->publication;
  123. }
  124. public function setPublication(?Publication $publication): void
  125. {
  126. $this->publication = $publication;
  127. }
  128. public function getReferenceName(): string
  129. {
  130. return $this->referenceName;
  131. }
  132. public function setReferenceName(string $referenceName): void
  133. {
  134. $this->referenceName = $referenceName;
  135. }
  136. public function getMathproblem(): ?Mathproblem
  137. {
  138. return $this->mathproblem;
  139. }
  140. public function setMathproblem(?Mathproblem $mathproblem): void
  141. {
  142. $this->mathproblem = $mathproblem;
  143. }
  144. public function getQuiz(): ?Quiz
  145. {
  146. return $this->quiz;
  147. }
  148. public function setQuiz(Quiz $quiz): void
  149. {
  150. $this->quiz = $quiz;
  151. }
  152. public function getAnswer(): ?Answer
  153. {
  154. return $this->answer;
  155. }
  156. public function setAnswer(?Answer $answer): void
  157. {
  158. $this->answer = $answer;
  159. }
  160. public function getProblemDndBin(): ?ProblemDndBin
  161. {
  162. return $this->problemDndBin;
  163. }
  164. public function setProblemDndBin(?ProblemDndBin $problemDndBin): void
  165. {
  166. $this->problemDndBin = $problemDndBin;
  167. }
  168. // used as field in CMS
  169. public function getUsage()
  170. {
  171. return MediaEntityHelper::getMediaUsages($this);
  172. }
  173. // used as field in CMS
  174. public function isValid(): bool
  175. {
  176. return MediaEntityHelper::isMediaValid($this);
  177. }
  178. public function isUsed(): bool
  179. {
  180. return MediaEntityHelper::isUsed($this);
  181. }
  182. public function numberOfUsages(): int {
  183. return MediaEntityHelper::numberOfUsages($this);
  184. }
  185. public function getIsDeleted(): ?bool
  186. {
  187. return $this->isDeleted;
  188. }
  189. public function setIsDeleted(?bool $isDeleted): void
  190. {
  191. $this->isDeleted = $isDeleted;
  192. }
  193. public function getFullMediaPath(): ?string
  194. {
  195. return $this->filePath ? '/' . self::UPLOAD_DIRECTORY . $this->filePath : null;
  196. }
  197. }