1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Smart\ContentBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
7
|
|
|
use Smart\ContentBundle\Entity\Traits\ContentTrait; |
8
|
|
|
use Smart\ContentBundle\Entity\Traits\ImageTrait; |
9
|
|
|
use Smart\ContentBundle\Entity\Traits\SeoTrait; |
10
|
|
|
use Symfony\Component\HttpFoundation\File\File; |
11
|
|
|
use Symfony\Component\HttpFoundation\File\UploadedFile; |
12
|
|
|
use Vich\UploaderBundle\Mapping\Annotation as Vich; |
13
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
14
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @ORM\Entity(repositoryClass="Smart\ContentBundle\Entity\Repository\CategoryRepository") |
18
|
|
|
* @ORM\Table(name="smart_content_category") |
19
|
|
|
* |
20
|
|
|
* @UniqueEntity({"url"}) |
21
|
|
|
* |
22
|
|
|
* @Vich\Uploadable |
23
|
|
|
*/ |
24
|
|
|
class Category |
25
|
|
|
{ |
26
|
|
|
use ContentTrait; |
27
|
|
|
use SeoTrait; |
28
|
|
|
use ImageTrait; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var int |
32
|
|
|
* |
33
|
|
|
* @ORM\Id |
34
|
|
|
* @ORM\Column(name="id", type="integer") |
35
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
36
|
|
|
*/ |
37
|
|
|
protected $id; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var ArrayCollection|Post[] |
41
|
|
|
* |
42
|
|
|
* @ORM\OneToMany(targetEntity="Smart\ContentBundle\Entity\Post", mappedBy="category") |
43
|
|
|
*/ |
44
|
|
|
protected $posts; |
45
|
|
|
|
46
|
1 |
|
public function __construct() |
47
|
|
|
{ |
48
|
1 |
|
$this->posts = new ArrayCollection(); |
49
|
1 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
public function __toString() |
55
|
|
|
{ |
56
|
|
|
return (string) $this->getTitle(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return ArrayCollection|Post[] |
61
|
|
|
*/ |
62
|
|
|
public function getPosts() |
63
|
|
|
{ |
64
|
|
|
return $this->posts; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param ArrayCollection|Post[] $posts |
69
|
|
|
* |
70
|
|
|
* @return $this |
71
|
|
|
*/ |
72
|
|
|
public function setPosts($posts) |
73
|
|
|
{ |
74
|
|
|
foreach ($posts as $post) { |
75
|
|
|
$this->addPost($post); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param Post $post |
83
|
|
|
* |
84
|
|
|
* @return $this |
85
|
|
|
*/ |
86
|
|
|
public function addPost($post) |
87
|
|
|
{ |
88
|
|
|
if (!$this->posts->contains($post)) { |
89
|
|
|
$this->posts->add($post); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|