src/Entity/Article.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ArticleRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6. * @ORM\Entity(repositoryClass=ArticleRepository::class)
  7. */
  8. class Article
  9. {
  10. /**
  11. * @ORM\Id
  12. * @ORM\GeneratedValue
  13. * @ORM\Column(type="integer")
  14. */
  15. private $id;
  16. /**
  17. * @ORM\Column(type="string", length=255)
  18. */
  19. private $titre;
  20. /**
  21. * @ORM\Column(type="string", length=100000)
  22. */
  23. private $contenu;
  24. /**
  25. * @ORM\Column(type="string", length=255,nullable=true)
  26. */
  27. private $image;
  28. /**
  29. * @ORM\Column(type="datetime")
  30. */
  31. private $date;
  32. /**
  33. * @ORM\Column(type="string", length=255, nullable=true)
  34. */
  35. private $altDescription;
  36. public function getId(): ?int
  37. {
  38. return $this->id;
  39. }
  40. public function getTitre(): ?string
  41. {
  42. return $this->titre;
  43. }
  44. public function setTitre(string $titre): self
  45. {
  46. $this->titre = $titre;
  47. return $this;
  48. }
  49. public function getContenu(): ?string
  50. {
  51. return $this->contenu;
  52. }
  53. public function setContenu(string $contenu): self
  54. {
  55. $this->contenu = $contenu;
  56. return $this;
  57. }
  58. public function getImage(): ?string
  59. {
  60. return $this->image;
  61. }
  62. public function setImage(?string $image): self
  63. {
  64. $this->image = $image;
  65. return $this;
  66. }
  67. public function getDate(): ?\DateTimeInterface
  68. {
  69. return $this->date;
  70. }
  71. public function setDate(\DateTimeInterface $date): self
  72. {
  73. $this->date = $date;
  74. return $this;
  75. }
  76. public function getDisplayContent(){
  77. $pattern = '/h1/i';
  78. $replacement = 'h2';
  79. $contenu = preg_replace($pattern, $replacement, $this->contenu);
  80. $pattern = '/<figure.*?>.*?<\/figure>/i';
  81. $replacement = '';
  82. $contenu = preg_replace($pattern, $replacement, $contenu);
  83. return $contenu;
  84. }
  85. public function getAltDescription(): ?string
  86. {
  87. return $this->altDescription;
  88. }
  89. public function setAltDescription(?string $altDescription): self
  90. {
  91. $this->altDescription = $altDescription;
  92. return $this;
  93. }
  94. public function getAbsoluteImage() : ?string
  95. {
  96. if(!empty($this->image)){
  97. return sprintf("https://%s/images/upload/%s",$_SERVER['HTTP_HOST'],$this->image);
  98. }
  99. return null;
  100. }
  101. }