1 | <?php |
||
15 | class TestGroup implements GroupInterface, \JsonSerializable |
||
16 | { |
||
17 | /** |
||
18 | * @var integer |
||
19 | * |
||
20 | * @ORM\Column(name="id", type="integer") |
||
21 | * @ORM\Id |
||
22 | * @ORM\GeneratedValue(strategy="AUTO") |
||
23 | */ |
||
24 | private $id; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | * |
||
29 | * @ORM\Column(name="name", type="string", length=50, unique=true) |
||
30 | */ |
||
31 | private $name; |
||
32 | |||
33 | /** |
||
34 | * @ORM\OneToMany(targetEntity="Test", mappedBy="group") |
||
35 | */ |
||
36 | private $tests; |
||
37 | |||
38 | /** |
||
39 | * @ORM\ManyToMany(targetEntity="Overwatch\UserBundle\Entity\User", mappedBy="groups") |
||
40 | */ |
||
41 | private $users; |
||
42 | |||
43 | /** |
||
44 | * @var \DateTime |
||
45 | * |
||
46 | * @ORM\Column(name="created_at", type="datetime") |
||
47 | */ |
||
48 | private $createdAt; |
||
49 | |||
50 | /** |
||
51 | * @var \DateTime |
||
52 | * |
||
53 | * @ORM\Column(name="updated_at", type="datetime") |
||
54 | */ |
||
55 | private $updatedAt; |
||
56 | |||
57 | |||
58 | /** |
||
59 | * Constructor |
||
60 | */ |
||
61 | 136 | public function __construct() |
|
66 | |||
67 | /** |
||
68 | * Serialise object to JSON |
||
69 | */ |
||
70 | 6 | public function jsonSerialize() |
|
71 | { |
||
72 | return [ |
||
73 | 6 | 'id' => $this->getId(), |
|
74 | 6 | 'name' => $this->getName(), |
|
75 | 6 | 'tests' => $this->getTests()->toArray(), |
|
76 | 6 | 'users' => $this->getUsers()->toArray(), |
|
77 | 6 | 'createdAt' => $this->getCreatedAt()->getTimestamp(), |
|
78 | 6 | 'updatedAt' => $this->getUpdatedAt()->getTimestamp() |
|
79 | 6 | ]; |
|
80 | } |
||
81 | |||
82 | /** |
||
83 | * Get id |
||
84 | * |
||
85 | * @return integer |
||
86 | */ |
||
87 | 29 | public function getId() |
|
91 | |||
92 | /** |
||
93 | * Set name |
||
94 | * |
||
95 | * @param string $name |
||
96 | * @return TestGroup |
||
97 | */ |
||
98 | 136 | public function setName($name) |
|
104 | |||
105 | /** |
||
106 | * Get name |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | 29 | public function getName() |
|
114 | |||
115 | /** |
||
116 | * Set createdAt |
||
117 | * |
||
118 | * @ORM\PrePersist |
||
119 | * @return TestGroup |
||
120 | */ |
||
121 | 130 | public function setCreatedAt() |
|
129 | |||
130 | /** |
||
131 | * Get createdAt |
||
132 | * |
||
133 | * @return \DateTime |
||
134 | */ |
||
135 | 7 | public function getCreatedAt() |
|
139 | |||
140 | /** |
||
141 | * Set updatedAt |
||
142 | * |
||
143 | * @ORM\PrePersist |
||
144 | * @ORM\PreUpdate |
||
145 | * @return TestGroup |
||
146 | */ |
||
147 | 130 | public function setUpdatedAt() |
|
153 | |||
154 | /** |
||
155 | * Get updatedAt |
||
156 | * |
||
157 | * @return \DateTime |
||
158 | */ |
||
159 | 6 | public function getUpdatedAt() |
|
163 | |||
164 | /** |
||
165 | * Add tests |
||
166 | * |
||
167 | * @param \Overwatch\TestBundle\Entity\Test $tests |
||
168 | * @return TestGroup |
||
169 | */ |
||
170 | 1 | public function addTest(\Overwatch\TestBundle\Entity\Test $tests) |
|
176 | |||
177 | /** |
||
178 | * Remove tests |
||
179 | * |
||
180 | * @param \Overwatch\TestBundle\Entity\Test $tests |
||
181 | */ |
||
182 | 1 | public function removeTest(\Overwatch\TestBundle\Entity\Test $tests) |
|
186 | |||
187 | /** |
||
188 | * Get tests |
||
189 | * |
||
190 | * @return \Doctrine\Common\Collections\Collection |
||
191 | */ |
||
192 | 11 | public function getTests() |
|
196 | |||
197 | /** |
||
198 | * Add users |
||
199 | * |
||
200 | * @param \Overwatch\UserBundle\Entity\User $user |
||
201 | * @return TestGroup |
||
202 | */ |
||
203 | 131 | public function addUser(\Overwatch\UserBundle\Entity\User $user) |
|
210 | |||
211 | /** |
||
212 | * Remove user |
||
213 | * |
||
214 | * @param \Overwatch\UserBundle\Entity\User $user |
||
215 | */ |
||
216 | 1 | public function removeUser(\Overwatch\UserBundle\Entity\User $user) |
|
217 | { |
||
218 | 1 | $user->removeGroup($this); |
|
219 | 1 | $this->users->removeElement($user); |
|
220 | 1 | } |
|
221 | |||
222 | /** |
||
223 | * Get users |
||
224 | * |
||
225 | * @return \Doctrine\Common\Collections\Collection |
||
226 | */ |
||
227 | 127 | public function getUsers() |
|
231 | |||
232 | /** |
||
233 | * FOSUserBundle needs groups to have roles. We don't. |
||
234 | */ |
||
235 | 20 | public function getRoles() |
|
255 | } |
||
256 |