<?php
/**
 * Created by PhpStorm.
 * User: eater
 * Date: 4/2/16
 * Time: 9:27 PM
 */

namespace Eater\Glim\Handler;


use Eater\Glim\Model\Server;
use Eater\Glim\Model\ServerQuery;

class Panel extends Session
{
    protected $shouldHaveUser = true;

    public function handle()
    {
        $superuser = $this->getUser()->getSuperuser();

        $vars = [
            'superuser' => $superuser,
            'servers'   => $this->fetchServers()
        ];

        if ($superuser) {
            $vars['registeredServers'] = $this->fetchServers('registered');
        }

        return $this->render('panel.html.twig', $vars);
    }

    public function fetchServers($status = "signed")
    {
        return ServerQuery::create()->filterByStatus($status)->find();
    }
}