TemplateRepository.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace Opentalent\OtTemplating\Templating;
  3. use Opentalent\OtCore\Website\OtPageRepository;
  4. use Opentalent\OtCore\Website\OtWebsiteRepository;
  5. use TYPO3\CMS\Core\Database\ConnectionPool;
  6. use TYPO3\CMS\Core\Utility\GeneralUtility;
  7. use TYPO3\CMS\Extbase\Object\ObjectManager;
  8. /**
  9. * Class TemplateRepository
  10. * Provides methods to retrieve data about the current site's template
  11. *
  12. * @package Opentalent\OtCore\Templating
  13. */
  14. class TemplateRepository
  15. {
  16. CONST templates = [
  17. 'Classic' => [
  18. 'name' => 'Classique',
  19. 'description' => "Le thème classique, simple et complet. C'est le thème par défaut.",
  20. 'picture' => 'EXT:ot_templating/Resources/Public/media/theme_classic.png'
  21. ],
  22. 'Modern' => [
  23. 'name' => 'Moderne',
  24. 'description' => '[Nouveauté 2020] Un thème moderne et intuitif.',
  25. 'picture' => 'EXT:ot_templating/Resources/Public/media/theme_modern.png'
  26. ]
  27. ];
  28. CONST defaultTemplate = 'Classic';
  29. CONST defaultPreferences = [
  30. 'themeColor' => 'lightblue',
  31. 'displayCarousel' => '1',
  32. 'displayBreadcrumb' => '1',
  33. ];
  34. /**
  35. * Returns the site template's name
  36. *
  37. * @param int $rootUid
  38. * @return string
  39. */
  40. public function getTemplate(int $rootUid): string
  41. {
  42. if (!($rootUid >= 0)) {
  43. return self::defaultTemplate;
  44. }
  45. $otWebsiteRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(OtWebsiteRepository::class);
  46. $website = $otWebsiteRepository->getWebsiteByPageUid($rootUid);
  47. $templateName = $website['template'];
  48. if ($templateName==='' || $templateName==null) {
  49. return self::defaultTemplate;
  50. }
  51. return $templateName;
  52. }
  53. /**
  54. * Returns the current site template's name
  55. * @param int $rootUid
  56. * @return array
  57. */
  58. public function getTemplatePreferences(int $rootUid): array
  59. {
  60. $otWebsiteRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(OtWebsiteRepository::class);
  61. $website = $otWebsiteRepository->getWebsiteByPageUid($rootUid);
  62. $templatePreferences = $website['template_preferences'] ?? '';
  63. if ($templatePreferences !== '') {
  64. $templatePreferences = json_decode($templatePreferences, true);
  65. } else {
  66. $templatePreferences = [];
  67. }
  68. return array_merge(self::defaultPreferences, $templatePreferences);
  69. }
  70. }