src/Entity/Core/Textbook/TextbookElement.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Core\Textbook;
  3. use App\Entity\Core\RelationTextbookElementImageReference;
  4. use App\Entity\Core\TagMathproblem;
  5. use App\Entity\Core\TemplateMathproblem;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. #[ORM\Table('textbook_element')]
  10. #[ORM\Entity(repositoryClass: TextbookElementRepository::class)]
  11. class TextbookElement
  12. {
  13. /**
  14. * @var int
  15. */
  16. #[ORM\Column(name: 'id', type: 'integer')]
  17. #[ORM\Id]
  18. #[ORM\GeneratedValue(strategy: 'AUTO')]
  19. private $id;
  20. /**
  21. * @var int
  22. */
  23. #[ORM\Column(name: 'sortorder', type: 'integer')]
  24. private $order;
  25. /**
  26. * @var string
  27. */
  28. #[ORM\Column(name: 'type', type: 'string', length: 255)]
  29. private $type;
  30. /**
  31. * @var string
  32. */
  33. #[ORM\Column(name: 'name', type: 'string', length: 255, nullable: true)]
  34. private $name;
  35. /**
  36. * @var string
  37. */
  38. #[ORM\Column(name: 'content', type: 'string', length: 5000)]
  39. private $content;
  40. /**
  41. * @var TextbookSubTopic
  42. */
  43. #[ORM\JoinColumn(name: 'subtopic_id', referencedColumnName: 'id')]
  44. #[ORM\ManyToOne(targetEntity: TextbookSubTopic::class, inversedBy: 'textbookElements')]
  45. private $textbookSubTopic;
  46. /**
  47. * @var string
  48. */
  49. #[ORM\Column(name: 'title', type: 'string', nullable: true)]
  50. private $title;
  51. /**
  52. * @var string
  53. */
  54. #[ORM\Column(name: 'explanation', type: 'string', nullable: true, length: 1000)]
  55. private $explanation;
  56. /**
  57. * @var string
  58. */
  59. #[ORM\Column(name: 'math_index', type: 'string', nullable: true)]
  60. private $mathIndex;
  61. /**
  62. * @var ArrayCollection|TagMathproblem[]
  63. */
  64. #[ORM\JoinTable(name: 'relation_textbook_element_tag')]
  65. #[ORM\JoinColumn(name: 'textbookelement_id', referencedColumnName: 'id')]
  66. #[ORM\ManyToMany(targetEntity: TagMathproblem::class, inversedBy: 'textbookElements')]
  67. private $tags;
  68. /**
  69. * @var bool
  70. */
  71. #[ORM\Column(type: 'boolean', name: 'use_as_hint', options: ['default' => true])]
  72. private $useAsHint;
  73. /**
  74. * @var string
  75. */
  76. #[ORM\Column(name: 'thumbnail', type: 'string', nullable: true)]
  77. private $thumbnail;
  78. /**
  79. * @var Collection|RelationTextbookElementImageReference[]
  80. */
  81. #[ORM\OneToMany(targetEntity: RelationTextbookElementImageReference::class, mappedBy: 'textbookElement', orphanRemoval: true, cascade: ['persist', 'remove'])]
  82. private array|Collection|ArrayCollection $imageReferences;
  83. public function __construct()
  84. {
  85. $this->imageReferences = new ArrayCollection();
  86. }
  87. /**
  88. * @return int
  89. */
  90. public function getOrder()
  91. {
  92. return $this->order;
  93. }
  94. /**
  95. * @return int
  96. */
  97. public function getType()
  98. {
  99. return $this->type;
  100. }
  101. /**
  102. * @return string
  103. */
  104. public function getName()
  105. {
  106. return $this->name;
  107. }
  108. /**
  109. * @return string
  110. */
  111. public function getContent()
  112. {
  113. return $this->content;
  114. }
  115. /**
  116. * @return TextbookSubTopic
  117. */
  118. public function getTextbookSubTopic()
  119. {
  120. return $this->textbookSubTopic;
  121. }
  122. /**
  123. * @return string|null
  124. */
  125. public function getTitle()
  126. {
  127. return $this->title;
  128. }
  129. /**
  130. * @return TagMathproblem[]|ArrayCollection
  131. */
  132. public function getTags()
  133. {
  134. return $this->tags;
  135. }
  136. /**
  137. * @param TagMathproblem[]|ArrayCollection $tags
  138. */
  139. public function setTags($tags)
  140. {
  141. $this->tags = $tags;
  142. }
  143. public function isUseAsHint(): bool
  144. {
  145. return $this->useAsHint;
  146. }
  147. /**
  148. * @return $this
  149. */
  150. public function setContent(?string $content): self
  151. {
  152. $this->content = $content;
  153. return $this;
  154. }
  155. public function setUseAsHint(bool $useAsHint): void
  156. {
  157. $this->useAsHint = $useAsHint;
  158. }
  159. public function getMathIndex(): ?string
  160. {
  161. return $this->mathIndex;
  162. }
  163. public function setMathIndex(?string $mathIndex)
  164. {
  165. $this->mathIndex = $mathIndex;
  166. }
  167. public function getId(): int
  168. {
  169. return $this->id;
  170. }
  171. /**
  172. * @return string
  173. */
  174. public function getExplanation(): ?string
  175. {
  176. return $this->explanation;
  177. }
  178. public function setExplanation(string $explanation): void
  179. {
  180. $this->explanation = $explanation;
  181. }
  182. public function getThumbnail(): ?string
  183. {
  184. return $this->thumbnail;
  185. }
  186. /**
  187. * @param string $thumbnail
  188. */
  189. public function setThumbnail(?string $thumbnail): void
  190. {
  191. $this->thumbnail = $thumbnail;
  192. }
  193. public function getImageReferences(): Collection
  194. {
  195. return $this->imageReferences;
  196. }
  197. public function setImageReferences(Collection $imageReferences): void
  198. {
  199. $this->imageReferences = $imageReferences;
  200. }
  201. public function getTextbookImageByReference(): ?string
  202. {
  203. foreach ($this->imageReferences as $imageReference) {
  204. if ($imageReference->getSorting() === 0)
  205. return $imageReference->getImageReference()->getFullMediaPath();
  206. }
  207. return null;
  208. }
  209. public function getContentWithInlineImagesParsed(): string
  210. {
  211. $parsedContent = $this->content;
  212. foreach ($this->imageReferences as $imageReference) {
  213. $imageTag = '<img class="mp-img" ';
  214. if ($imageReference->getWidth() !== null) {
  215. $imageTag .= 'style="width: ' . $imageReference->getWidth() . '%" ';
  216. }
  217. $imageTag .= 'src="' . $imageReference->getImageReference()->getFullMediaPath() . '">';
  218. $parsedContent = str_replace('{{ image_' . $imageReference->getSorting() . ' }}', $imageTag, $parsedContent);
  219. }
  220. return $parsedContent;
  221. }
  222. }