src/Flexy/FrontBundle/Entity/Page.php line 22

  1. <?php
  2. namespace App\Flexy\FrontBundle\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  6. use App\Flexy\FrontBundle\Repository\PageRepository;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Doctrine\DBAL\Types\Types;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use App\Entity\Link;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. #[ApiResource(
  13.     normalizationContext: ['groups' => ['read']],
  14.     denormalizationContext: ['groups' => ['write']],
  15. )]
  16. #[ApiFilter(SearchFilter::class,properties:["slug"=>"exact"])]
  17. #[ORM\Entity(repositoryClassPageRepository::class)]
  18. #[Gedmo\SoftDeleteable(fieldName'deletedAt'timeAwarefalsehardDeletetrue)]
  19. class Page
  20. {
  21.     #[ORM\Id]
  22.     #[ORM\GeneratedValue]
  23.     #[ORM\Column(type'integer')]
  24.     #[Groups(['read'])]
  25.     private $id;
  26.     #[ORM\Column(type'string'length255)]
  27.     #[Groups(['read','write'])]
  28.      private $title;
  29.      
  30.     #[ORM\Column(type'text'nullabletrue)]
  31.     #[Groups(['read','write'])]
  32.     private ?string $content null;
  33.     #[ORM\Column(type'json'nullabletrue)]
  34.     #[Groups(['read','write'])]
  35.     private $jsonContent=[];
  36.     #[ORM\Column(type'json'nullabletrue)]
  37.     #[Groups(['read','write'])]
  38.     private $jsonSimplifiedContent;
  39.     #[ORM\Column(type'datetime'nullabletrue)]
  40.     private ?\DateTimeInterface $createdAt null;
  41.     /**
  42.      * @Gedmo\Slug(fields={"title"})
  43.      */
  44.     #[Gedmo\Slug(fields: ['title'])]
  45.     #[ORM\Column(type'string'length255nullabletrue)]
  46.     #[Groups(['read','write'])]
  47.     private ?string $slug null;
  48.     
  49.     #[ORM\Column(type'boolean'nullabletrue)]
  50.     private ?bool $isEnabled null;
  51.     #[ORM\OneToOne(targetEntityLink::class, cascade: ['persist''remove'])]
  52.     #[ORM\JoinColumn(nullabletrueonDelete'CASCADE')]
  53.     private $link;
  54.     #[ORM\Column(type'boolean'nullabletrue)]
  55.     private $isLiveEditor;
  56.         #[ORM\Column(type'string'length255nullabletrue)]
  57.     private $pageEditor="summernote";
  58.     #[ORM\Column(type'string'length255nullabletrue)]
  59.     private $type="simple";
  60.     
  61.         #[ORM\Column(typeTypes::TEXTnullabletrue)]
  62.         private ?string $description null;
  63.         #[ORM\Column(nullabletrue)]
  64.     private ?\DateTimeImmutable $deletedAt null;
  65.     public function getId(): ?int
  66.     {
  67.         return $this->id;
  68.     }
  69.     public function getContent(): ?string
  70.     {
  71.         return $this->content;
  72.     }
  73.     public function setContent(?string $content): self
  74.     {
  75.         $this->content $content;
  76.         return $this;
  77.     }
  78.     public function getCreatedAt(): ?\DateTimeInterface
  79.     {
  80.         return $this->createdAt;
  81.     }
  82.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  83.     {
  84.         $this->createdAt $createdAt;
  85.         return $this;
  86.     }
  87.     public function getSlug(): ?string
  88.     {
  89.         return $this->slug;
  90.     }
  91.     public function setSlug(string $slug): self
  92.     {
  93.         $this->slug $slug;
  94.         return $this;
  95.     }
  96.     public function getIsEnabled(): ?bool
  97.     {
  98.         return $this->isEnabled;
  99.     }
  100.     public function setIsEnabled(?bool $isEnabled): self
  101.     {
  102.         $this->isEnabled $isEnabled;
  103.         return $this;
  104.     }
  105.      /**
  106.       * Get the value of title
  107.       */ 
  108.      public function getTitle()
  109.      {
  110.           return $this->title;
  111.      }
  112.      /**
  113.       * Set the value of title
  114.       *
  115.       * @return  self
  116.       */ 
  117.      public function setTitle($title)
  118.      {
  119.           $this->title $title;
  120.           return $this;
  121.      }
  122.     /**
  123.      * Get the value of link
  124.      */ 
  125.     public function getLink()
  126.     {
  127.         return $this->link;
  128.     }
  129.     /**
  130.      * Set the value of link
  131.      *
  132.      * @return  self
  133.      */ 
  134.     public function setLink($link)
  135.     {
  136.         $this->link $link;
  137.         return $this;
  138.     }
  139.     /**
  140.      * Get the value of jsonContent
  141.      */ 
  142.     public function getJsonContent()
  143.     {
  144.         if($this->jsonContent==null){
  145.             return [];
  146.         }
  147.         return $this->jsonContent;
  148.     }
  149.     /**
  150.      * Set the value of jsonContent
  151.      *
  152.      * @return  self
  153.      */ 
  154.     public function setJsonContent($jsonContent)
  155.     {
  156.         $this->jsonContent $jsonContent;
  157.         return $this;
  158.     }
  159.     public function jsonContentCSS() {
  160.         $contents $this->jsonSimplifiedContent;
  161.         $css '';
  162.         //dd($this->jsonContent);
  163.         foreach ($contents as $singleContent) {
  164.             $css $css.$singleContent["css"];
  165.         }
  166.         
  167.         return $css;
  168.     }
  169.     #[Groups(['read'])]
  170.     public function getJsonContentHTML() {
  171.         $contents $this->jsonSimplifiedContent;
  172.         $html '';
  173.         //dd($this->jsonContent);
  174.         foreach ($contents as $singleContent) {
  175.             $html $html.$singleContent["html"];
  176.         }
  177.         
  178.         return $html;
  179.     }
  180.     public function jsonContentToHtml() {
  181.         $obj $this->jsonContent;
  182.         $html '';
  183.         //dd($this->jsonContent);
  184.         foreach ($obj["blocks"] as $block) {
  185.             switch ($block["type"]) {
  186.                 case 'paragraph':
  187.                     $html .= '<p>' $block["data"]["text"] . '</p>';
  188.                     break;
  189.                 
  190.                 case 'header':
  191.                     $html .= '<h'$block["data"]["level"] .'>' $block["data"]["text"] . '</h'$block["data"]["level"] .'>';
  192.                     break;
  193.                 case 'raw':
  194.                     $html .= $block["data"]["html"];
  195.                     break;
  196.                 case 'list':
  197.                     $lsType = ($block["data"]["style"] == 'ordered') ? 'ol' 'ul';
  198.                     $html .= '<' $lsType '>';
  199.                     foreach($block["data"]["items"] as $item) {
  200.                         $html .= '<li>' $item '</li>';
  201.                     }
  202.                     $html .= '</' $lsType '>';
  203.                     break;
  204.                 
  205.                 case 'code':
  206.                     $html .= '<pre><code class="language-'$block["data"]["lang"] .'">'$block["data"]["code"] .'</code></pre>';
  207.                     break;
  208.                 
  209.                 case 'image':
  210.                     $html .= '<div class="img_pnl"><img src="'$block["data"]["file"]["url"]->url .'" /></div>';
  211.                     break;
  212.                 
  213.                 default:
  214.                     break;
  215.             }
  216.         }
  217.         
  218.         return $html;
  219.     }
  220.     /**
  221.      * Get the value of isLiveEditor
  222.      */ 
  223.     public function getIsLiveEditor()
  224.     {
  225.         return $this->isLiveEditor;
  226.     }
  227.     /**
  228.      * Set the value of isLiveEditor
  229.      *
  230.      * @return  self
  231.      */ 
  232.     public function setIsLiveEditor($isLiveEditor)
  233.     {
  234.         $this->isLiveEditor $isLiveEditor;
  235.         return $this;
  236.     }
  237.     /**
  238.      * Get the value of pageEditor
  239.      */ 
  240.     public function getPageEditor()
  241.     {
  242.         return $this->pageEditor;
  243.     }
  244.     /**
  245.      * Set the value of pageEditor
  246.      *
  247.      * @return  self
  248.      */ 
  249.     public function setPageEditor($pageEditor)
  250.     {
  251.         $this->pageEditor $pageEditor;
  252.         return $this;
  253.     }
  254.     /**
  255.      * Get the value of jsonSimplifiedContent
  256.      */ 
  257.     public function getJsonSimplifiedContent()
  258.     {
  259.         return $this->jsonSimplifiedContent;
  260.     }
  261.     /**
  262.      * Set the value of jsonSimplifiedContent
  263.      *
  264.      * @return  self
  265.      */ 
  266.     public function setJsonSimplifiedContent($jsonSimplifiedContent)
  267.     {
  268.         $this->jsonSimplifiedContent $jsonSimplifiedContent;
  269.         return $this;
  270.     }
  271.     public function getDescription(): ?string
  272.     {
  273.         return $this->description;
  274.     }
  275.     public function setDescription(?string $description): self
  276.     {
  277.         $this->description $description;
  278.         return $this;
  279.     }
  280.     /**
  281.      * Get the value of type
  282.      */ 
  283.     public function getType()
  284.     {
  285.         return $this->type;
  286.     }
  287.     /**
  288.      * Set the value of type
  289.      *
  290.      * @return  self
  291.      */ 
  292.     public function setType($type)
  293.     {
  294.         $this->type $type;
  295.         return $this;
  296.     }
  297. }