StatsSettingsRepository.php 1.3 KB

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