Passed
Push — master ( 546f84...80d964 )
by Dev
04:01
created

PageTrait::setMainContentIsMarkdown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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