<?phpdeclare(strict_types=1);namespace Hitso\Bundle\ContentBundle\Entity\Elements;use Doctrine\Common\Collections\Collection;use Doctrine\Common\Inflector\Inflector;use Gedmo\SoftDeleteable\Traits\SoftDeleteable as SoftDeleteableTrait;use Hitso\Bundle\CommonBundle\Doctrine\Behaviours\Identifiable;use Hitso\Bundle\CommonBundle\Doctrine\Behaviours\SoftDeleteInterface;use Hitso\Bundle\CommonBundle\Doctrine\Behaviours\VersionInterface;use Hitso\Bundle\CommonBundle\Doctrine\Behaviours\VersionTrait;use Hitso\Bundle\CommonBundle\Doctrine\Manager\EventResourceNameInterface;use Hitso\Bundle\CommonBundle\Entity\EntityInterface;use Hitso\Bundle\CommonBundle\Interfaces\Timestampable;use Hitso\Bundle\CommonBundle\Traits\TimestampableTrait;use Hitso\Bundle\ContentBundle\Entity\Content;use Hitso\Bundle\FileManagerBundle\Entity\File;use Hitso\Bundle\FormBundle\Storage\FileCollection;use Symfony\Component\PropertyAccess\PropertyAccess;use TheCodingMachine\GraphQLite\Annotations\Field;use TheCodingMachine\GraphQLite\Annotations\Type;/** * Class Element * * @package Hitso\Bundle\ContentBundle\Entity\Elements * @Type() */abstract class Element implements EntityInterface, ElementInterface, VersionInterface, SoftDeleteInterface, EventResourceNameInterface, Timestampable{ use Identifiable; use VersionTrait; use SoftDeleteableTrait; use TimestampableTrait; /** * @var Content */ protected $content; /** * @var int */ protected $order = 0; /** * @var string */ protected $caption; /** * @var bool */ protected $deleted = false; public function __clone() { $this->id = null; $this->version = 0; } /** * @Field() * @return Content */ public function getContent(): ?Content { return $this->content; } /** * @Field(outputType="ContentElementRaw") */ public function getRaw(): self { return $this; } /** * @Field(outputType="ContentElementRendered") */ public function getRendered(): self { return $this; } /** * @param Content|null $content * * @return $this */ public function setContent(?Content $content): self { $this->content = $content; return $this; } /** * @Field() */ public function getOrder(): int { return $this->order; } /** * @param int $order * * @return Element */ public function setOrder(int $order): self { $this->order = $order; return $this; } /** * @Field() */ public function getCaption(): ?string { return $this->caption; } public function setCaption(?string $caption): self { $this->caption = $caption; return $this; } /** * @Field() */ public function isDeleted(): bool { return $this->deleted; } public function setDeleted(bool $deleted): self { $this->deleted = $deleted; return $this; } /** * @Field() */ public static function getTypeName(): string { return Inflector::tableize((new \ReflectionClass(static::class))->getShortName()); } /** * @Field() */ public function getEventResourceName(): string { return (new \ReflectionClass(Element::class))->getShortName(); } /** * @Field() */ public function getSearchableContent(): ?string { return $this->caption; } /** * @Field() * @return File */ public function getFile(): ?File { return null; } public function copyTo(Element $element): Element { $ref = new \ReflectionObject($this); $propertyAccessor = PropertyAccess::createPropertyAccessor(); foreach ($ref->getProperties(\ReflectionProperty::IS_PROTECTED) as $property) { $propName = $property->getName(); if ($propertyAccessor->isWritable($element, $propName)) { $propertyAccessor->setValue($element, $propName, $this->{$propName}); } } return $element; }}