<commit_before><?php
/**
 * @file
 * LangSwitcher
 *
 * It contains the definition to:
 * @code
final class LangSwitcher;
 * @endcode
 *
 * @author dr.Pavka
 * @copyright Energine 2006
 *
 * @version 1.0.0
 */
namespace Energine\share\components;

use Energine\share\gears\SimpleBuilder, Energine\share\gears\Request, Energine\share\gears\DataDescription, Energine\share\gears\FieldDescription;

/**
 * language switcher.
 *
 * @code
final class LangSwitcher;
 * @endcode
 */
final class LangSwitcher extends DataSet
{
    /**
     * @copydoc DataSet::__construct
     */
    public function __construct($name, array $params = null)
    {
        parent::__construct($name, $params);
        $this->setType(self::COMPONENT_TYPE_LIST);
    }

    /**
     * @copydoc DataSet::createBuilder
     */
    protected function createBuilder()
    {
        return new SimpleBuilder();
    }

    /**
     * @copydoc DataSet::loadData
     */
    protected function loadData()
    {
        $lang = E()->getLanguage();
        $data = $lang->getLanguages();
        foreach ($data as $langID => $langInfo) {
            if (!isset($langInfo['lang_is_active']) || $langInfo['lang_is_active']) {
                $abbr = $langInfo['lang_abbr'];
                if ($langInfo['lang_default']) {
                    $langInfo['lang_abbr'] = '';
                }
                $result[$langID] = $langInfo;
                $result[$langID]['lang_real_abbr'] = $abbr;
                $result[$langID]['lang_id'] = $langID;
                $result[$langID]['lang_url'] = $result[$langID]['lang_abbr'] . (($result[$langID]['lang_abbr']) ? '/' : '') .
                    E()->getRequest()->getPath(Request::PATH_WHOLE, true);
            }
        }
        return $result;
    }

    /**
     * Create data description.
     *
     * @return DataDescription
     */
    protected function createDataDescription()
    {
        $result = new DataDescription();
        $f = new FieldDescription('lang_id');
        $f->setType(FieldDescription::FIELD_TYPE_INT);
        $result->addFieldDescription($f);

        $f = new FieldDescription('lang_abbr');
        $f->setType(FieldDescription::FIELD_TYPE_STRING);
        $result->addFieldDescription($f);

        $f = new FieldDescription('lang_name');
        $f->setType(FieldDescription::FIELD_TYPE_STRING);
        $result->addFieldDescription($f);

        $f = new FieldDescription('lang_url');
        $f->setType(FieldDescription::FIELD_TYPE_STRING);
        $result->addFieldDescription($f);

        $f = new FieldDescription('lang_real_abbr');
        $f->setType(FieldDescription::FIELD_TYPE_STRING);
        $result->addFieldDescription($f);<commit_msg>Lang switcher can use config<commit_after><?php
/**
 * @file
 * LangSwitcher
 *
 * It contains the definition to:
 * @code
final class LangSwitcher;
 * @endcode
 *
 * @author dr.Pavka
 * @copyright Energine 2006
 *
 * @version 1.0.0
 */
namespace Energine\share\components;

use Energine\share\gears\SimpleBuilder, Energine\share\gears\Request, Energine\share\gears\DataDescription, Energine\share\gears\FieldDescription;

/**
 * language switcher.
 *
 * @code
final class LangSwitcher;
 * @endcode
 */
final class LangSwitcher extends DataSet {
    /**
     * @copydoc DataSet::__construct
     */
    public function __construct($name, array $params = NULL) {
        parent::__construct($name, $params);
        $this->setType(self::COMPONENT_TYPE_LIST);
    }

    /**
     * @copydoc DataSet::createBuilder
     */
    protected function createBuilder() {
        return new SimpleBuilder();
    }

    /**
     * @copydoc DataSet::loadData
     */
    protected function loadData() {
        $lang = E()->getLanguage();
        $data = $lang->getLanguages();
        foreach ($data as $langID => $langInfo) {
            if (!isset($langInfo['lang_is_active']) || $langInfo['lang_is_active']) {
                $abbr = $langInfo['lang_abbr'];
                if ($langInfo['lang_default']) {
                    $langInfo['lang_abbr'] = '';
                }
                $result[$langID] = $langInfo;
                $result[$langID]['lang_real_abbr'] = $abbr;
                $result[$langID]['lang_id'] = $langID;
                $result[$langID]['lang_url'] = $result[$langID]['lang_abbr'] . (($result[$langID]['lang_abbr']) ? '/' : '') .
                    E()->getRequest()->getPath(Request::PATH_WHOLE, true);
            }
        }
        return $result;
    }

    /**
     * Create data description.
     *
     * @return DataDescription
     */
    protected function createDataDescription() {
        $result = new DataDescription();
        if (!$this->getConfig()->getCurrentStateConfig()) {
            $f = new FieldDescription('lang_id');
            $f->setType(FieldDescription::FIELD_TYPE_INT);
            $result->addFieldDescription($f);

            $f = new FieldDescription('lang_abbr');
            $f->setType(FieldDescription::FIELD_TYPE_STRING);
            $result->addFieldDescription($f);

            $f = new FieldDescription('lang_name');
            $f->setType(FieldDescription::FIELD_TYPE_STRING);
            $result->addFieldDescription($f);

            $f = new FieldDescription('lang_url');
            $f->setType(FieldDescription::FIELD_TYPE_STRING);
            $result->addFieldDescription($f);

            $f = new FieldDescription('lang_real_abbr');
            $f->setType(FieldDescription::FIELD_TYPE_STRING);
            $result->addFieldDescription($f);
        }
        else {
            $result->loadXML($this->getConfig()->getCurrentStateConfig()->fields);
        }
{'fraction_non_alphanumeric': 0.15091328249689662, 'fraction_numerical': 0.002482709700301472, 'mean_word_length': 2.5009310986964617, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2758433', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1644, 'n_words': 265}