|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Matks\Bundle\CustomerSupportBundle\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
6
|
|
|
use Knp\DoctrineBehaviors\Model as ORMBehaviors; |
|
7
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
8
|
|
|
|
|
9
|
|
|
use Matks\Bundle\CustomerSupportBundle\Model\TicketInterface; |
|
10
|
|
|
use Matks\Bundle\CustomerSupportBundle\Model\CategoryInterface; |
|
11
|
|
|
|
|
12
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
13
|
|
|
use LogicException; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Category entity |
|
17
|
|
|
* |
|
18
|
|
|
* @ORM\Entity(repositoryClass="Matks\Bundle\CustomerSupportBundle\Repository\CategoryRepository") |
|
19
|
|
|
* @ORM\Table(name="categories") |
|
20
|
|
|
* |
|
21
|
|
|
* @author Mathieu Ferment <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class Category implements CategoryInterface |
|
24
|
|
|
{ |
|
25
|
|
|
use ORMBehaviors\Timestampable\Timestampable; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var int |
|
29
|
|
|
* |
|
30
|
|
|
* @ORM\Id |
|
31
|
|
|
* @ORM\Column(type="integer") |
|
32
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
|
33
|
|
|
*/ |
|
34
|
|
|
private $id; |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var string |
|
38
|
|
|
* |
|
39
|
|
|
* @ORM\Column(type="string", length=255) |
|
40
|
|
|
* @Assert\NotBlank() |
|
41
|
|
|
*/ |
|
42
|
|
|
private $title; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var TicketInterface[] |
|
46
|
|
|
* |
|
47
|
|
|
* There are no addTicket or removeTicket functions as this is done by |
|
48
|
|
|
* the owning side, on Ticket entity |
|
49
|
|
|
* |
|
50
|
|
|
* @ORM\OneToMany( |
|
51
|
|
|
* targetEntity="Matks\Bundle\CustomerSupportBundle\Model\TicketInterface", |
|
52
|
|
|
* mappedBy="category", |
|
53
|
|
|
* cascade={"persist", "remove", "merge"} |
|
54
|
|
|
* ) |
|
55
|
|
|
* @Assert\Valid() |
|
56
|
|
|
*/ |
|
57
|
|
|
private $tickets; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var boolean |
|
61
|
|
|
* |
|
62
|
|
|
* @ORM\Column(type="boolean") |
|
63
|
|
|
* @Assert\NotBlank() |
|
64
|
|
|
*/ |
|
65
|
|
|
private $enabled; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Constructor |
|
69
|
|
|
* |
|
70
|
|
|
* @param string $title |
|
71
|
|
|
*/ |
|
72
|
4 |
|
public function __construct($title) |
|
73
|
|
|
{ |
|
74
|
4 |
|
$this->title = $title; |
|
75
|
4 |
|
$this->tickets = new ArrayCollection(); |
|
|
|
|
|
|
76
|
4 |
|
$this->enabled = true; |
|
77
|
4 |
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Get tickets associated |
|
81
|
|
|
* |
|
82
|
|
|
* @return TicketInterface[] |
|
83
|
|
|
*/ |
|
84
|
3 |
|
public function getTickets() |
|
85
|
|
|
{ |
|
86
|
3 |
|
return $this->tickets; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Get title |
|
91
|
|
|
* |
|
92
|
|
|
* @return string |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getTitle() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->title; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
2 |
|
public function deactivate() |
|
100
|
|
|
{ |
|
101
|
2 |
|
if (!$this->isActive()) { |
|
102
|
1 |
|
throw new LogicException("Cannot deactivate category not active"); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
2 |
|
if (!$this->getTickets()->isEmpty()) { |
|
106
|
|
|
throw new LogicException("Cannot deactivate category with tickets associated"); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
2 |
|
$this->enabled = false; |
|
110
|
2 |
|
} |
|
111
|
|
|
|
|
112
|
1 |
|
public function activate() |
|
113
|
|
|
{ |
|
114
|
1 |
|
if ($this->isActive()) { |
|
115
|
1 |
|
throw new LogicException("Cannot activate category already active"); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
1 |
|
$this->enabled = true; |
|
119
|
1 |
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @return bool |
|
123
|
|
|
*/ |
|
124
|
3 |
|
public function isActive() |
|
125
|
|
|
{ |
|
126
|
3 |
|
return true === $this->enabled; |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|