src/Entity/Content/Material.php line 17

  1. <?php
  2. namespace App\Entity\Content;
  3. use App\Entity\Common\Owner;
  4. use App\Entity\Traits\TrackerFields;
  5. use App\Entity\Traits\UserCreatedInterface;
  6. use App\Entity\Traits\UserUpdatedInterface;
  7. use App\Model\Common\HaveOwnerInterface;
  8. use App\Model\Translation\TranslatableTrait;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  11. #[ORM\Table(name'material')]
  12. #[ORM\Entity(repositoryClass\App\Repository\Content\MaterialRepository::class)]
  13. #[ORM\HasLifecycleCallbacks]
  14. class Material implements HaveOwnerInterfaceUserCreatedInterfaceUserUpdatedInterfaceTranslatableInterface
  15. {
  16.     use TrackerFields;
  17.     use TranslatableTrait;
  18.     public const TYPE_FILE 'file';
  19.     public const TYPE_LINK 'link';
  20.     public const TYPE_VIDEO 'video';
  21.     #[ORM\Id]
  22.     #[ORM\GeneratedValue(strategy'AUTO')]
  23.     #[ORM\Column(type'integer')]
  24.     private ?int $id null;
  25.     #[ORM\Embedded(class: \App\Entity\Common\Owner::class)]
  26.     private ?Owner $owner null;
  27.     #[ORM\Column(type'string')]
  28.     private ?string $type null;
  29.     #[ORM\Column(type'string'nullabletrue)]
  30.     private ?string $category null;
  31.     #[ORM\Column(type'json')]
  32.     private array $data = [];
  33.     #[ORM\Column(type'string'nullabletrue)]
  34.     private ?string $caption null;
  35.     #[ORM\Column(type'integer')]
  36.     private int $weight 1;
  37.     #[ORM\Column(type'boolean')]
  38.     private bool $published true;
  39.     public static function getTypes(): array
  40.     {
  41.         return [
  42.             self::TYPE_FILE,
  43.             self::TYPE_LINK,
  44.             self::TYPE_VIDEO,
  45.         ];
  46.     }
  47.     /**
  48.      * @return int
  49.      */
  50.     public function getWeight(): int
  51.     {
  52.         return $this->weight;
  53.     }
  54.     /**
  55.      * @param int $weight
  56.      */
  57.     public function setWeight(int $weight): void
  58.     {
  59.         $this->weight $weight;
  60.     }
  61.     public function getOwner(): Owner
  62.     {
  63.         return $this->owner;
  64.     }
  65.     /**
  66.      * @param Owner $owner
  67.      */
  68.     public function setOwner(Owner $owner): void
  69.     {
  70.         $this->owner $owner;
  71.     }
  72.     /**
  73.      * @return mixed
  74.      */
  75.     public function getId()
  76.     {
  77.         return $this->id;
  78.     }
  79.     /**
  80.      * @param mixed $id
  81.      */
  82.     public function setId($id): void
  83.     {
  84.         $this->id $id;
  85.     }
  86.     /**
  87.      * @return string
  88.      */
  89.     public function getType(): ?string
  90.     {
  91.         return $this->type;
  92.     }
  93.     /**
  94.      * @param string $type
  95.      */
  96.     public function setType(string $type): void
  97.     {
  98.         $this->type $type;
  99.     }
  100.     /**
  101.      * @return array
  102.      */
  103.     public function getData(): array
  104.     {
  105.         return $this->data;
  106.     }
  107.     /**
  108.      * @param array $data
  109.      */
  110.     public function setData(array $data): void
  111.     {
  112.         $this->data $data;
  113.     }
  114.     /**
  115.      * @return bool
  116.      */
  117.     public function isPublished(): bool
  118.     {
  119.         return $this->published;
  120.     }
  121.     /**
  122.      * @param bool $published
  123.      */
  124.     public function setPublished(bool $published): void
  125.     {
  126.         $this->published $published;
  127.     }
  128.     public function isFilled(): bool
  129.     {
  130.         switch ($this->type) {
  131.             case self::TYPE_FILE:
  132.                 return !empty($this->data['file']) ? true false;
  133.             case self::TYPE_VIDEO:
  134.             case self::TYPE_LINK:
  135.                 return !empty($this->data['url']) ? true false;
  136.         }
  137.         return false;
  138.     }
  139.     /**
  140.      * @return string
  141.      */
  142.     public function getCategory(): ?string
  143.     {
  144.         return $this->category;
  145.     }
  146.     /**
  147.      * @param string $category
  148.      */
  149.     public function setCategory(?string $category): void
  150.     {
  151.         $this->category $category;
  152.     }
  153. }