ScanReport.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Opentalent\OtAdmin\Domain\Entity;
  3. /**
  4. * Report of a ScanController->scanAllAction() operation
  5. */
  6. class ScanReport
  7. {
  8. /**
  9. * Date and time of the scan report
  10. * @var \DateTime|null
  11. */
  12. protected ?\DateTime $datetime = null;
  13. /**
  14. * Numeric statistics (number of website in each state)
  15. * @var array
  16. */
  17. protected array $stats = [];
  18. /**
  19. * Per-site results
  20. * @var array
  21. */
  22. protected array $results = [];
  23. public function __construct() {
  24. $this->datetime = new \DateTime();
  25. }
  26. /**
  27. * @return \DateTime
  28. */
  29. public function getDatetime(): \DateTime
  30. {
  31. return $this->datetime;
  32. }
  33. /**
  34. * @return array
  35. */
  36. public function getStats(): array
  37. {
  38. return $this->stats;
  39. }
  40. /**
  41. * @return array
  42. */
  43. public function getLabelledStats(): array
  44. {
  45. $labelled = [];
  46. foreach ($this->stats as $k => $v) {
  47. $labelled[SiteStatus::STATUSES[$k]] = $v;
  48. }
  49. return $labelled;
  50. }
  51. /**
  52. * @return array
  53. */
  54. public function getResults(): array
  55. {
  56. return $this->results;
  57. }
  58. /**
  59. * Set the result associated with the given organization id
  60. *
  61. * @param int $organizationId
  62. * @param SiteStatus $siteStatus
  63. */
  64. public function setResultFor(int $organizationId, SiteStatus $siteStatus): void
  65. {
  66. $this->results[$organizationId] = $siteStatus;
  67. if (!isset($this->stats[$siteStatus->getStatusCode()])) {
  68. $this->stats[$siteStatus->getStatusCode()] = 0;
  69. }
  70. $this->stats[$siteStatus->getStatusCode()] += 1;
  71. }
  72. }