Removed bugs in models (syntx errors) and changed Position to use abstract classes
This commit is contained in:
parent
6e1326240b
commit
47c81d3ce9
@ -1,108 +1,21 @@
|
||||
<?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
|
||||
class ClubsControllerPosition extends AbstractClubsController
|
||||
{
|
||||
|
||||
function new()
|
||||
protected function getNameOfElement()
|
||||
{
|
||||
$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));
|
||||
return 'position';
|
||||
}
|
||||
|
||||
function change()
|
||||
protected function getDataMapping()
|
||||
{
|
||||
$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));
|
||||
return array(
|
||||
'name'=>array('required'=>true, 'filter'=>'string', 'name'=>'Bezeichung')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class ClubsPlace extends ClubsAbstractModel
|
||||
class ClubsPlace extends AbstractClubsModel
|
||||
{
|
||||
protected $name;
|
||||
protected $address;
|
||||
|
@ -3,7 +3,7 @@
|
||||
// No direct access.
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class ClubsPosition extends ClubsAbstractModel
|
||||
class ClubsPosition extends AbstractClubsModel
|
||||
{
|
||||
protected $name;
|
||||
|
||||
|
@ -8,16 +8,16 @@ defined('_JEXEC') or die;
|
||||
?>
|
||||
|
||||
<form method="post" action="<?php echo $this->address; ?>">
|
||||
<input type='hidden' name='id' value='<?php echo $this->position->getId(); ?>'>
|
||||
<input type='hidden' name='id' value='<?php echo $this->object->getId(); ?>'>
|
||||
<table>
|
||||
<tr>
|
||||
<td>Bezeichnung</td>
|
||||
<td><input type='text' name='name' value='<?php echo htmlentities($this->position->getName()); ?>'></td>
|
||||
<td><input type='text' name='name' value='<?php echo htmlentities($this->object->getName()); ?>'></td>
|
||||
</tr>
|
||||
<?php if(! $this->isNew): ?>
|
||||
<tr>
|
||||
<td>ID</td>
|
||||
<td><?php echo $this->position->getId(); ?></td>
|
||||
<td><?php echo $this->object->getId(); ?></td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</table>
|
||||
|
@ -1,46 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\View\HtmlView;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Toolbar\ToolbarHelper;
|
||||
|
||||
// No direct access.
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class ClubsViewPosition extends HtmlView
|
||||
JLoader::register("ClubsControllerPosition", JPATH_ROOT . "/administrator/components/com_clubs/controllers/position.php");
|
||||
|
||||
class ClubsViewPosition extends AbstractClubsViewSingle
|
||||
{
|
||||
protected function getViewName()
|
||||
{
|
||||
return 'position';
|
||||
}
|
||||
|
||||
protected function getElementController()
|
||||
{
|
||||
return new ClubsControllerPosition();
|
||||
}
|
||||
|
||||
function display($tpl = null)
|
||||
{
|
||||
|
||||
$input = Factory::getApplication()->input;
|
||||
$id = $input->get->get('id');
|
||||
|
||||
if($id === 'new')
|
||||
{
|
||||
$this->address = Route::_('index.php?option=com_clubs&task=position.new');
|
||||
$this->position = ClubsPosition::createPosition();
|
||||
$this->isNew = true;
|
||||
}
|
||||
else if(is_numeric($id))
|
||||
{
|
||||
$this->address = Route::_('index.php?option=com_clubs&task=position.change');
|
||||
$this->position = ClubsPosition::loadPosition((int) $id);
|
||||
$this->isNew = false;
|
||||
}
|
||||
else
|
||||
throw new Exception('Need a position id.');
|
||||
|
||||
if($input->get->get('data', null, 'json') != null)
|
||||
{
|
||||
// Restore previous data
|
||||
$dataurl = $input->get->get('data', null, 'json');
|
||||
$data = json_decode($dataurl, true);
|
||||
|
||||
$this->position->setName($data['name']);
|
||||
|
||||
}
|
||||
|
||||
ToolbarHelper::title('Club-Management - Position');
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user