src/Entity/Core/ImageReference.php line 12

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Core;
  4. use App\Entity\Core\Quiz\Quiz;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use App\Services\Admin\MediaEntityHelper;
  7. #[ORM\Table('image_reference')]
  8. #[ORM\Entity]
  9. class ImageReference implements MediaInterface
  10. {
  11. public const UPLOAD_DIRECTORY = 'uploads/images/';
  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 image
  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 image 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: 'imageReference')]
  54. private ?Mathproblem $mathproblem;
  55. #[ORM\OneToOne(targetEntity: Quiz::class, mappedBy: 'imageReference')]
  56. private ?Quiz $quiz;
  57. #[ORM\OneToOne(targetEntity: Answer::class, mappedBy: 'imageReference')]
  58. private ?Answer $answer;
  59. #[ORM\OneToOne(targetEntity: ProblemDndBin::class, mappedBy: 'imageReference')]
  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. /**
  67. * @var ?int
  68. *
  69. * Width of the image in pixels
  70. */
  71. #[ORM\Column(name: 'image_pixel_width', type: 'integer', nullable: true)]
  72. private ?int $imagePixelWidth = null;
  73. public function __construct()
  74. {
  75. $this->mathproblem = null;
  76. $this->contentHash = null;
  77. $this->filePath = null;
  78. }
  79. public function getId(): ?int
  80. {
  81. return $this->id;
  82. }
  83. public function setId(int $id): void
  84. {
  85. $this->id = $id;
  86. }
  87. public function getContentHash(): ?string
  88. {
  89. return $this->contentHash;
  90. }
  91. public function setContentHash(?string $contentHash): void
  92. {
  93. $this->contentHash = $contentHash;
  94. }
  95. public function getFilePath(): ?string
  96. {
  97. return $this->filePath;
  98. }
  99. public function setFilePath(?string $filePath): void
  100. {
  101. $this->filePath = $filePath;
  102. }
  103. public function getCreditText(): ?string
  104. {
  105. return $this->creditText;
  106. }
  107. public function setCreditText(?string $creditText): void
  108. {
  109. $this->creditText = $creditText;
  110. }
  111. public function getPosition(): ?string
  112. {
  113. return $this->position;
  114. }
  115. public function setPosition(?string $position): void
  116. {
  117. $this->position = $position;
  118. }
  119. public function getAltText(): ?string
  120. {
  121. return $this->altText;
  122. }
  123. public function setAltText(?string $altText): void
  124. {
  125. $this->altText = $altText;
  126. }
  127. public function getPublication(): ?Publication
  128. {
  129. return $this->publication;
  130. }
  131. public function setPublication(?Publication $publication): void
  132. {
  133. $this->publication = $publication;
  134. }
  135. public function getReferenceName(): string
  136. {
  137. $this->referenceName = trim($this->referenceName);
  138. $this->referenceName = str_replace(" ", "_", $this->referenceName);
  139. return $this->referenceName;
  140. }
  141. public function setReferenceName(string $referenceName): void
  142. {
  143. $referenceName = trim($referenceName);
  144. $referenceName = str_replace(" ", "_", $referenceName);
  145. $this->referenceName = $referenceName;
  146. }
  147. public function getMathproblem(): ?Mathproblem
  148. {
  149. return $this->mathproblem;
  150. }
  151. public function setMathproblem(?Mathproblem $mathproblem): void
  152. {
  153. $this->mathproblem = $mathproblem;
  154. }
  155. public function getQuiz(): ?Quiz
  156. {
  157. return $this->quiz;
  158. }
  159. public function setQuiz(Quiz $quiz): void
  160. {
  161. $this->quiz = $quiz;
  162. }
  163. public function getAnswer(): ?Answer
  164. {
  165. return $this->answer;
  166. }
  167. public function setAnswer(?Answer $answer): void
  168. {
  169. $this->answer = $answer;
  170. }
  171. public function getProblemDndBin(): ?ProblemDndBin
  172. {
  173. return $this->problemDndBin;
  174. }
  175. public function setProblemDndBin(?ProblemDndBin $problemDndBin): void
  176. {
  177. $this->problemDndBin = $problemDndBin;
  178. }
  179. // used as field in CMS
  180. public function getUsage()
  181. {
  182. return MediaEntityHelper::getMediaUsages($this);
  183. }
  184. // used as field in CMS
  185. public function isValid(): bool
  186. {
  187. return MediaEntityHelper::isMediaValid($this);
  188. }
  189. public function isUsed(): bool
  190. {
  191. return MediaEntityHelper::isUsed($this);
  192. }
  193. public function numberOfUsages(): int {
  194. return MediaEntityHelper::numberOfUsages($this);
  195. }
  196. public function getIsDeleted(): ?bool
  197. {
  198. return $this->isDeleted;
  199. }
  200. public function setIsDeleted(?bool $isDeleted): void
  201. {
  202. $this->isDeleted = $isDeleted;
  203. }
  204. public function getFullMediaPath(): ?string
  205. {
  206. return $this->filePath ? '/' . self::UPLOAD_DIRECTORY . $this->filePath : null;
  207. }
  208. public function getImagePixelWidth(): ?int
  209. {
  210. return $this->imagePixelWidth;
  211. }
  212. public function setImagePixelWidth(?int $imagePixelWidth): void
  213. {
  214. $this->imagePixelWidth = $imagePixelWidth;
  215. }
  216. }