1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JhFlexiTimeTest\Fixture; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\DataFixtures\AbstractFixture; |
6
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
7
|
|
|
use JhFlexiTime\Entity\Booking; |
8
|
|
|
use JhUser\Entity\User; |
9
|
|
|
use JhFlexiTime\DateTime\DateTime; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class BookingsNotInMonth |
13
|
|
|
* @package JhUserTest\Fixture |
14
|
|
|
* @author Aydin Hassan <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class BookingsNotInMonth extends AbstractFixture |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var DateTime[] |
20
|
|
|
*/ |
21
|
|
|
protected $dates; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var User |
25
|
|
|
*/ |
26
|
|
|
protected $user; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param User $user |
30
|
|
|
*/ |
31
|
|
|
public function __construct(User $user) |
32
|
|
|
{ |
33
|
|
|
$this->user = $user; |
34
|
|
|
|
35
|
|
|
$this->dates = [ |
36
|
|
|
new DateTime("1 April 2014"), |
37
|
|
|
new DateTime("2 April 2014"), |
38
|
|
|
new DateTime("3 April 2014"), |
39
|
|
|
new DateTime("4 April 2014"), |
40
|
|
|
new DateTime("5 April 2014"), |
41
|
|
|
new DateTime("6 May 2014"), |
42
|
|
|
new DateTime("7 May 2014"), |
43
|
|
|
new DateTime("8 May 2014"), |
44
|
|
|
new DateTime("9 May 2014"), |
45
|
|
|
new DateTime("10 May 2014"), |
46
|
|
|
new DateTime("1 September 2014"), |
47
|
|
|
new DateTime("2 September 2014"), |
48
|
|
|
new DateTime("3 September 2014"), |
49
|
|
|
new DateTime("4 September 2014"), |
50
|
|
|
new DateTime("5 September 2014"), |
51
|
|
|
]; |
52
|
|
|
|
53
|
|
|
$this->monthWithNoBookings = new DateTime("1 October 2014"); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {inheritDoc} |
58
|
|
|
*/ |
59
|
|
|
public function load(ObjectManager $manager) |
60
|
|
|
{ |
61
|
|
|
$manager->persist($this->user); |
62
|
|
|
$manager->flush(); |
63
|
|
|
|
64
|
|
|
foreach ($this->dates as $date) { |
65
|
|
|
$booking = new Booking(); |
66
|
|
|
$booking->setUser($this->user); |
67
|
|
|
$booking->setDate($date); |
68
|
|
|
$manager->persist($booking); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$manager->flush(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return DateTime |
76
|
|
|
*/ |
77
|
|
|
public function getMonthWithNoBookings() |
78
|
|
|
{ |
79
|
|
|
return $this->monthWithNoBookings; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: