src/App/Entity/Feed/Entry/AbstractContentEntry.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Feed\Entry;
  3. use App\Entity\Content\AbstractDraft;
  4. use App\Entity\Content\AbstractObject;
  5. use App\Entity\Feed\AbstractEntry;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. /**
  9.  * @ORM\Entity(
  10.  *     repositoryClass = "App\Doctrine\Repository\Feed\Entry\ContentEntryRepository",
  11.  * )
  12.  */
  13. abstract class AbstractContentEntry extends AbstractEntry
  14. {
  15.     const DISCR 'content';
  16.     /**
  17.      * @var AbstractObject|null
  18.      *
  19.      * @ORM\OneToOne(
  20.      *     targetEntity = AbstractObject::class,
  21.      *     inversedBy = "entry",
  22.      * )
  23.      * @ORM\JoinColumn(
  24.      *     name = "object",
  25.      *     referencedColumnName = "id",
  26.      *     onDelete = "CASCADE",
  27.      * )
  28.      *
  29.      * @Groups({"object", "entry_object"})
  30.      */
  31.     protected ?AbstractObject $object null;
  32.     /**
  33.      * @var AbstractDraft|null
  34.      *
  35.      * @ORM\ManyToOne(
  36.      *     targetEntity = AbstractDraft::class,
  37.      * )
  38.      * @ORM\JoinColumn(
  39.      *     name = "draft",
  40.      *     referencedColumnName = "id",
  41.      *     onDelete = "CASCADE",
  42.      * )
  43.      */
  44.     protected ?AbstractDraft $draft null;
  45.     /**
  46.      * @return AbstractObject|null
  47.      */
  48.     public function getObject(): ?AbstractObject
  49.     {
  50.         return $this->object;
  51.     }
  52.     /**
  53.      * @param AbstractObject|null $object
  54.      * @return $this
  55.      */
  56.     public function setObject(?AbstractObject $object): self
  57.     {
  58.         $this->object $object;
  59.         return $this;
  60.     }
  61.     /**
  62.      * {@inheritDoc}
  63.      * @param AbstractObject $entity
  64.      */
  65.     public function populate($entity): self
  66.     {
  67.         // make sure we are a supported type
  68.         if ( ! $entity instanceof AbstractObject) {
  69.             throw new \LogicException();
  70.         }
  71.         // set the object
  72.         $this->setObject($entity);
  73.         // set the department
  74.         $this->setDepartment($entity->getDepartment());
  75.         // set the types
  76.         $this->setSchoolType($entity->getSchoolTypes());
  77.         // update basic cached fields
  78.         $this
  79.             ->setVisibility($entity->getVisibility())// this works right now because the options are the same
  80.             ->setTimestamp($entity->getTimestamp() ?: $entity->getCreatedAt())
  81.         ;
  82.         return $this;
  83.     }
  84.     /**
  85.      * @return string
  86.      *
  87.      * @Groups("entry")
  88.      */
  89.     abstract public function getType(): string;
  90. }