<commit_before><?php

namespace Arch\Factory;

/**
 * GenericView factory
 * 
 * Use this to create a new generic view
 *
 * @author mafonso
 */
class GenericView extends \Arch\IFactory
{
    /**
     * Holds the application
     * @var \Arch\App
     */
    protected $app;
    
    /**
     * Returns a new Generic view factory
     * @param \Arch\App $app
     */
    public function __construct(\Arch\App $app) {
        $this->app = $app;
    }

    /**
     * Returns a generic view
     * @return \Arch\IView
     */
    protected function fabricate($type) {
        $type = (string) $type;
        $pattern = implode(
            DIRECTORY_SEPARATOR,
            array(ARCH_PATH, 'src', 'Arch', 'View', '*.php')
        );
        $available = glob($pattern);
        array_walk($available, function(&$item) {
            $item = str_replace('.php', '', basename($item));
        });
        if (!in_array($type, $available)) {
            throw new \Exception(
                'Invalid generic view type. '
                .'Use one of the following strings: '.implode(', ', $available)
            );
        }
        $method_name = 'create'.$type;
        return $this->{$method_name}();
    }
    
    /**
     * Returns a new date picker view.
     * 
     * You should use your own template. Copy the default template from
     * <b>vendor/taviroquai/architectphp/theme/</b> to your module directory
     * 
     * @return \Arch\View\DatePicker
     */
    public function createDatePicker()
    {
        $view = new \Arch\View\DatePicker();
        // add view resources
        $this->app->getTheme()->addContent(
            $this->app->getHelperFactory()
                ->createURL('/arch/asset/css/bootstrap-datetimepicker.min.css'),
            'css'
        );
        $this->app->getTheme()->addContent(
            $this->app->getHelperFactory()
                ->createURL('/arch/asset/js/bootstrap-datetimepicker.min.js'),
            'js'
        );
        return $view;
    }
    
    /**
     * Returns a new file upload view.
     * 
     * You should use your own template. Copy the default template from
     * <b>vendor/taviroquai/architectphp/theme/</b> to your module directory
     * 
     * @return \Arch\View\FileUpload
     */
    public function createFileUpload()
    {
        $view = new \Arch\View\FileUpload();
        $view->set(
            'default_img',
            $this->app->getHelperFactory()
                ->createURL('/arch/asset/img/placehold-thumb.gif')
        );
        // add view resources
        $this->app->getTheme()->addContent(
            $this->app->getHelperFactory()
                ->createURL('/arch/asset/css/bootstrap-fileupload.min.css'),
            'css'
        );
        $this->app->getTheme()->addContent(
            $this->app->getHelperFactory()
                ->createURL('/arch/asset/js/bootstrap-fileupload.min.js'),
            'js'
        );
        return $view;
    }
    
    /**
     * Returns a new pagination view.
     * 
     * You should use your own template. Copy the default template from
     * <b>vendor/taviroquai/architectphp/theme/</b> to your module directory
     * 
     * @return \Arch\View\Pagination
     */
    public function createPagination()
    {
        $view = new \Arch\View\Pagination();
        $view->setInput($this->app->getInput());
        $view->id = 'p1';
        $view->parseCurrent();
        return $view;
    }
    
    /**
     * Creates a new text editor view.
     * 
     * You should use your own template. Copy the default template from
     * <b>vendor/taviroquai/architectphp/theme/</b> to your module directory
     * 
     * @return \Arch\View\TextEditor
     */
    public function createTextEditor()
    {
        $view = new \Arch\View\TextEditor();
        // add view resources
        $this->app->getTheme()->addContent(
            $this->app->getHelperFactory()
                ->createURL('/arch/asset/css/font-awesome.min.css'),
            'css'
        );
        $this->app->getTheme()->addContent(
            $this->app->getHelperFactory()
                ->createURL('/arch/asset/css/wysiwyg.css'),
            'css'
        );
        $this->app->getTheme()->addContent(
            $this->app->getHelperFactory()
                ->createURL('/arch/asset/js/jquery.hotkeys.js'),
            'js'
        );
        $this->app->getTheme()->addContent(
            $this->app->getHelperFactory()
                ->createURL('/arch/asset/js/bootstrap-wysiwyg.js'),
            'js'
        );
        return $view;
    }
    
    /**
     * Returns an anti-spam view.
     * 
     * You should use your own template. Copy the default template from
     * <b>vendor/taviroquai/architectphp/theme/</b> to your module directory
     * 
     * @return \Arch\View
     */
    public function createAntiSpam()
    {
        $view = new \Arch\View\AntiSpam();
        $view->setSession($this->app->getSession());
        $view->setInput($this->app->getInput());
        return $view;
    }
    
    /**
     * Returns a new breadcrumb view.
     * 
     * You should use your own template. Copy the default template from
     * <b>vendor/taviroquai/architectphp/theme/</b> to your module directory
     * 
     * @param boolena $parseInput Tells to insert items from input
     * @return \Arch\View\Breadcrumbs
     */
    public function createBreadcrumbs()
    {
        return new \Arch\View\Breadcrumbs();
    }
    
    /**
     * Returns a new carousel view.
     * 
     * You should use your own template. Copy the default template from
     * <b>vendor/taviroquai/architectphp/theme/</b> to your module directory
     * 
     * @return \Arch\View\Carousel
     */
    public function createCarousel()
    {
        $view = new \Arch\View\Carousel();
        $this->app->getTheme()->addContent(
            $this->app->getHelperFactory()<commit_msg>Parse input action by default when creating a breadcrumb view. The user can always remove items later.<commit_after><?php

namespace Arch\Factory;

/**
 * GenericView factory
 * 
 * Use this to create a new generic view
 *
 * @author mafonso
 */
class GenericView extends \Arch\IFactory
{
    /**
     * Holds the application
     * @var \Arch\App
     */
    protected $app;
    
    /**
     * Returns a new Generic view factory
     * @param \Arch\App $app
     */
    public function __construct(\Arch\App $app) {
        $this->app = $app;
    }

    /**
     * Returns a generic view
     * @return \Arch\IView
     */
    protected function fabricate($type) {
        $type = (string) $type;
        $pattern = implode(
            DIRECTORY_SEPARATOR,
            array(ARCH_PATH, 'src', 'Arch', 'View', '*.php')
        );
        $available = glob($pattern);
        array_walk($available, function(&$item) {
            $item = str_replace('.php', '', basename($item));
        });
        if (!in_array($type, $available)) {
            throw new \Exception(
                'Invalid generic view type. '
                .'Use one of the following strings: '.implode(', ', $available)
            );
        }
        $method_name = 'create'.$type;
        return $this->{$method_name}();
    }
    
    /**
     * Returns a new date picker view.
     * 
     * You should use your own template. Copy the default template from
     * <b>vendor/taviroquai/architectphp/theme/</b> to your module directory
     * 
     * @return \Arch\View\DatePicker
     */
    public function createDatePicker()
    {
        $view = new \Arch\View\DatePicker();
        // add view resources
        $this->app->getTheme()->addContent(
            $this->app->getHelperFactory()
                ->createURL('/arch/asset/css/bootstrap-datetimepicker.min.css'),
            'css'
        );
        $this->app->getTheme()->addContent(
            $this->app->getHelperFactory()
                ->createURL('/arch/asset/js/bootstrap-datetimepicker.min.js'),
            'js'
        );
        return $view;
    }
    
    /**
     * Returns a new file upload view.
     * 
     * You should use your own template. Copy the default template from
     * <b>vendor/taviroquai/architectphp/theme/</b> to your module directory
     * 
     * @return \Arch\View\FileUpload
     */
    public function createFileUpload()
    {
        $view = new \Arch\View\FileUpload();
        $view->set(
            'default_img',
            $this->app->getHelperFactory()
                ->createURL('/arch/asset/img/placehold-thumb.gif')
        );
        // add view resources
        $this->app->getTheme()->addContent(
            $this->app->getHelperFactory()
                ->createURL('/arch/asset/css/bootstrap-fileupload.min.css'),
            'css'
        );
        $this->app->getTheme()->addContent(
            $this->app->getHelperFactory()
                ->createURL('/arch/asset/js/bootstrap-fileupload.min.js'),
            'js'
        );
        return $view;
    }
    
    /**
     * Returns a new pagination view.
     * 
     * You should use your own template. Copy the default template from
     * <b>vendor/taviroquai/architectphp/theme/</b> to your module directory
     * 
     * @return \Arch\View\Pagination
     */
    public function createPagination()
    {
        $view = new \Arch\View\Pagination();
        $view->setInput($this->app->getInput());
        $view->id = 'p1';
        $view->parseCurrent();
        return $view;
    }
    
    /**
     * Creates a new text editor view.
     * 
     * You should use your own template. Copy the default template from
     * <b>vendor/taviroquai/architectphp/theme/</b> to your module directory
     * 
     * @return \Arch\View\TextEditor
     */
    public function createTextEditor()
    {
        $view = new \Arch\View\TextEditor();
        // add view resources
        $this->app->getTheme()->addContent(
            $this->app->getHelperFactory()
                ->createURL('/arch/asset/css/font-awesome.min.css'),
            'css'
        );
        $this->app->getTheme()->addContent(
            $this->app->getHelperFactory()
                ->createURL('/arch/asset/css/wysiwyg.css'),
            'css'
        );
        $this->app->getTheme()->addContent(
            $this->app->getHelperFactory()
                ->createURL('/arch/asset/js/jquery.hotkeys.js'),
            'js'
        );
        $this->app->getTheme()->addContent(
            $this->app->getHelperFactory()
                ->createURL('/arch/asset/js/bootstrap-wysiwyg.js'),
            'js'
        );
        return $view;
    }
    
    /**
     * Returns an anti-spam view.
     * 
     * You should use your own template. Copy the default template from
     * <b>vendor/taviroquai/architectphp/theme/</b> to your module directory
     * 
     * @return \Arch\View
     */
    public function createAntiSpam()
    {
        $view = new \Arch\View\AntiSpam();
        $view->setSession($this->app->getSession());
        $view->setInput($this->app->getInput());
        return $view;
    }
    
    /**
     * Returns a new breadcrumb view.
     * 
     * You should use your own template. Copy the default template from
     * <b>vendor/taviroquai/architectphp/theme/</b> to your module directory
     * 
     * @param boolena $parseInput Tells to insert items from input
     * @return \Arch\View\Breadcrumbs
     */
    public function createBreadcrumbs()
    {
        $view = new \Arch\View\Breadcrumbs();
        $view->parseAction($this->app);
        return $view;
    }
    
    /**
     * Returns a new carousel view.
     * 
     * You should use your own template. Copy the default template from
     * <b>vendor/taviroquai/architectphp/theme/</b> to your module directory
     * 
     * @return \Arch\View\Carousel
     */
    public function createCarousel()
    {
        $view = new \Arch\View\Carousel();
        $this->app->getTheme()->addContent(
            $this->app->getHelperFactory()
{'fraction_non_alphanumeric': 0.14010347129506007, 'fraction_numerical': 0.00016688918558077436, 'mean_word_length': 1.7969661610268377, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 173, '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': '3808894', 'n_tokens_mistral': 3536, 'n_tokens_neox': 3491, 'n_words': 752}