<commit_before><?php

/**
 * This file is part of Nepttune (https://www.peldax.com)
 *
 * Copyright (c) 2018 <NAME> (<EMAIL>)
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the MIT license. For more information, see
 * <https://www.peldax.com>.
 */

declare(strict_types = 1);

namespace Nepttune\Presenter;

abstract class BasePresenter extends \Nette\Application\UI\Presenter implements \Nepttune\ITranslator
{
    use \IPub\MobileDetect\TMobileDetect;
    use \Nepttune\TTranslator;

    /** @persistent */
    public $locale;

    /**
     * @inject
     * @var  \Nepttune\Component\IAssetLoaderFactory
     */
    public $iAssetLoaderFactory;

    /** @var  array */
    protected $meta;

    /** @var  array */
    protected $dest;

    public function injectParameters(array $meta, array $dest)
    {
        $this->meta = $meta;
        $this->dest = $dest;
    }

    protected function beforeRender()
    {
        $this->template->meta = $this->meta;
        $this->template->dest = $this->dest;

        parent::beforeRender();
    }

    public function flashMessage($message, $type = 'info') : \stdClass
    {
        $flash = parent::flashMessage($message, $type);

        if ($this->isAjax())
        {
            $this->redrawControl('flashMessages');
        }

        return $flash;
    }

    public function createComponent($name, array $args = null)
    {
        if (method_exists($this, 'createComponent'.ucfirst($name)))
        {
            return parent::createComponent($name);
        }

        if ($args !== null)
        {
            return $this->context->createService($name, $args);
        }

        return $this->context->createService($name);
    }

    public function actionCloseFancy($control = null, $rowId = null) : void
    {
        $this->getFlashSession()->setExpiration(time() + 5);

        $this->template->setFile(__DIR__.'/../templates/closeFancy.latte');

        $this->template->redrawControl = false;
        $this->template->redrawRow = false;

        if ($control && $rowId)
        {
            $this->template->redrawRow = true;
            $this->template->control = $control;
            $this->template->rowId = $rowId;
        }
        elseif ($control)
        {
            $this->template->redrawControl = true;
            $this->template->control = $control;
        }
    }

    public function getModule() : string
    {
        return substr($this->getName(), 0, strpos($this->getName(), ':'));
    }

    public function getNameWM() : string
    {
        if (strpos($this->getName(), ':') === false)
        {
            return $this->getName();
        }

        return substr($this->getName(), strpos($this->getName(), ':') + 1);
    }

    public function getId() : int
    {
        return (int) $this->getParameter('id');
    }
    
    public function findLayoutTemplateFile() : string
    {
        if ($this->layout)
        {
            return $this->layout;
        }
        
        $dir = \dirname(static::getReflection()->getFileName());
        $primary = $dir . '/../templates/@layout.latte';

        if (is_file($primary))
        {
            return $primary;
        }

        return static::getDefaultLayout();
    }

    public static function getDefaultLayout() : string
    {
        return static::getCoreLayout();
    }

    public static function getAjaxLayout() : string<commit_msg>Update BasePresenter.php<commit_after><?php

/**
 * This file is part of Nepttune (https://www.peldax.com)
 *
 * Copyright (c) 2018 <NAME> (<EMAIL>)
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the MIT license. For more information, see
 * <https://www.peldax.com>.
 */

declare(strict_types = 1);

namespace Nepttune\Presenter;

abstract class BasePresenter extends \Nette\Application\UI\Presenter implements \Nepttune\ITranslator
{
    use \IPub\MobileDetect\TMobileDetect;
    use \Nepttune\TTranslator;

    /** @persistent */
    public $locale;

    /** @var  string */
    public $module;

    /** @var  string */
    public $nameWM;

    /** @var  \Nepttune\Component\IAssetLoaderFactory */
    protected $iAssetLoaderFactory;

    /** @var  array */
    protected $meta;

    /** @var  array */
    protected $dest;

    public function injectParameters(array $meta, array $dest, \Nepttune\Component\IAssetLoaderFactory $IAssetLoaderFactory)
    {
        $this->meta = $meta;
        $this->dest = $dest;
        $this->iAssetLoaderFactory = $IAssetLoaderFactory;
    }
    
    protected function startup()
    {
        $pos = strpos($this->getName(), ':');

        $this->module = $pos === false ? '' :               substr($this->getName(), 0, $pos);
        $this->nameWM = $pos === false ? $this->getName() : substr($this->getName(), $pos + 1);

        parent::startup();
    }

    protected function beforeRender()
    {
        $this->template->meta = $this->meta;
        $this->template->dest = $this->dest;

        parent::beforeRender();
    }

    public function flashMessage($message, $type = 'info') : \stdClass
    {
        $flash = parent::flashMessage($message, $type);

        if ($this->isAjax())
        {
            $this->redrawControl('flashMessages');
        }

        return $flash;
    }

    public function createComponent($name, array $args = null)
    {
        if (method_exists($this, 'createComponent'.ucfirst($name)))
        {
            return parent::createComponent($name);
        }

        if ($args !== null)
        {
            return $this->context->createService($name, $args);
        }

        return $this->context->createService($name);
    }

    public function actionCloseFancy($control = null, $rowId = null) : void
    {
        $this->getFlashSession()->setExpiration(time() + 5);

        $this->template->setFile(__DIR__.'/../templates/closeFancy.latte');

        $this->template->redrawControl = false;
        $this->template->redrawRow = false;

        if ($control && $rowId)
        {
            $this->template->redrawRow = true;
            $this->template->control = $control;
            $this->template->rowId = $rowId;
        }
        elseif ($control)
        {
            $this->template->redrawControl = true;
            $this->template->control = $control;
        }
    }

    public function getModule() : string
    {
        return $this->module;
    }

    public function getNameWM() : string
    {
        return $this->nameWM;
    }

    public function getId() : int
    {
        return (int) $this->getParameter('id');
    }
    
    public function findLayoutTemplateFile() : string
    {
        if ($this->layout)
        {
            return $this->layout;
        }
        
        $dir = \dirname(static::getReflection()->getFileName());
        $primary = $dir . '/../templates/@layout.latte';

        if (is_file($primary))
        {
            return $primary;
        }

        return static::getDefaultLayout();
    }

    public static function getDefaultLayout() : string
    {
        return static::getCoreLayout();
    }

    public static function getAjaxLayout() : string
{'fraction_non_alphanumeric': 0.1471076667589261, 'fraction_numerical': 0.0022142264046498754, 'mean_word_length': 2.1655716162943497, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 96, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, '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': '1984505', 'n_tokens_mistral': 2139, 'n_tokens_neox': 2060, 'n_words': 431}