<commit_before><?php
/*
 * This file is part of the AlphaLemon CMS Application and it is distributed
 * under the GPL LICENSE Version 2.0. To use this application you must leave
 * intact this copyright notice.
 *
 * Copyright (c) AlphaLemon <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * For extra documentation and help please visit http://www.alphalemon.com
 * 
 * @license    GPL LICENSE Version 2.0
 * 
 */

namespace AlphaLemon\AlphaLemonCmsBundle\Core\Form\ModelChoiceValues;

use Symfony\Component\Finder\Finder;
use AlphaLemon\AlphaLemonCmsBundle\Core\Repository\AlThemeQuery;
use AlphaLemon\AlphaLemonCmsBundle\Core\Repository\AlPageQuery;

use AlphaLemon\AlphaLemonCmsBundle\Core\Repository\AlLanguageQuery;
use AlphaLemon\ThemeEngineBundle\Core\Autoloader\Base\BundlesAutoloaderComposer;
use AlphaLemon\AlphaLemonCmsBundle\Core\Repository\Repository\PageRepositoryInterface;
use AlphaLemon\AlphaLemonCmsBundle\Core\Repository\Repository\LanguageRepositoryInterface;
use AlphaLemon\AlphaLemonCmsBundle\Core\Repository\Repository\ThemeRepositoryInterface;

/**
 * Retrieves form the database the values used in the forms
 *
 * @author alphalemon <<EMAIL>>
 */
class ChoiceValues
{
    public static function getPages(PageRepositoryInterface $pageRepository, $withNoneOption = true)
    {
        $result = array();
        if($withNoneOption) $pages["none"] = " ";
        $pages = $pageRepository->activePages();
        foreach($pages as $page)
        {
            $result[$page->getId()] = $page->getPageName();
        }

        return $result;
    }

    public static function getLanguages(LanguageRepositoryInterface $languageRepository, $withNoneOption = true)
    {
        $result = array();
        if($withNoneOption) $languages["none"] = " ";
        $languages = $languageRepository->activeLanguages();
        foreach($languages as $language)
        {
            $result[$language->getId()] = $language->getLanguage();
        }

        return $result;
    }

    public static function getTemplates(ThemeRepositoryInterface $themeRepository)
    {
        // Default templates
        $templates = array("none" => " ");
        
        // Find the current active theme
        $theme = $themeRepository->activeBackend(); 
        if(null === $theme) return $templates;
        
        $composer = new BundlesAutoloaderComposer('AlphaLemon\\Theme' );
        $bundles = $composer->getBundles();  
        
        // Retrieves the path for the current theme
        $themeNamespace = 'AlphaLemon\\Theme\\' . $theme->getThemeName();
        if(!array_key_exists($themeNamespace, $bundles)) return $templates;        
        $themeDir = $bundles[$themeNamespace];
        
        // Points the templates' folder and retrieve the templates
        $templatesPath = sprintf('%s/Resources/views/Theme', $themeDir);
        $finder = new Finder();
        $templateFiles = $finder->files()->name('*.twig')->depth(0)->sortByName()->in($templatesPath);

        foreach($templateFiles as $templateFile)
        {
            $info = pathinfo($templateFile);
            $templateName = basename($info['filename'], '.html');
            $templates[$templateName] = $templateName;
        }

        return $templates;
    }
}<commit_msg>updated the retrieving of templates' theme<commit_after><?php
/*
 * This file is part of the AlphaLemon CMS Application and it is distributed
 * under the GPL LICENSE Version 2.0. To use this application you must leave
 * intact this copyright notice.
 *
 * Copyright (c) AlphaLemon <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * For extra documentation and help please visit http://www.alphalemon.com
 * 
 * @license    GPL LICENSE Version 2.0
 * 
 */

namespace AlphaLemon\AlphaLemonCmsBundle\Core\Form\ModelChoiceValues;

use Symfony\Component\Finder\Finder;
use AlphaLemon\AlphaLemonCmsBundle\Core\Repository\AlThemeQuery;
use AlphaLemon\AlphaLemonCmsBundle\Core\Repository\AlPageQuery;

use AlphaLemon\AlphaLemonCmsBundle\Core\Repository\AlLanguageQuery;
use AlphaLemon\ThemeEngineBundle\Core\Autoloader\Base\BundlesAutoloaderComposer;
use AlphaLemon\AlphaLemonCmsBundle\Core\Repository\Repository\PageRepositoryInterface;
use AlphaLemon\AlphaLemonCmsBundle\Core\Repository\Repository\LanguageRepositoryInterface;
use AlphaLemon\AlphaLemonCmsBundle\Core\Repository\Repository\ThemeRepositoryInterface;

/**
 * Retrieves form the database the values used in the forms
 *
 * @author alphalemon <<EMAIL>>
 */
class ChoiceValues
{
    public static function getPages(PageRepositoryInterface $pageRepository, $withNoneOption = true)
    {
        $result = array();
        if($withNoneOption) $pages["none"] = " ";
        $pages = $pageRepository->activePages();
        foreach($pages as $page)
        {
            $result[$page->getId()] = $page->getPageName();
        }

        return $result;
    }

    public static function getLanguages(LanguageRepositoryInterface $languageRepository, $withNoneOption = true)
    {
        $result = array();
        if($withNoneOption) $languages["none"] = " ";
        $languages = $languageRepository->activeLanguages();
        foreach($languages as $language)
        {
            $result[$language->getId()] = $language->getLanguage();
        }

        return $result;
    }

    public static function getTemplates(ThemeRepositoryInterface $themeRepository, \AlphaLemon\ThemeEngineBundle\Core\ThemesCollection\AlThemesCollection $themes)
    {
        $alTheme = $themeRepository->activeBackend();
        $theme = $themes->getTheme($alTheme->getThemeName());
        
        $templates = array("none" => " ");
        foreach($theme as $template)
        {
            $templateName = $template->getTemplateName();
            $templates[$templateName] = $templateName;
        }
        
        return $templates;
    }
}
{'fraction_non_alphanumeric': 0.11087208340228363, 'fraction_numerical': 0.0014893264934635116, 'mean_word_length': 3.3326164874551973, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4744773', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1631, 'n_words': 376}