<?php
namespace App\Entity\Feed\Entry;
use App\Entity\Content\AbstractDraft;
use App\Entity\Content\AbstractObject;
use App\Entity\Feed\AbstractEntry;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(
* repositoryClass = "App\Doctrine\Repository\Feed\Entry\ContentEntryRepository",
* )
*/
abstract class AbstractContentEntry extends AbstractEntry
{
const DISCR = 'content';
/**
* @var AbstractObject|null
*
* @ORM\OneToOne(
* targetEntity = AbstractObject::class,
* inversedBy = "entry",
* )
* @ORM\JoinColumn(
* name = "object",
* referencedColumnName = "id",
* onDelete = "CASCADE",
* )
*
* @Groups({"object", "entry_object"})
*/
protected ?AbstractObject $object = null;
/**
* @var AbstractDraft|null
*
* @ORM\ManyToOne(
* targetEntity = AbstractDraft::class,
* )
* @ORM\JoinColumn(
* name = "draft",
* referencedColumnName = "id",
* onDelete = "CASCADE",
* )
*/
protected ?AbstractDraft $draft = null;
/**
* @return AbstractObject|null
*/
public function getObject(): ?AbstractObject
{
return $this->object;
}
/**
* @param AbstractObject|null $object
* @return $this
*/
public function setObject(?AbstractObject $object): self
{
$this->object = $object;
return $this;
}
/**
* {@inheritDoc}
* @param AbstractObject $entity
*/
public function populate($entity): self
{
// make sure we are a supported type
if ( ! $entity instanceof AbstractObject) {
throw new \LogicException();
}
// set the object
$this->setObject($entity);
// set the department
$this->setDepartment($entity->getDepartment());
// set the types
$this->setSchoolType($entity->getSchoolTypes());
// update basic cached fields
$this
->setVisibility($entity->getVisibility())// this works right now because the options are the same
->setTimestamp($entity->getTimestamp() ?: $entity->getCreatedAt())
;
return $this;
}
/**
* @return string
*
* @Groups("entry")
*/
abstract public function getType(): string;
}