<?php
namespace Nen\Bundle\KennisbankPlatformBundle\Entity;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Translatable\Translatable;
use Nen\Bundle\KennisbankPlatformBundle\Entity\Bolt\BoltEntity;
use Nen\Bundle\KennisbankPlatformBundle\Entity\Bolt\BoltEntitySeoTrait;
use Nen\Bundle\KennisbankPlatformBundle\Entity\Bolt\BoltEntityTranslatableTrait;
use Nen\Bundle\KennisbankPlatformBundle\Entity\Bolt\BoltTaxonomy;
use Nen\Bundle\KennisbankPlatformBundle\Repository\BoltPageRepository;
/**
* @ORM\Entity(repositoryClass=BoltPageRepository::class)
* @ORM\Table(name="bolt_pages")
*/
class BoltPage extends BoltEntity implements Translatable
{
use BoltEntitySeoTrait;
use BoltEntityTranslatableTrait;
/**
* @ORM\OneToMany(targetEntity=BoltTaxonomy::class, mappedBy="page")
*/
protected Collection $taxonomy;
/**
* @ORM\Column(name="title", type="string", length=256, nullable=true)
*
* @Gedmo\Translatable()
*/
private ?string $title = null;
/**
* @ORM\Column(name="description", type="text", nullable=true)
*
* @Gedmo\Translatable()
*/
private ?string $description = null;
/**
* @ORM\Column(name="faqs", type="string", length=256, nullable=true)
*/
private ?string $faqCategory = null;
/**
* @ORM\Column(name="about_title", type="string", length=256, nullable=true)
*
* @Gedmo\Translatable()
*/
private ?string $aboutTitle = null;
/**
* @ORM\Column(name="about_description", type="text", nullable=true)
*
* @Gedmo\Translatable()
*/
private ?string $aboutDescription = null;
/**
* @ORM\Column(name="tool", type="text", nullable=true)
*/
private ?string $tool = null;
/**
* @ORM\Column(name="subscriptions", type="json", nullable=true)
*/
private ?array $subscriptions = null;
private array $blocks = [];
private array $pages = [];
private array $faqs = [];
private array $sections = [];
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getFaqCategory(): ?string
{
return $this->faqCategory;
}
public function setFaqCategory(?string $faqCategory): self
{
$this->faqCategory = $faqCategory;
return $this;
}
public function getAboutTitle(): ?string
{
return $this->aboutTitle;
}
public function setAboutTitle(?string $aboutTitle): self
{
$this->aboutTitle = $aboutTitle;
return $this;
}
public function getAboutDescription(): ?string
{
return $this->aboutDescription;
}
public function setAboutDescription(?string $aboutDescription): self
{
$this->aboutDescription = $aboutDescription;
return $this;
}
public function getBlocks(): array
{
return $this->blocks;
}
public function setBlocks(array $blocks): self
{
$this->blocks = $blocks;
return $this;
}
public function hasBlocks(): bool
{
return count($this->blocks) > 0;
}
public function getPages(): array
{
return $this->pages;
}
public function setPages(array $pages): self
{
$this->pages = $pages;
return $this;
}
public function hasPages(): bool
{
return count($this->pages) > 0;
}
public function getFaqs(): array
{
return $this->faqs;
}
public function setFaqs(array $faqs): self
{
$this->faqs = $faqs;
return $this;
}
public function getSection(): ?BoltTaxonomy
{
return $this->taxonomy->matching(
Criteria::create()
->andWhere(Criteria::expr()->eq('contenttype', 'pages'))
->andWhere(Criteria::expr()->eq('contentId', $this->getId()))
->andWhere(Criteria::expr()->eq('taxonomytype', 'sections'))
// Since Bolt 3 taxonomy is always saved, even when empty.
->andWhere(Criteria::expr()->neq('slug', ''))
->setMaxResults(1)
)->first() ?: null;
}
public function getSubscriptions(): ?array
{
return $this->subscriptions;
}
public function setSubscriptions(?array $subscriptions): self
{
$this->subscriptions = $subscriptions;
return $this;
}
public function getTool(): ?string
{
return $this->tool;
}
public function setTool(?string $tool): self
{
$this->tool = $tool;
return $this;
}
public function getSections(): array
{
return $this->sections;
}
public function setSections(array $sections): self
{
foreach ($sections as $section) {
$first = array_values($section)[0];
$this->sections[] = [
'type' => $first->getBlock(),
'value' => $section,
];
}
return $this;
}
}