|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace JhFlexiTime\Service; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
6
|
|
|
use JhFlexiTime\DateTime\DateTime; |
|
7
|
|
|
use JhFlexiTime\Entity\CappedCredit; |
|
8
|
|
|
use JhFlexiTime\Repository\CappedCreditRepositoryInterface; |
|
9
|
|
|
use ZfcUser\Entity\UserInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class CappedCreditService |
|
13
|
|
|
* @package JhFlexiTime\Service |
|
14
|
|
|
* @author Aydin Hassan <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class CappedCreditService |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var CappedCreditRepositoryInterface |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $cappedCreditRepository; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var ObjectManager |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $objectManager; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param CappedCreditRepositoryInterface $cappedCreditRepository |
|
30
|
|
|
* @param ObjectManager $objectManager |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct(CappedCreditRepositoryInterface $cappedCreditRepository, ObjectManager $objectManager) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->cappedCreditRepository = $cappedCreditRepository; |
|
35
|
|
|
$this->objectManager = $objectManager; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param UserInterface $user |
|
40
|
|
|
* @param float $creditAmount |
|
41
|
|
|
* @param DateTime $date |
|
42
|
|
|
*/ |
|
43
|
|
|
public function create(UserInterface $user, $creditAmount, DateTime $date) |
|
44
|
|
|
{ |
|
45
|
|
|
$cappedCredit = new CappedCredit; |
|
46
|
|
|
$cappedCredit->setUser($user); |
|
47
|
|
|
$cappedCredit->setDate($date->endOfMonth()); |
|
48
|
|
|
$cappedCredit->setCappedCredit($creditAmount); |
|
49
|
|
|
$this->save($cappedCredit); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param CappedCredit $cappedCredit |
|
54
|
|
|
*/ |
|
55
|
|
|
public function save(CappedCredit $cappedCredit) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->objectManager->persist($cappedCredit); |
|
58
|
|
|
$this->objectManager->flush(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param UserInterface $user |
|
63
|
|
|
*/ |
|
64
|
|
|
public function clearCappedCreditEntries(UserInterface $user) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->cappedCreditRepository->deleteAllByUser($user); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|