<?php
namespace App\Entity;
use App\Repository\BlogPostOrderRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* Ordre contextualisé des contenus (BlogPost) :
* - par Organisation (Instance)
* - et par contexte :
* - Domaine (D:<id>) => contenus dont blogPostCategory IS NULL
* - Rubrique (C:<id>) => contenus d'une catégorie donnée
*
* @ORM\Entity(repositoryClass=BlogPostOrderRepository::class)
* @ORM\Table(
* name="blog_post_order",
* uniqueConstraints={
* @ORM\UniqueConstraint(columns={"instance_id","context_key","blog_post_id"})
* },
* indexes={
* @ORM\Index(columns={"instance_id","context_key","position"})
* }
* )
*/
class BlogPostOrder
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @ORM\ManyToOne(targetEntity=Instance::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*/
private ?Instance $instance = null;
/**
* Exemple : "D:12" ou "C:34"
* @ORM\Column(type="string", length=32)
*/
private string $contextKey = '';
/**
* Rempli si contexte domaine
* @ORM\ManyToOne(targetEntity=Domain::class)
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
private ?Domain $domain = null;
/**
* Rempli si contexte rubrique
* @ORM\ManyToOne(targetEntity=BlogPostCategory::class)
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
private ?BlogPostCategory $category = null;
/**
* @ORM\ManyToOne(targetEntity=BlogPost::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*/
private ?BlogPost $blogPost = null;
/**
* @ORM\Column(type="integer")
*/
private int $position = 0;
public function getId(): ?int
{
return $this->id;
}
public function getInstance(): ?Instance
{
return $this->instance;
}
public function setInstance(?Instance $instance): self
{
$this->instance = $instance;
return $this;
}
public function getContextKey(): string
{
return $this->contextKey;
}
public function setContextKey(string $contextKey): self
{
$this->contextKey = $contextKey;
return $this;
}
public function getDomain(): ?Domain
{
return $this->domain;
}
public function setDomain(?Domain $domain): self
{
$this->domain = $domain;
return $this;
}
public function getCategory(): ?BlogPostCategory
{
return $this->category;
}
public function setCategory(?BlogPostCategory $category): self
{
$this->category = $category;
return $this;
}
public function getBlogPost(): ?BlogPost
{
return $this->blogPost;
}
public function setBlogPost(?BlogPost $blogPost): self
{
$this->blogPost = $blogPost;
return $this;
}
public function getPosition(): int
{
return (int) $this->position;
}
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
public function __toString(): string
{
$label = $this->blogPost?->getTitle() ?? 'Contenu';
return sprintf('[%s] %s', $this->contextKey, $label);
}
}