src/Entity/Core/SelfStudy/SelfStudyTypicalExamProblemElement.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Core\SelfStudy;
  3. use App\Entity\Core\RelationSelfStudyTypicalExamProblemElementImageReference;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Table('self_study_typical_exam_problem_element')]
  8. #[ORM\Entity]
  9. class SelfStudyTypicalExamProblemElement
  10. {
  11. /**
  12. * @var int
  13. */
  14. #[ORM\Column(name: 'id', type: 'integer')]
  15. #[ORM\Id]
  16. #[ORM\GeneratedValue(strategy: 'AUTO')]
  17. private $id;
  18. /**
  19. * @var int
  20. */
  21. #[ORM\Column(name: 'sortorder', type: 'integer')]
  22. private $order;
  23. /**
  24. * @var string
  25. */
  26. #[ORM\Column(name: 'type', type: 'string', length: 255)]
  27. private $type;
  28. /**
  29. * @var string
  30. */
  31. #[ORM\Column(name: 'content', type: 'string', length: 2500)]
  32. private $content;
  33. /**
  34. * @var SelfStudyTypicalExamProblem
  35. */
  36. #[ORM\JoinColumn(name: 'self_study_typical_exam_problem', referencedColumnName: 'id')]
  37. #[ORM\ManyToOne(targetEntity: SelfStudyTypicalExamProblem::class, inversedBy: 'elements')]
  38. private $problem;
  39. /**
  40. * @var Collection|RelationSelfStudyTypicalExamProblemElementImageReference[]
  41. */
  42. #[ORM\OneToMany(mappedBy: 'selfStudyTypicalExamProblemElement', targetEntity: RelationSelfStudyTypicalExamProblemElementImageReference::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
  43. private array|Collection|ArrayCollection $imageReferences;
  44. public function __construct()
  45. {
  46. $this->imageReferences = new ArrayCollection();
  47. }
  48. /**
  49. * @return int
  50. */
  51. public function getId()
  52. {
  53. return $this->id;
  54. }
  55. /**
  56. * @param int $id
  57. */
  58. public function setId($id)
  59. {
  60. $this->id = $id;
  61. }
  62. /**
  63. * @return int
  64. */
  65. public function getOrder()
  66. {
  67. return $this->order;
  68. }
  69. /**
  70. * @param int $order
  71. */
  72. public function setOrder($order)
  73. {
  74. $this->order = $order;
  75. }
  76. /**
  77. * @return string
  78. */
  79. public function getType()
  80. {
  81. return $this->type;
  82. }
  83. /**
  84. * @param string $type
  85. */
  86. public function setType($type)
  87. {
  88. $this->type = $type;
  89. }
  90. /**
  91. * @return string
  92. */
  93. public function getContent()
  94. {
  95. return $this->content;
  96. }
  97. /**
  98. * @param string $content
  99. */
  100. public function setContent($content)
  101. {
  102. $this->content = $content;
  103. }
  104. /**
  105. * @return SelfStudyTypicalExamProblem
  106. */
  107. public function getProblem()
  108. {
  109. return $this->problem;
  110. }
  111. /**
  112. * @param SelfStudyTypicalExamProblem $problem
  113. */
  114. public function setProblem($problem)
  115. {
  116. $this->problem = $problem;
  117. }
  118. public function getImageReferences(): Collection
  119. {
  120. return $this->imageReferences;
  121. }
  122. public function setImageReferences(Collection $imageReferences): void
  123. {
  124. $this->imageReferences = $imageReferences;
  125. }
  126. public function getContentWithInlineImagesParsed(): string
  127. {
  128. $parsedContent = $this->content;
  129. foreach ($this->imageReferences as $imageReference) {
  130. $imageTag = '<img class="mp-img" ';
  131. if ($imageReference->getWidth() !== null) {
  132. $imageTag .= 'style="width: ' . $imageReference->getWidth() . '%" ';
  133. }
  134. $imageTag .= 'src="' . $imageReference->getImageReference()->getFullMediaPath() . '">';
  135. $parsedContent = str_replace('{{ image_' . $imageReference->getSorting() . ' }}', $imageTag, $parsedContent);
  136. }
  137. return $parsedContent;
  138. }
  139. }