/**
  * Homepage of the module.
  *
  * Displays a list of the model sites which can be duplicated, and a list of
  * the already duplicated sites with their custom values.
  */
 public function indexAction()
 {
     // Models sites which can be duplicated.
     $this->view->assign('modelSitesList', FieldsConfigurationPresets::getModelSitesList());
     // Managing the already duplicated sites list.
     /** @var Save[] $savedSites */
     $savedSites = $this->saveRepository->findAll();
     $finalSavedSites = [];
     foreach ($savedSites as $key => $site) {
         // Adding root page of the site in the configuration.
         /** @var QuerySettingsInterface $defaultQuerySettings */
         $defaultQuerySettings = Core::getObjectManager()->get(QuerySettingsInterface::class);
         $defaultQuerySettings->setRespectStoragePage(false);
         $defaultQuerySettings->setIgnoreEnableFields(true);
         $this->pagesRepository->setDefaultQuerySettings($defaultQuerySettings);
         /** @var Pages $page */
         $page = $this->pagesRepository->findByUid($site->getRootPageUid());
         // The page may have been deleted.
         if (!$page) {
             continue;
         }
         $siteConfiguration['page'] = $page;
         $siteConfiguration['fields'] = $this->fillFieldsValuesFromSavedSite($site);
         $site->setConfiguration($siteConfiguration);
         $finalSavedSites[] = $site;
     }
     $this->view->assign('savedSites', $finalSavedSites);
 }
 /**
  * Construction function.
  *
  * @param array $duplicationData
  * @param array $duplicationSettings
  * @param array $fieldsValues
  */
 public function __construct(array $duplicationData = array(), array $duplicationSettings = array(), $fieldsValues = array())
 {
     $this->objectManager = Core::getObjectManager();
     $this->database = Core::getDatabase();
     $this->extensionConfiguration = Core::getExtensionConfiguration();
     $this->result = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Error\\Result');
     $this->setDuplicationData($duplicationData);
     $this->setDuplicationSettings($duplicationSettings);
     $this->initializeFields($fieldsValues);
 }
 /**
  * Construction function.
  *
  * @param array $duplicationData
  * @param array $duplicationSettings
  * @param array $fieldsValues
  */
 public function __construct(array $duplicationData = [], array $duplicationSettings = [], $fieldsValues = [])
 {
     $this->objectManager = Core::getObjectManager();
     $this->database = Core::getDatabase();
     $this->extensionConfiguration = Core::getExtensionConfiguration();
     $this->result = $this->objectManager->get(Result::class);
     $this->setDuplicationData($duplicationData);
     $this->setDuplicationSettings($duplicationSettings);
     $this->initializeFields($fieldsValues);
 }
 /**
  * Returns a cache instance.
  *
  * @param  string $name Name of the cache. Must be one of the class' constants.
  * @return FrontendInterface
  */
 public static function getCacheInstance($name)
 {
     if (!self::$cacheManager) {
         self::$cacheManager = Core::getObjectManager()->get(TYPO3CacheManager::class);
     }
     $cacheInstance = null;
     switch ($name) {
         case self::CACHE_MAIN:
         case self::CACHE_PROCESSED:
             $cacheInstance = self::$cacheManager->getCache($name);
     }
     return $cacheInstance;
 }
 /**
  * Will set the page linked to the "Save" records (based on their attribute
  * "rootPageUid").
  *
  * @param    array|Save $records An array containing "Save" models, or a single "Save" model.
  * @return    array|null                Returns the array sent with modified "page" attribute, or null if the parameter was empty.
  */
 public function attachPage($records)
 {
     if (!$records) {
         return null;
     }
     $objectManager = Core::getObjectManager();
     /** @var PagesRepository $pagesRepository */
     $pagesRepository = $objectManager->get(PagesRepository::class);
     if (is_array($records) || $records instanceof QueryResult) {
         /** @var Save[] $records */
         foreach ($records as $key => $record) {
             $page = $pagesRepository->findByUidWithoutCondition($record->getRootPageUid());
             $records[$key]->setPage($page[0]);
         }
     } elseif ($records instanceof Save) {
         /** @var Pages $page */
         $page = $pagesRepository->findByUidWithoutCondition($records->getRootPageUid());
         $records->setPage($page[0]);
     }
     return $records;
 }
 /**
  * When a site is being saved, this function will save all the fields values
  * in the DataBase, for further usage.
  */
 public function run()
 {
     $objectManager = Core::getObjectManager();
     /** @var \Romm\SiteFactory\Domain\Repository\SaveRepository $saveRepository */
     $saveRepository = $objectManager->get('Romm\\SiteFactory\\Domain\\Repository\\SaveRepository');
     $saveObject = $saveRepository->findOneByRootPageUid($this->getDuplicatedPageUid());
     $newObject = false;
     if (empty($saveObject)) {
         $newObject = true;
         /** @var \Romm\SiteFactory\Domain\Model\Save $saveObject */
         $saveObject = GeneralUtility::makeInstance('Romm\\SiteFactory\\Domain\\Model\\Save');
         $saveObject->setRootPageUid($this->getDuplicatedPageUid());
     }
     $configuration = $this->getDuplicationData();
     ArrayUtility::mergeRecursiveWithOverrule($configuration, array('fieldsValues' => $this->getFieldsValues()));
     $saveObject->setConfiguration(json_encode($configuration));
     if ($newObject) {
         $saveRepository->add($saveObject);
     } else {
         $saveRepository->update($saveObject);
     }
 }
 /**
  * Generates a TemplateService from a given page uid, by running through
  * the pages root line.
  *
  * @param    int|null|bool $pageUid The uid of the page you want the TypoScript configuration from. If "null" is given, only the static configuration is returned.
  * @return    TemplateService
  */
 private static function generateConfiguration($pageUid = null)
 {
     if (!array_key_exists($pageUid, self::$pageConfiguration)) {
         $objectManager = Core::getObjectManager();
         $rootLine = null;
         if ($pageUid && MathUtility::canBeInterpretedAsInteger($pageUid) && $pageUid > 0) {
             /** @var PageRepository $pageRepository */
             $pageRepository = $objectManager->get(PageRepository::class);
             $rootLine = $pageRepository->getRootLine($pageUid);
         }
         /** @var ExtendedTemplateService $templateService */
         $templateService = $objectManager->get(ExtendedTemplateService::class);
         $templateService->tt_track = 0;
         $templateService->init();
         if ($rootLine !== null) {
             $templateService->runThroughTemplates($rootLine);
         }
         $templateService->generateConfig();
         $templateService->generateConfig_constants();
         self::$pageConfiguration[$pageUid] = $templateService;
     }
     return self::$pageConfiguration[$pageUid];
 }
 /**
  * Returns the sys_template record marked with "site_factory_template" for
  * the given page.
  *
  * @param	int			$pageUid	The page uid.
  * @return	array|false				Array of result, false if no template was found.
  */
 private static function getPageTemplate($pageUid)
 {
     /** @var \TYPO3\CMS\Core\TypoScript\ExtendedTemplateService $templateService */
     $templateService = Core::getObjectManager()->get('TYPO3\\CMS\\Core\\TypoScript\\ExtendedTemplateService');
     $template = $templateService->ext_getFirstTemplate($pageUid);
     return $template;
 }
 /**
  * Returns the sys_template record marked with "site_factory_template" for
  * the given page.
  *
  * @param    int $pageUid The page uid.
  * @return    array|false                Array of result, false if no template was found.
  */
 private static function getPageTemplate($pageUid)
 {
     /** @var ExtendedTemplateService $templateService */
     $templateService = Core::getObjectManager()->get(ExtendedTemplateService::class);
     $template = $templateService->ext_getFirstTemplate($pageUid);
     return $template;
 }
 /**
  * Will set the page linked to the "Save" records (based on their attribute
  * "rootPageUid").
  *
  * @param	array|Save	$records	An array containing "Save" models, or a single "Save" model.
  * @return	array|null				Returns the array sent with modified "page" attribute, or null if the parameter was empty.
  */
 public function attachPage($records)
 {
     if (!$records) {
         return NULL;
     }
     $objectManager = Core::getObjectManager();
     /** @var \Romm\SiteFactory\Domain\Repository\PagesRepository $pagesRepository */
     $pagesRepository = $objectManager->get('Romm\\SiteFactory\\Domain\\Repository\\PagesRepository');
     if (is_array($records) || $records instanceof QueryResult) {
         /** @var \Romm\SiteFactory\Domain\Model\Save[] $records */
         foreach ($records as $key => $record) {
             $page = $pagesRepository->findByUidWithoutCondition($record->getRootPageUid());
             $records[$key]->setPage($page[0]);
         }
     } elseif ($records instanceof Save) {
         /** @var \Romm\SiteFactory\Domain\Model\Pages $page */
         $page = $pagesRepository->findByUidWithoutCondition($records->getRootPageUid());
         $records->setPage($page[0]);
     }
     return $records;
 }