src/Entity/Content/Material.php line 17
<?php
namespace App\Entity\Content;
use App\Entity\Common\Owner;
use App\Entity\Traits\TrackerFields;
use App\Entity\Traits\UserCreatedInterface;
use App\Entity\Traits\UserUpdatedInterface;
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: 'material')]
#[ORM\Entity(repositoryClass: \App\Repository\Content\MaterialRepository::class)]
#[ORM\HasLifecycleCallbacks]
class Material implements HaveOwnerInterface, UserCreatedInterface, UserUpdatedInterface, TranslatableInterface
{
use TrackerFields;
use TranslatableTrait;
public const TYPE_FILE = 'file';
public const TYPE_LINK = 'link';
public const TYPE_VIDEO = 'video';
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Embedded(class: \App\Entity\Common\Owner::class)]
private ?Owner $owner = null;
#[ORM\Column(type: 'string')]
private ?string $type = null;
#[ORM\Column(type: 'string', nullable: true)]
private ?string $category = null;
#[ORM\Column(type: 'json')]
private array $data = [];
#[ORM\Column(type: 'string', nullable: true)]
private ?string $caption = null;
#[ORM\Column(type: 'integer')]
private int $weight = 1;
#[ORM\Column(type: 'boolean')]
private bool $published = true;
public static function getTypes(): array
{
return [
self::TYPE_FILE,
self::TYPE_LINK,
self::TYPE_VIDEO,
];
}
/**
* @return int
*/
public function getWeight(): int
{
return $this->weight;
}
/**
* @param int $weight
*/
public function setWeight(int $weight): void
{
$this->weight = $weight;
}
public function getOwner(): Owner
{
return $this->owner;
}
/**
* @param Owner $owner
*/
public function setOwner(Owner $owner): void
{
$this->owner = $owner;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
*/
public function setId($id): void
{
$this->id = $id;
}
/**
* @return string
*/
public function getType(): ?string
{
return $this->type;
}
/**
* @param string $type
*/
public function setType(string $type): void
{
$this->type = $type;
}
/**
* @return array
*/
public function getData(): array
{
return $this->data;
}
/**
* @param array $data
*/
public function setData(array $data): void
{
$this->data = $data;
}
/**
* @return bool
*/
public function isPublished(): bool
{
return $this->published;
}
/**
* @param bool $published
*/
public function setPublished(bool $published): void
{
$this->published = $published;
}
public function isFilled(): bool
{
switch ($this->type) {
case self::TYPE_FILE:
return !empty($this->data['file']) ? true : false;
case self::TYPE_VIDEO:
case self::TYPE_LINK:
return !empty($this->data['url']) ? true : false;
}
return false;
}
/**
* @return string
*/
public function getCategory(): ?string
{
return $this->category;
}
/**
* @param string $category
*/
public function setCategory(?string $category): void
{
$this->category = $category;
}
}