<?php

use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\Factory;

// No direct access.
defined('_JEXEC') or die;

JLoader::register("ClubsControllerPosition", JPATH_ROOT . "/administrator/components/com_clubs/controllers/position.php");

class ClubsViewClubPosition extends HtmlView
{

    function display($tpl = null)
    {
        $input = Factory::getApplication()->input->get;
        $positonFactory = new CommonClubsModelFactoryPosition();
        $userFactory = new CommonClubsModelFactoryUser();
        $this->positions = $positonFactory->loadElements();
        $this->users = $userFactory->loadElements();
        
        $id = $input->getCmd('id', 'new');
        $assocFactory = new CommonClubsModelFactoryUserassoc();
        
        if($id !== 'new')
        {
            $id = (int) $id;
            
            $this->assoc = $assocFactory->loadById($id);
        }
        else
        {
            $this->assoc = $assocFactory->createNew();
        }
        
        $this->id = $id;
        $this->clubid = $input->getInt('club');
        
        $this->username = '<i>Derzeit vakant.</i>';
        $this->usercity = '';
        if($this->assoc->getUser() !== null)
        {
            $u = $this->assoc->getUser();
            $this->username = htmlentities($u->getName());
            $this->usercity = htmlentities($u->getCity());
        }
        
        parent::display($tpl);
        
        jexit();
    }
    protected function getControllerName()
    {
        return 'position';
    }

    protected function getFactory()
    {
        return new CommonClubsModelFactoryPosition();
    }

}