src/CmsBundle/Entity/Preset.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\CmsBundle\Entity;
  3. use App\CmsBundle\Enum\LogActionEnum;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * Preset
  9.  *
  10.  * @ORM\Table(name="preset")
  11.  * @ORM\Entity(repositoryClass="App\CmsBundle\Repository\PresetRepository")
  12.  */
  13. class Preset
  14. {
  15.     use LogTrait;
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\Column(type="integer", options={"unsigned":true})
  19.      * @ORM\GeneratedValue(strategy="AUTO")
  20.      */
  21.     protected ?int $id null;
  22.     /**
  23.      * @ORM\Column(name="handler", type="string", length=1000)
  24.      */
  25.     private string $handler;
  26.     /**
  27.      * @ORM\Column(name="title", type="string", length=1000)
  28.      */
  29.     private string $title;
  30.     /**
  31.      * @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\Widget", mappedBy="preset")
  32.      */
  33.     protected Collection $widgets;
  34.     /**
  35.      * @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\WidgetParameter", mappedBy="preset", cascade={"persist","remove"})
  36.      * @ORM\JoinColumn(nullable=true)
  37.      */
  38.     private Collection $widgetParameters;
  39.     public function __construct()
  40.     {
  41.         $this->widgets = new ArrayCollection();
  42.         $this->widgetParameters = new ArrayCollection();
  43.     }
  44.     /**
  45.      * @return int|null
  46.      */
  47.     public function getId(): ?int
  48.     {
  49.         return $this->id;
  50.     }
  51.     /**
  52.      * @param int $id
  53.      * @return void
  54.      */
  55.     public function setId(int $id): void
  56.     {
  57.         $this->id $id;
  58.     }
  59.     /**
  60.      * @return Site
  61.      */
  62.     public function getSite(): Site
  63.     {
  64.         return $this->site;
  65.     }
  66.     /**
  67.      * @param Site $site
  68.      * @return $this
  69.      */
  70.     public function setSite(Site $site): self
  71.     {
  72.         $this->site $site;
  73.         return $this;
  74.     }
  75.     /**
  76.      * @return string
  77.      */
  78.     public function getHandler(): string
  79.     {
  80.         return $this->handler;
  81.     }
  82.     /**
  83.      * @param string $handler
  84.      * @return Preset
  85.      */
  86.     public function setHandler(string $handler): self
  87.     {
  88.         $this->handler $handler;
  89.         return $this;
  90.     }
  91.     /**
  92.      * @return string
  93.      */
  94.     public function getTitle(): string
  95.     {
  96.         return $this->title;
  97.     }
  98.     /**
  99.      * @param string $title
  100.      * @return Preset
  101.      */
  102.     public function setTitle(string $title): self
  103.     {
  104.         $this->title $title;
  105.         return $this;
  106.     }
  107.     /**
  108.      * @return Collection
  109.      */
  110.     public function getWidgetParameters(): Collection
  111.     {
  112.         return $this->widgetParameters;
  113.     }
  114.     public function getWidgets(): Collection
  115.     {
  116.         return $this->widgets;
  117.     }
  118.     /**
  119.      * @param WidgetParameter $widgetParameter
  120.      * @return $this
  121.      */
  122.     public function addWidgetParameter(WidgetParameter $widgetParameter): self
  123.     {
  124.         if (!$this->widgetParameters->contains($widgetParameter)) {
  125.             $this->addCollectionLog(
  126.                 LogActionEnum::ADD,
  127.                 'widgetParameter',
  128.                 (object)[
  129.                     'name'  => $widgetParameter->getName(),
  130.                     'value' => $widgetParameter->getValue()
  131.                 ]
  132.             );
  133.             $widgetParameter->setPreset($this);
  134.             $this->widgetParameters[] = $widgetParameter;
  135.         }
  136.         return $this;
  137.     }
  138.     /**
  139.      * @param WidgetParameter $widgetParameter
  140.      * @return $this
  141.      */
  142.     public function removeWidgetParameter(WidgetParameter $widgetParameter): self
  143.     {
  144.         if ($this->widgetParameters->removeElement($widgetParameter)) {
  145.             $this->addCollectionLog(
  146.                 LogActionEnum::REMOVE,
  147.                 'widgetParameter',
  148.                 (object)[
  149.                     'name'  => $widgetParameter->getName(),
  150.                     'value' => $widgetParameter->getValue()
  151.                 ]
  152.             );
  153.             if ($widgetParameter->getPreset() === $this) {
  154.                 $widgetParameter->setPreset(null);
  155.             }
  156.         }
  157.         return $this;
  158.     }
  159.     /**
  160.      * @param $action
  161.      * @param $property
  162.      * @param object $value
  163.      * @return $this
  164.      */
  165.     public function addCollectionLog($action$propertyobject $value): self
  166.     {
  167.         if (LogActionEnum::exists($action)) {
  168.             $log json_decode($this->log ?? '[]'true);
  169.             $log[$property][$action][] = $value;
  170.             $this->log json_encode($log);
  171.         }
  172.         return $this;
  173.     }
  174. }