src/Entity/BlogPostOrder.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BlogPostOrderRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6.  * Ordre contextualisé des contenus (BlogPost) :
  7.  * - par Organisation (Instance)
  8.  * - et par contexte :
  9.  *    - Domaine (D:<id>) => contenus dont blogPostCategory IS NULL
  10.  *    - Rubrique (C:<id>) => contenus d'une catégorie donnée
  11.  *
  12.  * @ORM\Entity(repositoryClass=BlogPostOrderRepository::class)
  13.  * @ORM\Table(
  14.  *     name="blog_post_order",
  15.  *     uniqueConstraints={
  16.  *         @ORM\UniqueConstraint(columns={"instance_id","context_key","blog_post_id"})
  17.  *     },
  18.  *     indexes={
  19.  *         @ORM\Index(columns={"instance_id","context_key","position"})
  20.  *     }
  21.  * )
  22.  */
  23. class BlogPostOrder
  24. {
  25.     /**
  26.      * @ORM\Id
  27.      * @ORM\GeneratedValue
  28.      * @ORM\Column(type="integer")
  29.      */
  30.     private ?int $id null;
  31.     /**
  32.      * @ORM\ManyToOne(targetEntity=Instance::class)
  33.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  34.      */
  35.     private ?Instance $instance null;
  36.     /**
  37.      * Exemple : "D:12" ou "C:34"
  38.      * @ORM\Column(type="string", length=32)
  39.      */
  40.     private string $contextKey '';
  41.     /**
  42.      * Rempli si contexte domaine
  43.      * @ORM\ManyToOne(targetEntity=Domain::class)
  44.      * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  45.      */
  46.     private ?Domain $domain null;
  47.     /**
  48.      * Rempli si contexte rubrique
  49.      * @ORM\ManyToOne(targetEntity=BlogPostCategory::class)
  50.      * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  51.      */
  52.     private ?BlogPostCategory $category null;
  53.     /**
  54.      * @ORM\ManyToOne(targetEntity=BlogPost::class)
  55.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  56.      */
  57.     private ?BlogPost $blogPost null;
  58.     /**
  59.      * @ORM\Column(type="integer")
  60.      */
  61.     private int $position 0;
  62.     public function getId(): ?int
  63.     {
  64.         return $this->id;
  65.     }
  66.     public function getInstance(): ?Instance
  67.     {
  68.         return $this->instance;
  69.     }
  70.     public function setInstance(?Instance $instance): self
  71.     {
  72.         $this->instance $instance;
  73.         return $this;
  74.     }
  75.     public function getContextKey(): string
  76.     {
  77.         return $this->contextKey;
  78.     }
  79.     public function setContextKey(string $contextKey): self
  80.     {
  81.         $this->contextKey $contextKey;
  82.         return $this;
  83.     }
  84.     public function getDomain(): ?Domain
  85.     {
  86.         return $this->domain;
  87.     }
  88.     public function setDomain(?Domain $domain): self
  89.     {
  90.         $this->domain $domain;
  91.         return $this;
  92.     }
  93.     public function getCategory(): ?BlogPostCategory
  94.     {
  95.         return $this->category;
  96.     }
  97.     public function setCategory(?BlogPostCategory $category): self
  98.     {
  99.         $this->category $category;
  100.         return $this;
  101.     }
  102.     public function getBlogPost(): ?BlogPost
  103.     {
  104.         return $this->blogPost;
  105.     }
  106.     public function setBlogPost(?BlogPost $blogPost): self
  107.     {
  108.         $this->blogPost $blogPost;
  109.         return $this;
  110.     }
  111.     public function getPosition(): int
  112.     {
  113.         return (int) $this->position;
  114.     }
  115.     public function setPosition(int $position): self
  116.     {
  117.         $this->position $position;
  118.         return $this;
  119.     }
  120.     public function __toString(): string
  121.     {
  122.         $label $this->blogPost?->getTitle() ?? 'Contenu';
  123.         return sprintf('[%s] %s'$this->contextKey$label);
  124.     }
  125. }