<commit_before><?php
namespace ExampleModule\Controller;

use \QF\Controller,
    \ExampleModule\Entity\Foo,
    \ExampleModule\Form;


class Example extends Controller
{
    //default index, show, create, update, delete actions
    
    public function index($parameter)
    {     
        $t = $this->qf->i18n->get('ExampleModule');
        
        $showPerPage = 20;
        $currentPage = !empty($_GET['p']) ? $_GET['p'] : 1;

        $this->qf->config->page_title = $t->indexTitle(array('page' => $currentPage));
        $this->qf->config->meta_description = $t->indexDescription;

        $entities = Foo::getRepository($this->qf->db->get())->load(null, null, 'id DESC', $showPerPage, ($currentPage - 1) * $showPerPage);
        
        $pager = new \QF\Utils\Pager(
            Foo::getRepository($this->qf->db->get())->count(),
            $showPerPage,
            $this->qf->routing->getUrl('example.index') . '(?p={page})',
            $currentPage,
            7,
            false
        );
        
        return $this->qf->parse('ExampleModule', 'example/index', array('t' => $t, 'entities' => $entities, 'pager' => $pager));
    }
    
    public function show($parameter)
    {
        $t = $this->qf->i18n->get('ExampleModule');
        
        $foo = Foo::getRepository($this->qf->db->get())->loadOne('id', $parameter['id']);
        if (!$foo) {
            return $this->qf->routing->callError(404);
        }
        
        $this->qf->config->page_title = $t->showTitle(array('title' => htmlspecialchars($foo->title)));
        $this->qf->config->meta_description = $t->showDescription(array('title' => htmlspecialchars($foo->title))); 
        
        return $this->qf->parse('ExampleModule', 'example/show', array('t' => $t, 'entity' => $foo));
    }
    
    public function create($parameter)
    {
        $t = $this->qf->i18n->get('ExampleModule');
        
        $this->qf->config->page_title = $t->createTitle;
        $this->qf->config->meta_description = $t->createDescription;
        
        $form = new ExampleForm(array(
            'entity' => new Foo($this->qf->db->get()),
            't' => $t
        ));
        
        $view = array();
        
        $success = false;
        if ($form->validate()) {
            $foo = $form->updateEntity();
            if ($foo->save()) {
                $success = true;
                $message = $t->createSuccessMessage(array('title' => htmlspecialchars($foo->title)));

                if ($this->qf->getConfig('format') === null) {
                    //$this->registry->helper->messages->add($message, 'success');
                    return $this->qf->routing->redirect($this->qf->routing->getUrl('example.show', array('id' => $foo->id)));
                }
                
                $view['message'] = $message;
                $view['entity'] = $foo;
            } else {
                $form->setError($t->createErrorMessage);
            }
        }

        $view['success'] = $success;
        $view['form'] = $form;
        
        $view['t'] = $t;
        
        return $this->qf->parse('ExampleModule', 'example/create', $view);
    }
    
    public function update($parameter)
    {
        $t = $this->qf->i18n->get('ExampleModule');
        
        $foo = Foo::getRepository($this->qf->db->get())->loadOne('id', $parameter['id']);
        if (!$foo) {
            return $this->qf->routing->callError(404);
        }
        
        $this->qf->config->page_title = $t->updateTitle;
        $this->qf->config->meta_description = $t->updateDescription;

        $form = new ExampleForm(array(
            'entity' => $foo,
            't' => $t
        ));
        
        $view = array();
        
        $success = false;
        if ($form->validate()) {
            $foo = $form->updateEntity();
            if ($foo->save()) {
                $success = true;
                $message = $t->updateSuccessMessage(array('title' => htmlspecialchars($foo->title)));

                if ($this->qf->getConfig('format') === null) {
                    //$this->registry->helper->messages->add($message, 'success');
                    return $this->qf->routing->redirect($this->qf->routing->getUrl('example.show', array('id' => $foo->id)));<commit_msg>updated example controller to use CacheQueue (not added yet)<commit_after><?php
namespace ExampleModule\Controller;

use \QF\Controller,
    \ExampleModule\Entity\Foo,
    \ExampleModule\Form;


class Example extends Controller
{
    //default index, show, create, update, delete actions
    
    public function index($parameter)
    {     
        $cacheKey = serialize(array(
            $this->qf->getConfig('current_route'),
            $this->qf->getConfig('current_route_parameter'),
            $this->qf->getConfig('request_method'),
        ));
        return $this->qf->cache->getOrSet('view_'.md5($cacheKey), function($parameter) {  
            $t = $this->qf->i18n->get('ExampleModule');
        
            $showPerPage = 20;
            $currentPage = !empty($_GET['p']) ? $_GET['p'] : 1;

            $this->qf->config->page_title = $t->indexTitle(array('page' => $currentPage));
            $this->qf->config->meta_description = $t->indexDescription;

            $entities = Foo::getRepository($this->qf->db->get())->load(null, null, 'id DESC', $showPerPage, ($currentPage - 1) * $showPerPage);

            $pager = new \QF\Utils\Pager(
                Foo::getRepository($this->qf->db->get())->count(),
                $showPerPage,
                $this->qf->routing->getUrl('example.index') . '(?p={page})',
                $currentPage,
                7,
                false
            );

            return $this->qf->parse('ExampleModule', 'example/index', array('t' => $t, 'entities' => $entities, 'pager' => $pager));
            
        }, $parameter, 60*60, false, array('view', 'view_Example', 'view_Example_index'));
            
    }
    
    public function show($parameter)
    {
        $cacheKey = serialize(array(
            $this->qf->getConfig('current_route'),
            $this->qf->getConfig('current_route_parameter'),
            $this->qf->getConfig('request_method'),
        ));
        return $this->qf->cache->getOrSet('view_'.md5($cacheKey), function($parameter) {  
            $t = $this->qf->i18n->get('ExampleModule');

            $foo = Foo::getRepository($this->qf->db->get())->loadOne('id', $parameter['id']);
            if (!$foo) {
                return $this->qf->routing->callError(404);
            }

            $this->qf->config->page_title = $t->showTitle(array('title' => htmlspecialchars($foo->title)));
            $this->qf->config->meta_description = $t->showDescription(array('title' => htmlspecialchars($foo->title))); 

            return $this->qf->parse('ExampleModule', 'example/show', array('t' => $t, 'entity' => $foo));
        }, $parameter, 60*60, false, array('view', 'view_Example', 'view_Example_show', 'view_Example_show_'.$parameter['id']));   
    }
    
    public function create($parameter)
    {
        $t = $this->qf->i18n->get('ExampleModule');
        
        $this->qf->config->page_title = $t->createTitle;
        $this->qf->config->meta_description = $t->createDescription;
        
        $form = new ExampleForm(array(
            'entity' => new Foo($this->qf->db->get()),
            't' => $t
        ));
        
        $view = array();
        
        $success = false;
        if ($form->validate()) {
            $foo = $form->updateEntity();
            if ($foo->save()) {
                $success = true;
                $message = $t->createSuccessMessage(array('title' => htmlspecialchars($foo->title)));

                if ($this->qf->getConfig('format') === null) {
                    //$this->registry->helper->messages->add($message, 'success');
                    return $this->qf->routing->redirect($this->qf->routing->getUrl('example.show', array('id' => $foo->id)));
                }
                
                $view['message'] = $message;
                $view['entity'] = $foo;
            } else {
                $form->setError($t->createErrorMessage);
            }
        }

        $view['success'] = $success;
        $view['form'] = $form;
        
        $view['t'] = $t;
        
        return $this->qf->parse('ExampleModule', 'example/create', $view);
    }
    
    public function update($parameter)
    {
        $t = $this->qf->i18n->get('ExampleModule');
        
        $foo = Foo::getRepository($this->qf->db->get())->loadOne('id', $parameter['id']);
        if (!$foo) {
            return $this->qf->routing->callError(404);
        }
        
        $this->qf->config->page_title = $t->updateTitle;
        $this->qf->config->meta_description = $t->updateDescription;

        $form = new ExampleForm(array(
            'entity' => $foo,
            't' => $t
        ));
        
        $view = array();
        
        $success = false;
        if ($form->validate()) {
            $foo = $form->updateEntity();
            if ($foo->save()) {
                $this->qf->cache->outdateByTag('view_Example_show_'.$parameter['id']);
                $success = true;
                $message = $t->updateSuccessMessage(array('title' => htmlspecialchars($foo->title)));

                if ($this->qf->getConfig('format') === null) {
                    //$this->registry->helper->messages->add($message, 'success');
                    return $this->qf->routing->redirect($this->qf->routing->getUrl('example.show', array('id' => $foo->id)));
{'fraction_non_alphanumeric': 0.19391476503073876, 'fraction_numerical': 0.005001562988433885, 'mean_word_length': 2.000312597686777, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 292, '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': '5441219', 'n_tokens_mistral': 2906, 'n_tokens_neox': 2828, 'n_words': 419}