Added backend for position of persons

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

76
sql/init3.sql Normal file
View File

@ -0,0 +1,76 @@
CREATE TABLE `dev_club_keys` (
`privkey` text NOT NULL,
`publickey` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `dev_club_users` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`user` varchar(30) NOT NULL,
`password` varchar(150) DEFAULT NULL,
`name` varchar(255) NOT NULL,
`address` tinytext NOT NULL,
`city` varchar(50) NOT NULL,
`mail` varchar(100) NOT NULL,
`phone` varchar(50) DEFAULT NULL,
`mobile` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `dev_club_offers` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `dev_club_positions` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `dev_club_clubs` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`address` tinytext NOT NULL,
`city` varchar(50) NOT NULL,
`homepage` varchar(100) NULL,
`mail` varchar(100) NOT NULL,
`iban` char(34) NOT NULL,
`bic` char(11) NOT NULL,
`charitable` tinyint(1) NOT NULL,
`president` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `dev_club_offer_assocs` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`clubid` int(10) NOT NULL,
`offerid` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `dev_club_places` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`clubid` int(10) NOT NULL,
`name` varchar(100) NOT NULL,
`address` tinytext NOT NULL,
`area` int(10) NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `dev_club_user_assocs` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`clubid` int(10) NOT NULL,
`userid` int(10) NOT NULL,
`positionid` int(10) NOT NULL,
`admin` tinyint(1) NOT NULL DEFAULT 0,
`state` enum('regular', 'vacant', 'temporary') NOT NULL DEFAULT 'vacant',
`address` tinytext DEFAULT NULL,
`mail` varchar(100) DEFAULT NULL,
`phone` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

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));
}
}

View File

@ -0,0 +1,157 @@
<?php
// No direct access.
use Joomla\CMS\Factory;
defined('_JEXEC') or die;
class ClubsPosition
{
protected $id;
protected $name;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
protected function loadData(array $data)
{
$this->id = $data['id'];
$this->name = $data['name'];
}
protected function __construct()
{}
public static function loadPositions()
{
$dbo = Factory::getDbo();
$q = $dbo->getQuery(true);
$q->select('*')
->from('#__club_positions');
$dbo->setQuery($q);
$dbo->execute();
$list = $dbo->loadAssocList('id');
$ret = array();
foreach($list as $p)
{
$po = new ClubsPosition();
$po->loadData($p);
$ret[] = $po;
}
return $ret;
}
public static function loadPosition(int $id)
{
$dbo = Factory::getDbo();
$q = $dbo->getQuery(true);
$q->select('*')->from('#__club_positions')->where('id=' . (int) $id);
$dbo->setQuery($q);
$dbo->execute();
$row = $dbo->loadAssoc();
if($row == null)
{
throw new Exception("No position found.");
// TODO
}
$position = new ClubsPosition();
$position->loadData($row);
return $position;
}
public static function createPosition()
{
$position = new ClubsPosition();
$position->id = 'new';
return $position;
}
public function save()
{
if($this->id === 'new')
$this->insertPosition();
else
$this->updatePosition();
}
private function insertPosition()
{
$dbo = Factory::getDbo();
$q = $dbo->getQuery(true);
$vname = $q->q($this->name);
$q->insert('#__club_positions')
->columns(array('name'))
->values("$vname")
;
$dbo->transactionStart();
$dbo->setQuery($q);
$dbo->execute();
$this->id = $dbo->insertid();
$dbo->transactionCommit();
}
private function updatePosition()
{
$dbo = Factory::getDbo();
$q = $dbo->getQuery(true);
$vname = $q->q($this->name);
$q->update('#__club_positions')
->set(array(
"name=$vname"
))
->where("id=". (int) $this->id)
;
$dbo->setQuery($q);
$dbo->execute();
}
public function delete()
{
if($this->id === 'new')
return;
$dbo = Factory::getDbo();
$q = $dbo->getQuery(true);
$q->delete('#__club_positions')
->where('id=' . (int) $this->id);
$dbo->setQuery($q);
$dbo->execute();
}
}

View File

@ -0,0 +1,27 @@
<?php
// No direct access.
use Joomla\CMS\Router\Route;
defined('_JEXEC') or die;
?>
<form method="post" action="<?php echo $this->address; ?>">
<input type='hidden' name='id' value='<?php echo $this->position->getId(); ?>'>
<table>
<tr>
<td>Bezeichnung</td>
<td><input type='text' name='name' value='<?php echo htmlentities($this->position->getName()); ?>'></td>
</tr>
<?php if(! $this->isNew): ?>
<tr>
<td>ID</td>
<td><?php echo $this->position->getId(); ?></td>
</tr>
<?php endif; ?>
</table>
<input type='submit' value='Speichern'> <br /><a href='<?php echo Route::_('index.php?option=com_clubs&view=positions'); ?>'>Zur&uuml;ck zur &Uuml;bersicht</a>
</form>

View File

@ -0,0 +1,47 @@
<?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
{
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);
}
}

View File

@ -0,0 +1,28 @@
<?php
// No direct access.
use Joomla\CMS\Router\Route;
defined('_JEXEC') or die;
?>
<table class='table table-stiped, table-hover'>
<thead>
<tr>
<th width='30%'>Bezeichnung</th>
<th width='5%'>L&ouml;schen?</th>
<th width='5%'>id</th>
</tr>
</thead>
<?php foreach($this->positions as $position): ?>
<?php $link = Route::_('index.php?option=com_clubs&view=position&id=' . $position->getId()); ?>
<tr>
<td><a href='<?php echo $link; ?>'><?php echo htmlentities($position->getName()); ?></a></td>
<td><a href='<?php echo Route::_('index.php?option=com_clubs&task=position.delete&id=' . $position->getId()); ?>'>Del</a></td>
<td><?php echo htmlentities($position->getId()); ?></td>
</tr>
<?php endforeach; ?>
</table>
<div><a href='<?php echo Route::_('index.php?option=com_clubs&view=position&id=new'); ?>'>Neues Angebot anlegen</a></div>

View File

@ -0,0 +1,20 @@
<?php
use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\Toolbar\ToolbarHelper;
// No direct access.
defined('_JEXEC') or die;
class ClubsViewPositions extends HtmlView
{
function display($tpl = null)
{
$this->positions = ClubsPosition::loadPositions();
ToolbarHelper::title('Club-Management - Positionen');
parent::display($tpl);
}
}