src/Flexy/FrontBundle/Entity/Page.php line 34
<?php
namespace App\Flexy\FrontBundle\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use App\Flexy\FrontBundle\Repository\PageRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Link;
use Symfony\Component\Serializer\Annotation\Groups;
use Gedmo\Translatable\Translatable;
use Gedmo\Mapping\Annotation as Gedmo;
/**
*
* @example This page need to have a rich content for SEO (in htmlContent) Texts and
* paragraphes with cool design using bootstrap CSS 5+ and icons from font awesome
*
*/
#[ApiResource(
normalizationContext: ['groups' => ['read']],
denormalizationContext: ['groups' => ['write']],
)]
#[ApiFilter(SearchFilter::class,properties:["slug"=>"exact"])]
#[ORM\Entity(repositoryClass: PageRepository::class)]
#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: true)]
#[ORM\Cache(usage:"NONSTRICT_READ_WRITE",region:"append_depend")]
class Page implements Translatable
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Groups(['read'])]
private $id;
/**
* #requiredForAi
* @example Give me HTML5 with some cool CSS 3 using bootstrap 5 ,You can Use (Containers,Grids,ListGroups,Accordions,Form controls), Suggest paragraphs (at least 16 if type simple, 4 if widget) use all images provided
*/
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $htmlContent = null;
#[ORM\Column(type: 'string', length: 255, nullable: false)]
#[Groups(['read','write'])]
#[Gedmo\Translatable]
private $title;
#[ORM\Column(type: 'json', nullable: true)]
#[Groups(['read','write'])]
#[Gedmo\Translatable]
private $jsonContent=[];
#[ORM\Column(type: 'json', nullable: true)]
#[Groups(['read','write'])]
#[Gedmo\Translatable]
private $jsonSimplifiedContent;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTimeInterface $createdAt = null;
/**
* @Gedmo\Slug(fields={"title"})
*/
#[Gedmo\Slug(fields: ['title'], unique:true, updatable:false)]
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read','write'])]
private ?string $slug = null;
#[ORM\Column(type: 'boolean', nullable: true)]
private ?bool $isEnabled = null;
#[ORM\OneToOne(targetEntity: Link::class, cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(nullable: true, onDelete: 'CASCADE')]
private $link;
/**
*
* @example [wysiwyg|simple|summernote] type of page editor default is wysiwyg
*/
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $pageEditor="summernote";
/**
*
* @example [simple|widget] default is simple (Is the full page with more content)
*/
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $type="simple";
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $deletedAt = null;
/**
* Used locale to override Translation listener`s locale
* this is not a mapped field of entity metadata, just a simple property
*/
#[Gedmo\Locale]
private $locale;
#[ORM\Column(length: 255, nullable: true)]
private ?string $image = null;
#[ORM\ManyToMany(targetEntity: CategoryPage::class, inversedBy: 'pages')]
private Collection $categories;
#[ORM\Column(length: 255, nullable: true)]
private ?string $keywords = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $titleAdmin = null;
#[Groups(['read','write'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $frontHook = null;
#[Groups(['read','write'])]
#[ORM\Column(nullable: true)]
private ?int $frontHookPriority = null;
public function __construct()
{
$this->categories = new ArrayCollection();
}
public function __toString()
{
return $this->title. " (".$this->type.")";
}
public function getId(): ?int
{
return $this->id;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getIsEnabled(): ?bool
{
return $this->isEnabled;
}
public function setIsEnabled(?bool $isEnabled): self
{
$this->isEnabled = $isEnabled;
return $this;
}
/**
* Get the value of title
*/
public function getTitle()
{
return $this->title;
}
/**
* Set the value of title
*
* @return self
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get the value of link
*/
public function getLink()
{
return $this->link;
}
/**
* Set the value of link
*
* @return self
*/
public function setLink($link)
{
$this->link = $link;
return $this;
}
/**
* Get the value of jsonContent
*/
public function getJsonContent()
{
if($this->jsonContent==null){
return [];
}
return $this->jsonContent;
}
/**
* Set the value of jsonContent
*
* @return self
*/
public function setJsonContent($jsonContent)
{
$this->jsonContent = $jsonContent;
return $this;
}
#[Groups(['read'])]
public function getJsonContentCSS() {
$contents = $this->jsonSimplifiedContent;
$css = '';
if(!$contents){
return '';
}
//dd($this->jsonContent);
foreach ($contents as $singleContent) {
$css = $css.$singleContent["css"];
}
return $css;
}
#[Groups(['read'])]
public function getJsonContentHTML() {
$contents = $this->jsonSimplifiedContent;
$html = '';
if(!$contents){
return '';
}
//dd($this->jsonContent);
foreach ($contents as $singleContent) {
$html = $html.$singleContent["html"];
}
return $html;
}
public function jsonContentToHtml() {
$obj = $this->jsonContent;
$html = '';
//dd($this->jsonContent);
foreach ($obj["blocks"] as $block) {
switch ($block["type"]) {
case 'paragraph':
$html .= '<p>' . $block["data"]["text"] . '</p>';
break;
case 'header':
$html .= '<h'. $block["data"]["level"] .'>' . $block["data"]["text"] . '</h'. $block["data"]["level"] .'>';
break;
case 'raw':
$html .= $block["data"]["html"];
break;
case 'list':
$lsType = ($block["data"]["style"] == 'ordered') ? 'ol' : 'ul';
$html .= '<' . $lsType . '>';
foreach($block["data"]["items"] as $item) {
$html .= '<li>' . $item . '</li>';
}
$html .= '</' . $lsType . '>';
break;
case 'code':
$html .= '<pre><code class="language-'. $block["data"]["lang"] .'">'. $block["data"]["code"] .'</code></pre>';
break;
case 'image':
$html .= '<div class="img_pnl"><img src="'. $block["data"]["file"]["url"]->url .'" /></div>';
break;
default:
break;
}
}
return $html;
}
/**
* Get the value of pageEditor
*/
public function getPageEditor()
{
return $this->pageEditor;
}
/**
* Set the value of pageEditor
*
* @return self
*/
public function setPageEditor($pageEditor)
{
$this->pageEditor = $pageEditor;
return $this;
}
/**
* Get the value of jsonSimplifiedContent
*/
public function getJsonSimplifiedContent()
{
return $this->jsonSimplifiedContent;
}
/**
* Set the value of jsonSimplifiedContent
*
* @return self
*/
public function setJsonSimplifiedContent($jsonSimplifiedContent)
{
$this->jsonSimplifiedContent = $jsonSimplifiedContent;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
/**
* Get the value of type
*/
public function getType()
{
return $this->type;
}
/**
* Set the value of type
*
* @return self
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
public function getHtmlContent(): ?string
{
return $this->htmlContent;
}
public function setHtmlContent(?string $htmlContent): static
{
$this->htmlContent = $htmlContent;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): static
{
$this->image = $image;
return $this;
}
/**
* @return Collection<int, CategoryPage>
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(CategoryPage $category): static
{
if (!$this->categories->contains($category)) {
$this->categories->add($category);
$category->addPage($this);
}
return $this;
}
public function removeCategory(CategoryPage $category): static
{
if ($this->categories->removeElement($category)) {
$category->removePage($this);
}
return $this;
}
public function getKeywords(): ?string
{
return $this->keywords;
}
public function setKeywords(?string $keywords): static
{
$this->keywords = $keywords;
return $this;
}
public function getTitleAdmin(): ?string
{
return $this->titleAdmin;
}
public function setTitleAdmin(?string $titleAdmin): static
{
$this->titleAdmin = $titleAdmin;
return $this;
}
public function getFrontHook(): ?string
{
return $this->frontHook;
}
public function setFrontHook(?string $frontHook): static
{
$this->frontHook = $frontHook;
return $this;
}
public function getFrontHookPriority(): ?int
{
return $this->frontHookPriority;
}
public function setFrontHookPriority(?int $frontHookPriority): static
{
$this->frontHookPriority = $frontHookPriority;
return $this;
}
}