|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Albert221\Blog\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime; |
|
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @Entity(repositoryClass="\Albert221\Blog\Repository\Database\PostRepository") |
|
10
|
|
|
* @Table(name="posts", indexes={ |
|
11
|
|
|
* @Index(columns={"title"}, flags={"fulltext"}), |
|
12
|
|
|
* @Index(columns={"title","content"}, flags={"fulltext"}) |
|
13
|
|
|
* }) |
|
14
|
|
|
*/ |
|
15
|
|
|
class Post |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var int Id |
|
19
|
|
|
* @Id @Column(type="integer") @GeneratedValue |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $id; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var string Title |
|
25
|
|
|
* @Column(type="string") |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $title; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var string Slug |
|
31
|
|
|
* @Column(type="string", unique=true) |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $slug; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string Content |
|
37
|
|
|
* @Column(type="text") |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $content; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var DateTime Published at |
|
43
|
|
|
* @Column(type="datetime") |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $published_at; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var Category Category |
|
49
|
|
|
* @ManyToOne(targetEntity="Category", inversedBy="posts") |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $category; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var ArrayCollection Tags |
|
55
|
|
|
* @ManyToMany(targetEntity="Tag", inversedBy="posts", cascade={"persist"}) |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $tags; |
|
58
|
|
|
|
|
59
|
|
|
public function __construct() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->tags = new ArrayCollection; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function getId() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->id; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function getTitle() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->title; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function setTitle($title) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->title = $title; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getSlug() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->slug; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function setSlug($slug) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->slug = $slug; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function getContent() |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->content; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getShortContent() |
|
95
|
|
|
{ |
|
96
|
|
|
return mb_substr($this->content, 0, mb_strpos($this->content, '<!--more-->')); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function setContent($content) |
|
100
|
|
|
{ |
|
101
|
|
|
$this->content = $content; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function getPublishedAt() |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->published_at; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function setPublishedAt(DateTime $published_at) |
|
110
|
|
|
{ |
|
111
|
|
|
$this->published_at = $published_at; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function setCategory($category) |
|
115
|
|
|
{ |
|
116
|
|
|
$this->category = $category; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function getCategory() |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->category; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function getTags() |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->tags; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function addTag(Tag $tag) |
|
130
|
|
|
{ |
|
131
|
|
|
$this->tags[] = $tag; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|