Added backend for position of persons

This commit is contained in:
2019-04-17 15:04:24 +02:00
parent e801770b80
commit 22566986a8
7 changed files with 463 additions and 0 deletions

View File

@@ -0,0 +1,108 @@
<?php
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Router\Route;
// No direct access.
defined('_JEXEC') or die;
class ClubsControllerPosition extends BaseController
{
function new()
{
$app = Factory::getApplication();
$input = $app->input;
$p = ClubsPosition::createPosition();
// Fetch the posted data
$name = $input->post->getString('name');
// Check the input data
$error = false;
// Check existence of the other fields
$fields = array('name'=>'Bezeichnung');
foreach ($fields as $f => $fname)
{
$fvalue = $$f;
if(! isset($fvalue) || empty(trim($fvalue)))
{
$app->enqueueMessage("Das Feld $fname ist obligatorisch.", 'error');
$error = true;
}
}
if($error)
{
$data = array();
foreach(array('name') as $i)
$data[$i] = $$i;
$urldata = urlencode(json_encode($data));
$this->setRedirect(Route::_('index.php?option=com_clubs&view=position&id=new&data=' . $urldata, false));
return;
}
$p->setName($name);
// Do the actual work
$p->save();
$this->setRedirect(Route::_('index.php?option=com_clubs&view=positions', false));
}
function change()
{
$app = Factory::getApplication();
$input = $app->input;
$id = (int) $input->post->getInt('id');
$p = ClubsPosition::loadPosition((int) $id);
// Fetch the posted data
$name = $input->post->getString('name');
// Check the input data
$error = false;
// Check existence of the other fields
$fields = array('name'=>'Bezeichnung');
foreach ($fields as $f => $fname)
{
$fvalue = $$f;
if(! isset($fvalue) || empty(trim($fvalue)))
{
$app->enqueueMessage("Das Feld $fname ist obligatorisch.", 'error');
$error = true;
}
}
if($error)
{
$data = array();
foreach(array('name') as $i)
$data[$i] = $$i;
$urldata = urlencode(json_encode($data));
$this->setRedirect(Route::_('index.php?option=com_clubs&view=offer&id=' . $id . '&data=' . $urldata, false));
return;
}
$p->setName($name);
// Do the actual work
$p->save();
$this->setRedirect(Route::_('index.php?option=com_clubs&view=positions', false));
}
function delete()
{
$app = Factory::getApplication();
$id = $app->input->get->getInt('id');
$app->enqueueMessage("Removal of position with id $id.");
$user = ClubsPosition::loadPosition($id);
$user->delete();
$this->setRedirect(Route::_('index.php?option=com_clubs&view=positions', false));
}
}