<?php
namespace App\Entity\Core\SelfStudy;
use App\Entity\Core\RelationSelfStudyTypicalExamProblemElementImageReference;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Table('self_study_typical_exam_problem_element')]
#[ORM\Entity]
class SelfStudyTypicalExamProblemElement
{
/**
* @var int
*/
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private $id;
/**
* @var int
*/
#[ORM\Column(name: 'sortorder', type: 'integer')]
private $order;
/**
* @var string
*/
#[ORM\Column(name: 'type', type: 'string', length: 255)]
private $type;
/**
* @var string
*/
#[ORM\Column(name: 'content', type: 'string', length: 2500)]
private $content;
/**
* @var SelfStudyTypicalExamProblem
*/
#[ORM\JoinColumn(name: 'self_study_typical_exam_problem', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: SelfStudyTypicalExamProblem::class, inversedBy: 'elements')]
private $problem;
/**
* @var Collection|RelationSelfStudyTypicalExamProblemElementImageReference[]
*/
#[ORM\OneToMany(mappedBy: 'selfStudyTypicalExamProblemElement', targetEntity: RelationSelfStudyTypicalExamProblemElementImageReference::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
private array|Collection|ArrayCollection $imageReferences;
public function __construct()
{
$this->imageReferences = new ArrayCollection();
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return int
*/
public function getOrder()
{
return $this->order;
}
/**
* @param int $order
*/
public function setOrder($order)
{
$this->order = $order;
}
/**
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* @param string $type
*/
public function setType($type)
{
$this->type = $type;
}
/**
* @return string
*/
public function getContent()
{
return $this->content;
}
/**
* @param string $content
*/
public function setContent($content)
{
$this->content = $content;
}
/**
* @return SelfStudyTypicalExamProblem
*/
public function getProblem()
{
return $this->problem;
}
/**
* @param SelfStudyTypicalExamProblem $problem
*/
public function setProblem($problem)
{
$this->problem = $problem;
}
public function getImageReferences(): Collection
{
return $this->imageReferences;
}
public function setImageReferences(Collection $imageReferences): void
{
$this->imageReferences = $imageReferences;
}
public function getContentWithInlineImagesParsed(): string
{
$parsedContent = $this->content;
foreach ($this->imageReferences as $imageReference) {
$imageTag = '<img class="mp-img" ';
if ($imageReference->getWidth() !== null) {
$imageTag .= 'style="width: ' . $imageReference->getWidth() . '%" ';
}
$imageTag .= 'src="' . $imageReference->getImageReference()->getFullMediaPath() . '">';
$parsedContent = str_replace('{{ image_' . $imageReference->getSorting() . ' }}', $imageTag, $parsedContent);
}
return $parsedContent;
}
}