|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File was created 28.04.2016 08:30 |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace PeekAndPoke\Component\Slumber\Data\Addon\Journal; |
|
7
|
|
|
|
|
8
|
|
|
use PeekAndPoke\Component\Slumber\Data\Addon\Journal\DomainModel\JournalEntry; |
|
9
|
|
|
use PeekAndPoke\Component\Slumber\Data\Addon\Journal\DomainModel\Record; |
|
10
|
|
|
use PeekAndPoke\Component\Slumber\Data\Cursor; |
|
11
|
|
|
use PeekAndPoke\Component\Slumber\Data\EntityRepository; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @method JournalEntry[]|Cursor find(array $query = null) |
|
15
|
|
|
* @method JournalEntry|null findOne(array $query = null) |
|
16
|
|
|
* @method JournalEntry|null findById($id) |
|
17
|
|
|
* @method JournalEntry|null findByReference($reference) |
|
18
|
|
|
* |
|
19
|
|
|
* @author Karsten J. Gerber <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class JournalEntryRepositoryImpl extends EntityRepository implements JournalEntryRepository |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @return Record |
|
25
|
|
|
*/ |
|
26
|
2 |
|
public function createRecord() |
|
27
|
|
|
{ |
|
28
|
2 |
|
return new JournalEntry(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @return int |
|
33
|
|
|
*/ |
|
34
|
2 |
|
public function getRecordsCount() |
|
35
|
|
|
{ |
|
36
|
2 |
|
return $this->find()->count(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return int |
|
41
|
|
|
*/ |
|
42
|
2 |
|
public function getCompactedRecordsCount() |
|
43
|
|
|
{ |
|
44
|
2 |
|
return $this->find([ |
|
45
|
2 |
|
'isCompacted' => true, |
|
46
|
2 |
|
])->count(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param string $externalReference |
|
51
|
|
|
* |
|
52
|
|
|
* @return JournalEntry[]|Cursor |
|
53
|
|
|
*/ |
|
54
|
3 |
|
public function findByExternalReference($externalReference) |
|
55
|
|
|
{ |
|
56
|
3 |
|
$result = $this->find([ |
|
57
|
3 |
|
'externalReference' => (string) $externalReference, |
|
58
|
|
|
]); |
|
59
|
|
|
|
|
60
|
3 |
|
$result->sort(['_id' => 1]); |
|
61
|
|
|
|
|
62
|
3 |
|
return $result; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param int $limit Number of entries to get |
|
67
|
|
|
* |
|
68
|
|
|
* @return JournalEntry[]|Cursor |
|
69
|
|
|
*/ |
|
70
|
1 |
|
public function findOldestNotCompacted($limit) |
|
71
|
|
|
{ |
|
72
|
1 |
|
$cursor = $this->find([ |
|
73
|
1 |
|
'isCompacted' => ['$ne' => true], |
|
74
|
|
|
]); |
|
75
|
|
|
|
|
76
|
1 |
|
$cursor->skip(0)->limit($limit); |
|
77
|
|
|
|
|
78
|
1 |
|
return $cursor; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|