src/CoreBundle/Entity/TextbookElement.php line 15

Open in your IDE?
  1. <?php
  2. namespace CoreBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7. * @ORM\Table("textbook_element")
  8. * @ORM\Entity
  9. * @ORM\Entity(repositoryClass="TextbookElementRepository")
  10. */
  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. */
  20. private $id;
  21. /**
  22. * @var int
  23. *
  24. * @ORM\Column(name="sortorder", type="integer")
  25. */
  26. private $order;
  27. /**
  28. * @var string
  29. *
  30. * @ORM\Column(name="type", type="string", length=255)
  31. */
  32. private $type;
  33. /**
  34. * @var string
  35. *
  36. * @ORM\Column(name="name", type="string", length=255, nullable=true)
  37. */
  38. private $name;
  39. /**
  40. * @var string
  41. *
  42. * @ORM\Column(name="content", type="string", length=5000)
  43. */
  44. private $content;
  45. /**
  46. * @var TextbookSubTopic
  47. *
  48. * @ORM\ManyToOne(targetEntity="TextbookSubTopic", inversedBy="textbookElements")
  49. * @ORM\JoinColumn(name="subtopic_id", referencedColumnName="id")
  50. */
  51. private $textbookSubTopic;
  52. /**
  53. * @var ?string
  54. *
  55. * @ORM\Column(name="textbook_image", type="string", nullable=true)
  56. */
  57. private $textbookImage;
  58. /**
  59. * @var string
  60. *
  61. * @ORM\Column(name="title", type="string", nullable=true)
  62. */
  63. private $title;
  64. /**
  65. * @var string
  66. *
  67. * @ORM\Column(name="explanation", type="string", nullable=true, length=1000)
  68. */
  69. private $explanation;
  70. /**
  71. * @var string
  72. *
  73. * @ORM\Column(name="math_index", type="string", nullable=true)
  74. */
  75. private $mathIndex;
  76. /**
  77. * @var ArrayCollection|TagMathproblem[]
  78. *
  79. * @ORM\ManyToMany(targetEntity="TagMathproblem", inversedBy="textbookElements")
  80. * @ORM\JoinTable(name="relation_textbook_element_tag",
  81. * joinColumns={@ORM\JoinColumn(name="textbookelement_id", referencedColumnName="id")})
  82. * inverseJoinColumns={@ORM\JoinColumn(name="mpelement_problem_id", referencedColumnName="id")},
  83. */
  84. private $tags;
  85. /**
  86. * @var bool
  87. * @ORM\Column(type="boolean", name="use_as_hint", options={"default": true})
  88. */
  89. private $useAsHint;
  90. /**
  91. * @var string
  92. *
  93. * @ORM\Column(name="thumbnail", type="string", nullable=true)
  94. */
  95. private $thumbnail;
  96. /**
  97. * @var Collection|RelationTextbookElementImageReference[]
  98. * @ORM\OneToMany(targetEntity="RelationTextbookElementImageReference", mappedBy="textbookElement", orphanRemoval=true, cascade={"persist", "remove"})
  99. */
  100. private array|Collection|ArrayCollection $imageReferences;
  101. public function __construct()
  102. {
  103. $this->imageReferences = new ArrayCollection();
  104. }
  105. /**
  106. * @return int
  107. */
  108. public function getOrder()
  109. {
  110. return $this->order;
  111. }
  112. /**
  113. * @var ArrayCollection|TemplateMathproblem[]
  114. * @ORM\ManyToMany(targetEntity="TemplateMathproblem", mappedBy="tags")
  115. *
  116. */
  117. /**
  118. * @return int
  119. */
  120. public function getType()
  121. {
  122. return $this->type;
  123. }
  124. /**
  125. * @return string
  126. */
  127. public function getName()
  128. {
  129. return $this->name;
  130. }
  131. /**
  132. * @return string
  133. */
  134. public function getContent()
  135. {
  136. return $this->content;
  137. }
  138. /**
  139. * @return TextbookSubTopic
  140. */
  141. public function getTextbookSubTopic()
  142. {
  143. return $this->textbookSubTopic;
  144. }
  145. /**
  146. * @return ?string
  147. */
  148. public function getTextbookImage()
  149. {
  150. return $this->textbookImage;
  151. }
  152. /**
  153. * @return string|null
  154. */
  155. public function getTitle()
  156. {
  157. return $this->title;
  158. }
  159. /**
  160. * @return TagMathproblem[]|ArrayCollection
  161. */
  162. public function getTags()
  163. {
  164. return $this->tags;
  165. }
  166. /**
  167. * @param TagMathproblem[]|ArrayCollection $tags
  168. */
  169. public function setTags($tags)
  170. {
  171. $this->tags = $tags;
  172. }
  173. /**
  174. * @return bool
  175. */
  176. public function isUseAsHint(): bool
  177. {
  178. return $this->useAsHint;
  179. }
  180. /**
  181. * @param string|null $content
  182. * @return $this
  183. */
  184. public function setContent(?string $content): self
  185. {
  186. $this->content = $content;
  187. return $this;
  188. }
  189. /**
  190. * @param bool $useAsHint
  191. */
  192. public function setUseAsHint(bool $useAsHint): void
  193. {
  194. $this->useAsHint = $useAsHint;
  195. }
  196. public function getMathIndex(): ?string
  197. {
  198. return $this->mathIndex;
  199. }
  200. public function setMathIndex(?string $mathIndex)
  201. {
  202. $this->mathIndex = $mathIndex;
  203. }
  204. public function getId(): int
  205. {
  206. return $this->id;
  207. }
  208. /**
  209. * @return string
  210. */
  211. public function getExplanation(): ?string
  212. {
  213. return $this->explanation;
  214. }
  215. /**
  216. * @param string $explanation
  217. */
  218. public function setExplanation(string $explanation): void
  219. {
  220. $this->explanation = $explanation;
  221. }
  222. /**
  223. * @return string|null
  224. */
  225. public function getThumbnail(): ?string
  226. {
  227. return $this->thumbnail;
  228. }
  229. /**
  230. * @param string $thumbnail
  231. */
  232. public function setThumbnail(?string $thumbnail): void
  233. {
  234. $this->thumbnail = $thumbnail;
  235. }
  236. public function getImageReferences(): Collection
  237. {
  238. return $this->imageReferences;
  239. }
  240. /**
  241. * @param Collection $imageReferences
  242. */
  243. public function setImageReferences(Collection $imageReferences): void
  244. {
  245. $this->imageReferences = $imageReferences;
  246. }
  247. public function setTextbookImage(?string $textbookImage): void
  248. {
  249. $this->textbookImage = $textbookImage;
  250. }
  251. public function getTextbookImageByReference(): ?string
  252. {
  253. foreach ($this->imageReferences as $imageReference) {
  254. if ($imageReference->getSorting() === 0)
  255. return $imageReference->getImageReference()->getFullMediaPath();
  256. }
  257. //TODO: Image migration - Remove after all migrations has been run.
  258. if ($this->textbookImage) {
  259. return "/bundles/abacuscore/textbook_images/$this->textbookImage.png";
  260. }
  261. return null;
  262. }
  263. public function getContentWithInlineImagesParsed(): string
  264. {
  265. $parsedContent = $this->content;
  266. foreach ($this->imageReferences as $imageReference) {
  267. $imageTag = '<img class="mp-img" ';
  268. if ($imageReference->getWidth() !== null) {
  269. $imageTag .= 'style="width: ' . $imageReference->getWidth() . '%" ';
  270. }
  271. $imageTag .= 'src="' . $imageReference->getImageReference()->getFullMediaPath() . '">';
  272. $parsedContent = str_replace('{{ image_' . $imageReference->getSorting() . ' }}', $imageTag, $parsedContent);
  273. }
  274. return $parsedContent;
  275. }
  276. }