<?php
namespace CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table("textbook_element")
* @ORM\Entity
* @ORM\Entity(repositoryClass="TextbookElementRepository")
*/
class TextbookElement
{
/**
* @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="name", type="string", length=255, nullable=true)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="content", type="string", length=5000)
*/
private $content;
/**
* @var TextbookSubTopic
*
* @ORM\ManyToOne(targetEntity="TextbookSubTopic", inversedBy="textbookElements")
* @ORM\JoinColumn(name="subtopic_id", referencedColumnName="id")
*/
private $textbookSubTopic;
/**
* @var ?string
*
* @ORM\Column(name="textbook_image", type="string", nullable=true)
*/
private $textbookImage;
/**
* @var string
*
* @ORM\Column(name="title", type="string", nullable=true)
*/
private $title;
/**
* @var string
*
* @ORM\Column(name="explanation", type="string", nullable=true, length=1000)
*/
private $explanation;
/**
* @var string
*
* @ORM\Column(name="math_index", type="string", nullable=true)
*/
private $mathIndex;
/**
* @var ArrayCollection|TagMathproblem[]
*
* @ORM\ManyToMany(targetEntity="TagMathproblem", inversedBy="textbookElements")
* @ORM\JoinTable(name="relation_textbook_element_tag",
* joinColumns={@ORM\JoinColumn(name="textbookelement_id", referencedColumnName="id")})
* inverseJoinColumns={@ORM\JoinColumn(name="mpelement_problem_id", referencedColumnName="id")},
*/
private $tags;
/**
* @var bool
* @ORM\Column(type="boolean", name="use_as_hint", options={"default": true})
*/
private $useAsHint;
/**
* @var string
*
* @ORM\Column(name="thumbnail", type="string", nullable=true)
*/
private $thumbnail;
/**
* @var Collection|RelationTextbookElementImageReference[]
* @ORM\OneToMany(targetEntity="RelationTextbookElementImageReference", mappedBy="textbookElement", orphanRemoval=true, cascade={"persist", "remove"})
*/
private array|Collection|ArrayCollection $imageReferences;
public function __construct()
{
$this->imageReferences = new ArrayCollection();
}
/**
* @return int
*/
public function getOrder()
{
return $this->order;
}
/**
* @var ArrayCollection|TemplateMathproblem[]
* @ORM\ManyToMany(targetEntity="TemplateMathproblem", mappedBy="tags")
*
*/
/**
* @return int
*/
public function getType()
{
return $this->type;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @return string
*/
public function getContent()
{
return $this->content;
}
/**
* @return TextbookSubTopic
*/
public function getTextbookSubTopic()
{
return $this->textbookSubTopic;
}
/**
* @return ?string
*/
public function getTextbookImage()
{
return $this->textbookImage;
}
/**
* @return string|null
*/
public function getTitle()
{
return $this->title;
}
/**
* @return TagMathproblem[]|ArrayCollection
*/
public function getTags()
{
return $this->tags;
}
/**
* @param TagMathproblem[]|ArrayCollection $tags
*/
public function setTags($tags)
{
$this->tags = $tags;
}
/**
* @return bool
*/
public function isUseAsHint(): bool
{
return $this->useAsHint;
}
/**
* @param string|null $content
* @return $this
*/
public function setContent(?string $content): self
{
$this->content = $content;
return $this;
}
/**
* @param bool $useAsHint
*/
public function setUseAsHint(bool $useAsHint): void
{
$this->useAsHint = $useAsHint;
}
public function getMathIndex(): ?string
{
return $this->mathIndex;
}
public function setMathIndex(?string $mathIndex)
{
$this->mathIndex = $mathIndex;
}
public function getId(): int
{
return $this->id;
}
/**
* @return string
*/
public function getExplanation(): ?string
{
return $this->explanation;
}
/**
* @param string $explanation
*/
public function setExplanation(string $explanation): void
{
$this->explanation = $explanation;
}
/**
* @return string|null
*/
public function getThumbnail(): ?string
{
return $this->thumbnail;
}
/**
* @param string $thumbnail
*/
public function setThumbnail(?string $thumbnail): void
{
$this->thumbnail = $thumbnail;
}
public function getImageReferences(): Collection
{
return $this->imageReferences;
}
/**
* @param Collection $imageReferences
*/
public function setImageReferences(Collection $imageReferences): void
{
$this->imageReferences = $imageReferences;
}
public function setTextbookImage(?string $textbookImage): void
{
$this->textbookImage = $textbookImage;
}
public function getTextbookImageByReference(): ?string
{
foreach ($this->imageReferences as $imageReference) {
if ($imageReference->getSorting() === 0)
return $imageReference->getImageReference()->getFullMediaPath();
}
//TODO: Image migration - Remove after all migrations has been run.
if ($this->textbookImage) {
return "/bundles/abacuscore/textbook_images/$this->textbookImage.png";
}
return null;
}
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;
}
}