StatsSettingsRepository.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Opentalent\OtStats\Settings;
  3. /**
  4. * Class StatsRepository
  5. *
  6. * Give access to the website's settings for the stats module
  7. *
  8. * @package Opentalent\OtTemplating\Page
  9. */
  10. class StatsSettingsRepository
  11. {
  12. /**
  13. * @var \TYPO3\CMS\Core\Database\ConnectionPool
  14. */
  15. private $connectionPool;
  16. public function injectConnectionPool(\TYPO3\CMS\Core\Database\ConnectionPool $connectionPool)
  17. {
  18. $this->connectionPool = $connectionPool;
  19. }
  20. /**
  21. * Returns the website registered matomo site's id
  22. * @param int $rootPageUid
  23. * @return int|null
  24. */
  25. public function getMatomoSiteId(int $rootPageUid)
  26. {
  27. // Set up a connection to the typo3 DB
  28. $queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
  29. $matomoId = $queryBuilder
  30. ->select('tx_opentalent_matomo_id')
  31. ->from('pages')
  32. ->where($queryBuilder->expr()->eq('uid', $rootPageUid))
  33. ->andWhere($queryBuilder->expr()->eq('is_siteroot', 1))
  34. ->execute()
  35. ->fetchColumn(0);
  36. if ($matomoId === false) {
  37. throw new \RuntimeException('No existing root page with uid ' . $rootPageUid);
  38. }
  39. return $matomoId;
  40. }
  41. }