Fetch the active template blocks for the active shop and the active theme.

@todo extract oxtplblocks query to ModuleTemplateBlockRepository

@return ResultSetInterface The active template blocks for the active shop and the active theme.
160958
protected function fetchBlockRecords()
    {
        $activeThemeId = oxNew(\OxidEsales\Eshop\Core\Theme::class)->getActiveThemeId();
        $config = Registry::getConfig();
        $database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);

        $query = "select * from oxtplblocks where oxactive=1 and oxshopid=? and oxtheme in ('', ?)";

        return $database->select($query, [$config->getShopId(), $activeThemeId]);
    }
22431
public function getTemplateAccessors() {
		if($this->templateAccessors) return $this->templateAccessors;

		$list = array ('Up', 'Top');
		foreach(ClassInfo::implementorsOf('TemplateGlobalProvider') as $class) {
			$vars = $class::get_template_global_variables();
			if($vars) {
				foreach($vars as $varName => $func) {
					$list[] = is_numeric($varName) ? strtolower($func) : strtolower($varName);
				}
			}
		}

		return $this->templateAccessors = $list;		
	}
684778
public function findAllTemplates()
    {
        if (null !== $this->templates) {
            return $this->templates;
        }

        $templates = array();

        foreach ($this->paths as $dir) {
            $templates = array_merge($templates, $this->findTemplatesInFolder($dir));
        }

        return $this->templates = $templates;
    }
636706
private function view()
    {
        if (isset(static::$view)) {
            return static::$view;
        }

        $classNamespace = $this->getModuleName();
        $className = $this->getComponentName();

        return "{$classNamespace}::blocks.{$className}";
    }
1003473
public function getAllTemplates()
    {
        $strCacheDir = $this->container->getParameter('kernel.cache_dir');

        // Try to load from cache
        if (file_exists($strCacheDir.'/contao/config/twig-templates.php')) {
            self::$twigFiles = include $strCacheDir.'/contao/config/twig-templates.php';

            return self::$twigFiles;
        }

        $bundles = $this->kernel->getBundles();

        if (\is_array($bundles)) {
            foreach (array_reverse($bundles) as $key => $value) {
                $path = $this->kernel->locateResource("@$key");

                $dir = rtrim($path, '/').'/Resources/views';

                if (!is_dir($dir)) {
                    continue;
                }
                $finder = new Finder();
                $twigKey = preg_replace('/Bundle$/', '', $key);

                foreach ($finder->in($dir)->files()->name('*.twig') as $file) {
                    /** @var SplFileInfo $file */
                    $name = $file->getBasename();
                    $legacyName = false !== strpos($name, 'html.twig') ? $file->getBasename('.html.twig') : $name;

                    if (isset(self::$twigFiles[$name])) {
                        continue;
                    }

                    self::$twigFiles[$name] = "@$twigKey/".$file->getRelativePathname();

                    if ($legacyName !== $name) {
                        self::$twigFiles[$legacyName] = self::$twigFiles[$name];
                    }
                }
            }
        }

        foreach ($this->container->get('contao.resource_finder')->findIn('templates')->name('*.twig') as $file) {
            $name = $file->getBasename();
            $legacyName = false !== strpos($name, 'html.twig') ? $file->getBasename('.html.twig') : $name;

            /* @var SplFileInfo $file */
            self::$twigFiles[$name] = $file->getRealPath();

            if ($legacyName !== $name) {
                self::$twigFiles[$legacyName] = self::$twigFiles[$name];
            }
        }

        // add root templates
        $rootTemplates = $this->findTemplates($this->containerUtil->getProjectDir().'/templates/');

        if (\is_array($rootTemplates)) {
            foreach ($rootTemplates as $file) {
                $name = basename($file);
                $legacyName = false !== strpos($name, 'html.twig') ? basename($file, '.html.twig') : $name;

                self::$twigFiles[$name] = $file;

                if ($legacyName !== $name) {
                    self::$twigFiles[$legacyName] = self::$twigFiles[$name];
                }
            }
        }

        return self::$twigFiles;
    }
1146522
public function getBlocksWithFilter($onlyActive = true)
    {
        $query = Block::query()->with(self::$loadRelations)
            ->where('filter', '!=', null);

        if ($onlyActive) {
            $query->where('is_active', '=', true);
        }

        $blocks = $query->orderBy('weight', 'ASC')->get();

        return $blocks;
    }
1348242
public function getTemplate()
    {
        if (!$this->useCaching()) {
            $result = $this->renderTemplate();
        } else {
            $cache = Injector::inst()->get(CacheInterface::class . '.PageSlices');
            if (!$cache->has($this->getCacheKey())) {
                $result = $this->renderTemplate();
                $cache->set($this->getCacheKey(), $result);
            } else {
                $result = $cache->get($this->getCacheKey());
            }
        }

        return $result;
    }
1046495
public static function &GetInstanceForCurrentFilter()
    {
        static $oInstance = false;
        if (false === $oInstance) {
            $oInstance = null;
            $aFilter = TdbShop::GetActiveFilter();
            if (array_key_exists('shop_manufacturer_id', $aFilter) && !empty($aFilter['shop_manufacturer_id'])) {
                $oInstance = TdbShopManufacturer::GetNewInstance();
                /** @var $oInstance TdbShopManufacturer */
                if (!$oInstance->Load($aFilter['shop_manufacturer_id'])) {
                    $oInstance = null;
                }
            }
        }

        return $oInstance;
    }
1372469
public function getThirdPartyBlocks()
    {
        /** @var Application $application */
        $application = $this->get('application');
        $embeddedComposer = $application->getEmbeddedComposer();
        $config = $embeddedComposer->getExternalComposerConfig();
        $loadBlock = $config->has('block-loader') ? $config->get('block-loader') : '.bldr/blocks.yml';
        $blockFile = $embeddedComposer->getExternalRootDirectory().DIRECTORY_SEPARATOR.$loadBlock;

        if (!file_exists($blockFile)) {
            return [];
        }

        $blockNames = Yaml::parse(file_get_contents($blockFile));
        if (null === $blockNames) {
            return [];
        }

        $blocks     = [];
        foreach ($blockNames as $block) {
            $blocks[] = new $block();
        }

        return $blocks;
    }
1320953
public function getActiveAreas($template)
    {
        $originalTemplate = $template;
        $options = get_option('modularity-options');

        // Use the ACF-options for module areas if activated
        if (get_field('acf_module_areas', 'option')) {
            $template = str_replace('.blade.php', '', $template);
            $active = get_field($template . '_active_sidebars', 'option');
        } else {
            $active = isset($options['enabled-areas'][$template]) ? $options['enabled-areas'][$template] : array();
        }

        self::$isEditing['template'] = $template;

        // Fallback
        if (is_array($active) && count($active) === 0 && !is_numeric($template) && strpos($template, 'archive-') !== false
            && !in_array($template, \Modularity\Options\Archives::getArchiveTemplateSlugs())) {
            $template = explode('-', $template, 2)[0];
            self::$isEditing['template'] = $template;
            $active = isset($options['enabled-areas'][$template]) ? $options['enabled-areas'][$template] : array();
        }

        if (self::$isEditing['title'] == 'archive-post') {
            $home = \Modularity\Helper\Wp::findCoreTemplates(array(
                'home'
            ));

            if ($home) {
                $active = isset($options['enabled-areas']['home']) ? $options['enabled-areas']['home'] : array();
                self::$isEditing['template'] = 'home';
            }
        }

        return $active;
    }
767170
protected function getPageTemplates()
    {
        $choices = [];

        $templates = $this->getContainer()->getParameter('networking_init_cms.page.templates');
        foreach ($templates as $key => $template) {
            $choices[$template['name']] = $key;
        }

        return $choices;
    }
820212
private function getViewsToTreat()
    {
        $templateRepo = $this->entityManager->getRepository('VictoireTemplateBundle:Template');
        $rootTemplates = $templateRepo->getInstance()
            ->where('template.template IS NULL')
            ->getQuery()
            ->getResult();
        $templates = [];
        $recursiveGetTemplates = function ($template) use (&$recursiveGetTemplates, &$templates) {
            array_push($templates, $template);
            foreach ($template->getInheritors() as $_template) {
                if ($_template instanceof Template) {
                    $recursiveGetTemplates($_template);
                }
            }
        };

        foreach ($rootTemplates as $rootTemplate) {
            $recursiveGetTemplates($rootTemplate);
        }

        $pageRepo = $this->entityManager->getRepository('VictoirePageBundle:BasePage');
        $pages = $pageRepo->findAll();
        $errorRepo = $this->entityManager->getRepository('VictoireTwigBundle:ErrorPage');
        $errorPages = $errorRepo->findAll();

        return array_merge($templates, array_merge($pages, $errorPages));
    }
1172618
public function getBlockTypeSets()
    {
        $db = Loader::db();
        $list = array();
        $r = $db->Execute(
                'select btsID from BlockTypeSetBlockTypes where btID = ? order by displayOrder asc',
                array($this->getBlockTypeID()));
        while ($row = $r->FetchRow()) {
            $list[] = BlockTypeSet::getByID($row['btsID']);
        }
        $r->Close();

        return $list;
    }
1293216
public function getBlockTypeComposerTemplates()
    {
        $btHandle = $this->getBlockTypeHandle();
        $files = array();
        $fh = Loader::helper('file');
        $dir = DIR_FILES_BLOCK_TYPES . "/{$btHandle}/" . DIRNAME_BLOCK_TEMPLATES_COMPOSER;
        if (is_dir($dir)) {
            $files = array_merge($files, $fh->getDirectoryContents($dir));
        }
        foreach (PackageList::get()->getPackages() as $pkg) {
            $dir =
                (is_dir(DIR_PACKAGES . '/' . $pkg->getPackageHandle()) ? DIR_PACKAGES : DIR_PACKAGES_CORE)
                . '/' . $pkg->getPackageHandle() . '/' . DIRNAME_BLOCKS . '/' . $btHandle . '/' . DIRNAME_BLOCK_TEMPLATES_COMPOSER;
            if (is_dir($dir)) {
                $files = array_merge($files, $fh->getDirectoryContents($dir));
            }
        }
        $dir = DIR_FILES_BLOCK_TYPES_CORE . "/{$btHandle}/" . DIRNAME_BLOCK_TEMPLATES_COMPOSER;
        if (file_exists($dir)) {
            $files = array_merge($files, $fh->getDirectoryContents($dir));
        }
        $templates = array();
        foreach (array_unique($files) as $file) {
            $templates[] = new TemplateFile($this, $file);
        }

        return TemplateFile::sortTemplateFileList($templates);
    }
1362230
private function getTemplate()
    {
        if ($this->template) {
            return $this->template;
        }

        try {
            $this->template = $this->environment->load($name = $this->config['template']);
        } catch (\Twig_Error $e) {
            throw new Exception\RenderingException("Failed to load $name template.");
        }

        // TODO : hasBlock() does not use template inheritance.

        if (!$this->template->hasBlock('cms_content')) {
            throw new Exception\RenderingException('Unable to find "cms_content" twig block.');
        }
        if (!$this->template->hasBlock('cms_container')) {
            throw new Exception\RenderingException('Unable to find "cms_container" twig block.');
        }
        if (!$this->template->hasBlock('cms_row')) {
            throw new Exception\RenderingException('Unable to find "cms_row" twig block.');
        }
        if (!$this->template->hasBlock('cms_block')) {
            throw new Exception\RenderingException('Unable to find "cms_block" twig block.');
        }

        return $this->template;
    }
715321
protected function fetchBlocks()
    {
        if (null === $this->blocks)
        {
            $this->blocks = array();

            $allBlocks = ContentBlockQuery::create()
                ->find()
            ;

            foreach ($allBlocks as $block)
            {
                /* @var $block ContentBlock */
                $this->blocks[$block->getName()][$block->getLocale()] = $block;
            }
        }
    }
389194
public function buildTemplate()
    {
        if (!empty($this->template)) {
            return $this->template;
        }

        $actions = [];
        foreach ($this->actionBuilders as $actionBuilder) {
            $actions[] = $actionBuilder->buildTemplateAction();
        }

        $this->template = [
            'type' => TemplateType::CONFIRM,
            'text' => $this->text,
            'actions' => $actions,
        ];

        return $this->template;
    }