src/Hitso/Bundle/ContentBundle/Entity/Elements/Element.php line 162

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Hitso\Bundle\ContentBundle\Entity\Elements;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\Common\Inflector\Inflector;
  6. use Gedmo\SoftDeleteable\Traits\SoftDeleteable as SoftDeleteableTrait;
  7. use Hitso\Bundle\CommonBundle\Doctrine\Behaviours\Identifiable;
  8. use Hitso\Bundle\CommonBundle\Doctrine\Behaviours\SoftDeleteInterface;
  9. use Hitso\Bundle\CommonBundle\Doctrine\Behaviours\VersionInterface;
  10. use Hitso\Bundle\CommonBundle\Doctrine\Behaviours\VersionTrait;
  11. use Hitso\Bundle\CommonBundle\Doctrine\Manager\EventResourceNameInterface;
  12. use Hitso\Bundle\CommonBundle\Entity\EntityInterface;
  13. use Hitso\Bundle\CommonBundle\Interfaces\Timestampable;
  14. use Hitso\Bundle\CommonBundle\Traits\TimestampableTrait;
  15. use Hitso\Bundle\ContentBundle\Entity\Content;
  16. use Hitso\Bundle\FileManagerBundle\Entity\File;
  17. use Hitso\Bundle\FormBundle\Storage\FileCollection;
  18. use Symfony\Component\PropertyAccess\PropertyAccess;
  19. use TheCodingMachine\GraphQLite\Annotations\Field;
  20. use TheCodingMachine\GraphQLite\Annotations\Type;
  21. /**
  22.  * Class Element
  23.  *
  24.  * @package Hitso\Bundle\ContentBundle\Entity\Elements
  25.  * @Type()
  26.  */
  27. abstract class Element implements
  28.     EntityInterface,
  29.     ElementInterface,
  30.     VersionInterface,
  31.     SoftDeleteInterface,
  32.     EventResourceNameInterface,
  33.     Timestampable
  34. {
  35.     use Identifiable;
  36.     use VersionTrait;
  37.     use SoftDeleteableTrait;
  38.     use TimestampableTrait;
  39.     /**
  40.      * @var Content
  41.      */
  42.     protected $content;
  43.     /**
  44.      * @var int
  45.      */
  46.     protected $order 0;
  47.     /**
  48.      * @var string
  49.      */
  50.     protected $caption;
  51.     /**
  52.      * @var bool
  53.      */
  54.     protected $deleted false;
  55.     public function __clone()
  56.     {
  57.         $this->id      null;
  58.         $this->version 0;
  59.     }
  60.     /**
  61.      * @Field()
  62.      * @return Content
  63.      */
  64.     public function getContent(): ?Content
  65.     {
  66.         return $this->content;
  67.     }
  68.     /**
  69.      * @Field(outputType="ContentElementRaw")
  70.      */
  71.     public function getRaw(): self
  72.     {
  73.         return $this;
  74.     }
  75.     /**
  76.      * @Field(outputType="ContentElementRendered")
  77.      */
  78.     public function getRendered(): self
  79.     {
  80.         return $this;
  81.     }
  82.     /**
  83.      * @param Content|null $content
  84.      *
  85.      * @return $this
  86.      */
  87.     public function setContent(?Content $content): self
  88.     {
  89.         $this->content $content;
  90.         return $this;
  91.     }
  92.     /**
  93.      * @Field()
  94.      */
  95.     public function getOrder(): int
  96.     {
  97.         return $this->order;
  98.     }
  99.     /**
  100.      * @param int $order
  101.      *
  102.      * @return Element
  103.      */
  104.     public function setOrder(int $order): self
  105.     {
  106.         $this->order $order;
  107.         return $this;
  108.     }
  109.     /**
  110.      * @Field()
  111.      */
  112.     public function getCaption(): ?string
  113.     {
  114.         return $this->caption;
  115.     }
  116.     public function setCaption(?string $caption): self
  117.     {
  118.         $this->caption $caption;
  119.         return $this;
  120.     }
  121.     /**
  122.      * @Field()
  123.      */
  124.     public function isDeleted(): bool
  125.     {
  126.         return $this->deleted;
  127.     }
  128.     public function setDeleted(bool $deleted): self
  129.     {
  130.         $this->deleted $deleted;
  131.         return $this;
  132.     }
  133.     /**
  134.      * @Field()
  135.      */
  136.     public static function getTypeName(): string
  137.     {
  138.         return Inflector::tableize((new \ReflectionClass(static::class))->getShortName());
  139.     }
  140.     /**
  141.      * @Field()
  142.      */
  143.     public function getEventResourceName(): string
  144.     {
  145.         return (new \ReflectionClass(Element::class))->getShortName();
  146.     }
  147.     /**
  148.      * @Field()
  149.      */
  150.     public function getSearchableContent(): ?string
  151.     {
  152.         return $this->caption;
  153.     }
  154.     /**
  155.      * @Field()
  156.      * @return File
  157.      */
  158.     public function getFile(): ?File
  159.     {
  160.         return null;
  161.     }
  162.     public function copyTo(Element $element): Element
  163.     {
  164.         $ref              = new \ReflectionObject($this);
  165.         $propertyAccessor PropertyAccess::createPropertyAccessor();
  166.         foreach ($ref->getProperties(\ReflectionProperty::IS_PROTECTED) as $property) {
  167.             $propName $property->getName();
  168.             if ($propertyAccessor->isWritable($element$propName)) {
  169.                 $propertyAccessor->setValue($element$propName$this->{$propName});
  170.             }
  171.         }
  172.         return $element;
  173.     }
  174. }