src/Entity/Content/News.php line 30
<?php
/**
* Created by PhpStorm.
* User: Михаил
* Date: 21.12.2018
* Time: 11:20
*/
namespace App\Entity\Content;
use App\Entity\Common\DateInterval;
use App\Entity\Common\File;
use App\Entity\Common\Owner;
use App\Entity\Traits\TrackerFields;
use App\Entity\Traits\UserCreatedInterface;
use App\Entity\Traits\UserUpdatedInterface;
use App\Entity\User\User;
use App\Entity\UUID\HaveUuidInterface;
use App\Entity\UUID\UuidTrait;
use App\Model\Common\HaveOwnerInterface;
use App\Model\Translation\TranslatableTrait;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
#[ORM\Table(name: 'news')]
#[ORM\Index(name: 'idx_active', columns: ['published', 'pinned', 'publish_at'])]
#[ORM\Index(name: 'idx_deleted', columns: ['deleted'])]
#[ORM\Entity(repositoryClass: \App\Repository\Content\NewsRepository::class)]
#[ORM\HasLifecycleCallbacks]
class News implements UserCreatedInterface, UserUpdatedInterface, HaveOwnerInterface, HaveUuidInterface, TranslatableInterface
{
use TrackerFields;
use UuidTrait;
use TranslatableTrait;
public const SITE_PER_PAGE = 10;
public const ADMIN_PER_PAGE = 20;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', nullable: true)]
private $caption;
#[ORM\Column(type: 'string', length: 250, nullable: true)]
private $subtitle;
#[ORM\Column(type: 'text', nullable: true)]
private $preview;
/**
* @var File|null
*/
#[ORM\ManyToOne(targetEntity: 'App\Entity\Common\File', cascade: ['remove', 'persist'])]
private $image;
#[ORM\Column(type: 'text', nullable: true)]
private $text;
/**
* @var \App\Entity\Content\NewsType
*/
#[ORM\ManyToOne(targetEntity: 'App\Entity\Content\NewsType', inversedBy: 'news')]
#[ORM\JoinColumn(nullable: false)]
private $type;
/**
* @var Owner
*/
#[ORM\Embedded(class: 'App\Entity\Common\Owner')]
private $owner;
/**
* @var DateInterval
*/
#[ORM\Embedded(class: 'App\Entity\Common\DateInterval')]
private $interval;
/**
* @var bool
*/
#[ORM\Column(type: 'boolean')]
private $published = true;
#[ORM\Column(type: 'datetime', nullable: true)]
private $publish_at;
/**
* @var bool
*/
#[ORM\Column(type: 'boolean')]
private $pinned = false;
public function __construct()
{
$this->owner = new Owner();
$this->publish_at = new \DateTime();
$this->interval = new \App\Entity\Common\DateInterval();
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
*/
public function setId($id): void
{
$this->id = $id;
}
/**
* @return bool
*/
public function isPublished(): bool
{
return $this->published;
}
/**
* @param bool $published
*/
public function setPublished(bool $published): void
{
$this->published = $published;
}
/**
* @return mixed
*/
public function getPublishAt()
{
return $this->publish_at;
}
/**
* @param mixed $publish_at
*/
public function setPublishAt($publish_at): void
{
$this->publish_at = $publish_at;
}
/**
* @return bool
*/
public function isPinned(): bool
{
return $this->pinned;
}
/**
* @param bool $pinned
*/
public function setPinned(bool $pinned): void
{
$this->pinned = $pinned;
}
/**
* @return User
*/
public function getCreatedBy(): ?User
{
return $this->created_by;
}
public function setCreatedBy(?User $user)
{
$this->created_by = $user;
}
/**
* @return User
*/
public function getUpdatedBy(): ?User
{
return $this->updated_by;
}
public function setUpdatedBy(?User $user)
{
$this->updated_by = $user;
}
public function getTypeString(): string
{
return $this->getType()->getType();
}
/**
* @return \App\Entity\Content\NewsType
*/
public function getType(): ?\App\Entity\Content\NewsType
{
return $this->type;
}
/**
* @param mixed $type
*/
public function setType($type): void
{
$this->type = $type;
}
/**
* @return Owner
*/
public function getOwner(): Owner
{
return $this->owner;
}
/**
* @param Owner $owner
*/
public function setOwner(Owner $owner): void
{
$this->owner = $owner;
}
/**
* @return DateInterval
*/
public function getInterval(): ?DateInterval
{
return $this->interval;
}
/**
* @param DateInterval $interval
*/
public function setInterval(DateInterval $interval): void
{
$this->interval = $interval;
}
/**
* @return File|null
*/
public function getImage(): ?File
{
return $this->image;
}
/**
* @param File|null $image
*/
public function setImage(?File $image): void
{
$this->image = $image;
}
/**
* @return bool
* @noinspection PhpUnused
*/
public function isIndexable(): bool
{
return false === $this->deleted;
}
public function isActive(): bool
{
return $this->isPublished();
}
}