]>
Commit | Line | Data |
---|---|---|
61d40693 A |
1 | <?php |
2 | ||
3 | /** | |
4 | * Populates a reference history | |
5 | */ | |
6 | class ReferenceHistory | |
7 | { | |
8 | private $count; | |
9 | ||
10 | private $history = []; | |
11 | ||
12 | /** | |
13 | * Populates the test DB with reference data | |
14 | */ | |
15 | public function __construct() | |
16 | { | |
17 | $this->addEntry( | |
6bc90f50 A |
18 | History::DELETED, |
19 | DateTime::createFromFormat('Ymd_His', '20170303_121216'), | |
20 | 124 | |
61d40693 A |
21 | ); |
22 | ||
23 | $this->addEntry( | |
6bc90f50 A |
24 | History::SETTINGS, |
25 | DateTime::createFromFormat('Ymd_His', '20170302_121215') | |
61d40693 A |
26 | ); |
27 | ||
28 | $this->addEntry( | |
29 | History::UPDATED, | |
30 | DateTime::createFromFormat('Ymd_His', '20170301_121214'), | |
31 | 123 | |
32 | ); | |
33 | ||
34 | $this->addEntry( | |
6bc90f50 A |
35 | History::CREATED, |
36 | DateTime::createFromFormat('Ymd_His', '20170201_121214'), | |
37 | 124 | |
61d40693 A |
38 | ); |
39 | ||
40 | $this->addEntry( | |
6bc90f50 A |
41 | History::CREATED, |
42 | DateTime::createFromFormat('Ymd_His', '20170101_121212'), | |
43 | 123 | |
61d40693 A |
44 | ); |
45 | } | |
46 | ||
47 | /** | |
48 | * Adds a new history entry | |
49 | * | |
50 | * @param string $event Event identifier | |
51 | * @param DateTime $datetime creation date | |
52 | * @param int $id optional: related link ID | |
53 | */ | |
54 | protected function addEntry($event, $datetime, $id = null) | |
55 | { | |
56 | $link = [ | |
57 | 'event' => $event, | |
58 | 'datetime' => $datetime, | |
59 | 'id' => $id, | |
60 | ]; | |
61 | $this->history[] = $link; | |
62 | $this->count++; | |
63 | } | |
64 | ||
65 | /** | |
66 | * Writes data to the datastore | |
67 | * | |
68 | * @param string $filename write history content to. | |
69 | */ | |
70 | public function write($filename) | |
71 | { | |
72 | FileUtils::writeFlatDB($filename, $this->history); | |
73 | } | |
74 | ||
75 | /** | |
76 | * Returns the number of links in the reference data | |
77 | */ | |
78 | public function count() | |
79 | { | |
80 | return $this->count; | |
81 | } | |
82 | } |