ReferenceHistory.php 1.8 KB

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