Created structure to access the offers of the clubs
This commit is contained in:
108
src/admin/controllers/offer.php
Normal file
108
src/admin/controllers/offer.php
Normal 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 ClubsControllerOffer extends BaseController
|
||||
{
|
||||
|
||||
function new()
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$input = $app->input;
|
||||
$o = ClubsOffer::createOffer();
|
||||
|
||||
// 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=new&data=' . $urldata, false));
|
||||
return;
|
||||
}
|
||||
|
||||
$o->setName($name);
|
||||
|
||||
// Do the actual work
|
||||
$o->save();
|
||||
$this->setRedirect(Route::_('index.php?option=com_clubs&view=offers', false));
|
||||
}
|
||||
|
||||
function change()
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$input = $app->input;
|
||||
$id = (int) $input->post->getInt('id');
|
||||
$o = ClubsOffer::loadOffer((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;
|
||||
}
|
||||
|
||||
$o->setName($name);
|
||||
|
||||
// Do the actual work
|
||||
$o->save();
|
||||
$this->setRedirect(Route::_('index.php?option=com_clubs&view=offers', false));
|
||||
}
|
||||
|
||||
function delete()
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$id = $app->input->get->getInt('id');
|
||||
$app->enqueueMessage("Removal of offer with id $id.");
|
||||
$user = ClubsOffer::loadOffer($id);
|
||||
$user->delete();
|
||||
$this->setRedirect(Route::_('index.php?option=com_clubs&view=offers', false));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user