src/CoreBundle/Entity/ImageReference.php line 13

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