1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PiedWeb\CMSBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Cocur\Slugify\Slugify; |
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
7
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
8
|
|
|
|
9
|
|
|
trait PageTrait |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @ORM\Column(type="string", length=150) |
13
|
|
|
* @Assert\NotBlank |
14
|
|
|
*/ |
15
|
|
|
protected $slug; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @ORM\Column(type="string", length=200, nullable=true) |
19
|
|
|
*/ |
20
|
|
|
protected $title; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @ORM\Column(type="text", nullable=true) |
24
|
|
|
*/ |
25
|
|
|
protected $mainContent; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @ORM\Column(type="datetime") |
29
|
|
|
*/ |
30
|
|
|
protected $createdAt; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @ORM\Column(type="datetime") |
34
|
|
|
*/ |
35
|
|
|
protected $updatedAt; |
36
|
|
|
|
37
|
|
|
public function __toString() |
38
|
|
|
{ |
39
|
|
|
return trim($this->host.'/'.$this->slug.' '); |
40
|
|
|
} |
41
|
|
|
|
42
|
3 |
|
public function __constructPage() |
43
|
|
|
{ |
44
|
3 |
|
$this->updatedAt = null !== $this->updatedAt ? $this->updatedAt : new \DateTime(); |
45
|
3 |
|
$this->createdAt = null !== $this->createdAt ? $this->createdAt : new \DateTime(); |
46
|
3 |
|
} |
47
|
|
|
|
48
|
|
|
public function getSlug(): ?string |
49
|
|
|
{ |
50
|
|
|
return $this->slug; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getRealSlug(): ?string |
54
|
|
|
{ |
55
|
|
|
if ('homepage' == $this->slug) { |
56
|
|
|
return ''; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $this->slug; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function setSlug($slug, $set = false): self |
63
|
|
|
{ |
64
|
|
|
if (true === $set) { |
65
|
|
|
$this->slug = $slug; |
66
|
|
|
} elseif (null === $slug) { // work around for disabled input in sonata admin |
67
|
|
|
if (null === $this->slug) { |
68
|
|
|
throw new \ErrorException('slug cant be null'); |
69
|
|
|
} |
70
|
|
|
} else { |
71
|
|
|
$slg = new Slugify(['regexp' => '/[^A-Za-z0-9\/]+/']); |
72
|
|
|
$slug = $slg->slugify($slug); |
73
|
|
|
$slug = trim($slug, '/'); |
74
|
|
|
$this->slug = $slug; //$this->setSlug(trim($slug, '/'), true); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
3 |
|
public function getTitle(): ?string |
81
|
|
|
{ |
82
|
3 |
|
return $this->title; |
83
|
|
|
} |
84
|
|
|
|
85
|
3 |
|
public function setTitle(?string $title): self |
86
|
|
|
{ |
87
|
3 |
|
$this->title = $title; |
88
|
|
|
|
89
|
3 |
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function getMainContent(): ?string |
93
|
|
|
{ |
94
|
|
|
return $this->mainContent; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function setMainContent(?string $mainContent): self |
98
|
|
|
{ |
99
|
|
|
$this->mainContent = $mainContent; |
100
|
|
|
|
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function getCreatedAt(): ?\DateTimeInterface |
105
|
|
|
{ |
106
|
|
|
return $this->createdAt; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function setCreatedAt(\DateTimeInterface $createdAt): self |
110
|
|
|
{ |
111
|
|
|
$this->createdAt = $createdAt; |
112
|
|
|
|
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function getUpdatedAt(): ?\DateTimeInterface |
117
|
|
|
{ |
118
|
|
|
return $this->updatedAt; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function setUpdatedAt(\DateTimeInterface $updatedAt): self |
122
|
|
|
{ |
123
|
|
|
$this->updatedAt = $updatedAt; |
124
|
|
|
|
125
|
|
|
return $this; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|