1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Entity; |
4
|
|
|
|
5
|
|
|
use AppBundle\Util\Uuid; |
6
|
|
|
use Behat\Transliterator\Transliterator; |
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
8
|
|
|
use Doctrine\ORM\Mapping\Column; |
9
|
|
|
use Doctrine\ORM\Mapping\Entity; |
10
|
|
|
use Doctrine\ORM\Mapping\Id; |
11
|
|
|
use Doctrine\ORM\Mapping\OneToMany; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @Entity(repositoryClass="CategoryRepository") |
15
|
|
|
*/ |
16
|
|
|
class Category |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @Id |
20
|
|
|
* @Column(type="string", length=40) |
21
|
|
|
*/ |
22
|
|
|
private $id; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @OneToMany(targetEntity="Meal", mappedBy="category") |
26
|
|
|
*/ |
27
|
|
|
private $meals; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @Column(type="string", length=128) |
31
|
|
|
*/ |
32
|
|
|
private $name; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @Column(type="text", nullable=true) |
36
|
|
|
*/ |
37
|
|
|
private $description; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @Column(type="string", length=128, unique=true) |
41
|
|
|
*/ |
42
|
|
|
private $slug; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @Column(type="integer") |
46
|
|
|
*/ |
47
|
|
|
private $position = 1; |
48
|
|
|
|
49
|
|
|
public function __construct() |
50
|
|
|
{ |
51
|
|
|
$this->id = Uuid::generateV4(); |
52
|
|
|
$this->meals = new ArrayCollection(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getId() |
56
|
|
|
{ |
57
|
|
|
return $this->id; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getMeals($activeOnly = true) |
61
|
|
|
{ |
62
|
|
|
$meals = array(); |
63
|
|
|
|
64
|
|
|
foreach ($this->meals as $meal) { |
65
|
|
|
if (!$activeOnly || $meal->isActive()) { |
66
|
|
|
$meals[] = $meal; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
usort($meals, function ($left, $right) { |
71
|
|
|
return $left->getPosition() > $right->getPosition(); |
72
|
|
|
}); |
73
|
|
|
|
74
|
|
|
return $meals; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getName() |
78
|
|
|
{ |
79
|
|
|
return $this->name; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getSlug() |
83
|
|
|
{ |
84
|
|
|
return $this->slug; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function setName($name) |
88
|
|
|
{ |
89
|
|
|
$this->name = $name; |
90
|
|
|
$this->slug = Transliterator::urlize($name); |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getDescription() |
96
|
|
|
{ |
97
|
|
|
return $this->description; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function setDescription($description) |
101
|
|
|
{ |
102
|
|
|
$this->description = $description; |
103
|
|
|
|
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function getPosition() |
108
|
|
|
{ |
109
|
|
|
return $this->position; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function setPosition($position) |
113
|
|
|
{ |
114
|
|
|
$this->position = $position; |
115
|
|
|
|
116
|
|
|
return $this; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|