jablonka.czprosek.czf

freenet-router

Subversion Repositories:
[/] [trunk/] [freenet-router/] [var/] [www/] [freenet-router/] [Framework/] [Controllers/] [SimpleViewController.php] - Rev 2

Compare with Previous - Blame - Download


<?php

namespace Phem\Controllers;

use Phem\Controllers\Controller;
use Phem\Core\Collection;
use Phem\Environment\EnvironmentManager;
use Phem\Environment\ResourceType;
use Phem\Libraries\Security\Model\MySQL\User;
use Phem\Views\SimpleView;

/**
 *
 * @author kubapet
 */
abstract class SimpleViewController extends Controller
{

    /** @var Collection */
    protected $model;
    protected $template;

    /** @var Boolean */
    protected $renderTemplate = true;
    private $view;

    function __construct()
    {
        parent::__construct();
        $this->model = new Collection();
    }

    public function getModel()
    {
        return $this->model;
    }

    public function setModel($model)
    {
        $this->model = $model;
    }

    public function getTemplate()
    {
        return $this->template;
    }

    public function setTemplate($template)
    {
        $this->template = $template;
    }

    public function getRenderTemplate()
    {
        return $this->renderTemplate;
    }

    public function setRenderTemplate($renderTemplate)
    {
        $this->renderTemplate = $renderTemplate;
    }

    function execute($task)
    {
        parent::execute($task);
        if (($this->redirectToController != null) || ($this->redirectToTask != null))
        {
            return;
        }


        if ($task == null)
        {
            $task = $this->defaultTask;
        }

        $classPathArray = explode('\\', get_class($this));
        $classShortName = end($classPathArray);

        if ($this->template == null)
        {
            $this->template = str_replace("Controller", "", $classShortName) . DS . $task . ".twig";
        }


        if ($this->loggedUser == "guest")
        {
            $user = new User();
            $user->setUsername($this->loggedUser);
            $this->model->put("loggedUser", $user);
        }
        else if ($this->loggedUser != null)
        {
            $user = EnvironmentManager::getUserManager()->getUser($this->loggedUser);          
            $this->model->put("loggedUser", $user);
        }   
        
        
        $this->model->put("styles", EnvironmentManager::getResourceManager()
                ->getResourcePathCollection(ResourceType::CSS));
        $this->model->put("scripts", EnvironmentManager::getResourceManager()
                ->getResourcePathCollection(ResourceType::JS));
        $this->model->put("controller", str_replace("Controller", "", $classShortName));
        $this->model->put("task", $task);
        $this->model->put("requestUrl", $_SERVER["REQUEST_URI"]);
        $this->model->put("lb", EnvironmentManager::getLinkBuilder());
        $this->model->put("httpHost", $_SERVER["HTTP_HOST"]);
        $this->model->put("pathPrefix", SITE_SUBDIR);
        $this->model->put("sessionId", EnvironmentManager::getSession()->getId());

        if ($this->renderTemplate)
        {
            $this->view = new SimpleView($this->template, $this->model);
            $this->view->display();
        }
    }

}

Powered by WebSVN 2.2.1