MultiUserBookedCredit::getUserRecords()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace JhFlexiTimeTest\Fixture;
4
5
use Doctrine\Common\DataFixtures\AbstractFixture;
6
use Doctrine\Common\Persistence\ObjectManager;
7
use JhFlexiTime\Entity\BookedCredit;
8
use JhFlexiTime\Entity\BookedCreditType;
9
use JhFlexiTime\Entity\Booking;
10
use JhFlexiTime\Entity\CappedCredit;
11
use JhUser\Entity\User;
12
use JhFlexiTime\DateTime\DateTime;
13
14
/**
15
 * Class MultiUserBookedCredit
16
 * @package JhUserTest\Fixture
17
 * @author Aydin Hassan <[email protected]>
18
 */
19
class MultiUserBookedCredit extends AbstractFixture
20
{
21
    /**
22
     * @var User
23
     */
24
    protected $user1;
25
26
    /**
27
     * @var User
28
     */
29
    protected $user2;
30
31
    /**
32
     * @var array
33
     */
34
    protected $userRecords = [];
35
36
    /**
37
     * @param User $user1
38
     */
39
    public function __construct(User $user1)
40
    {
41
        $this->user1 = $user1;
42
        $this->user2 = new User;
43
        $this->user2->setEmail('[email protected]')->setPassword("password");
44
    }
45
46
    /**
47
     * {inheritDoc}
48
     */
49
    public function load(ObjectManager $manager)
50
    {
51
        $manager->persist($this->user1);
52
        $manager->persist($this->user2);
53
        $manager->flush();
54
55
        $bookingType = new BookedCreditType;
56
        $bookingType->setLabel('Overtime');
57
        $bookingType->setShortname('ot');
58
        $manager->persist($bookingType);
59
60
        $dateFormat = "1-%s-2014";
61
        for ($i = 1; $i <= 10; $i++) {
62
            $date = new DateTime(sprintf($dateFormat, $i));
63
64
            $bookedCredit1 = new BookedCredit;
65
            $bookedCredit1->setUser($this->user1);
66
            $bookedCredit1->setDate($date);
67
            $bookedCredit1->setAmount(10);
68
            $bookedCredit1->setType($bookingType);
69
70
            $this->userRecords[] = $bookedCredit1;
71
72
            $bookedCredit2 = new BookedCredit;
73
            $bookedCredit2->setUser($this->user2);
74
            $bookedCredit2->setDate($date);
75
            $bookedCredit2->setAmount(10);
76
            $bookedCredit2->setType($bookingType);
77
78
79
            $manager->persist($bookedCredit1);
80
            $manager->persist($bookedCredit2);
81
        }
82
83
        $manager->flush();
84
    }
85
86
    /**
87
     * @return array
88
     */
89
    public function getUserRecords()
90
    {
91
        return $this->userRecords;
92
    }
93
94
    /**
95
     * @return User
96
     */
97
    public function getUser2()
98
    {
99
        return $this->user2;
100
    }
101
}
102