Created basic backend for club view
This commit is contained in:
parent
4dc78c21af
commit
5ce47c288d
@ -173,7 +173,11 @@ abstract class AbstractClubsController extends BaseController
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(isset($v['skip_null_check']))
|
||||||
|
$value = $values[$m];
|
||||||
|
else
|
||||||
$value = (isset($values[$m]) && strlen($values[$m]) > 0) ? $values[$m] : null;
|
$value = (isset($values[$m]) && strlen($values[$m]) > 0) ? $values[$m] : null;
|
||||||
|
|
||||||
$obj->$functionName($value);
|
$obj->$functionName($value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,16 +107,7 @@ abstract class AbstractClubsModel
|
|||||||
$q = $dbo->getQuery(true);
|
$q = $dbo->getQuery(true);
|
||||||
|
|
||||||
$mappings = $this->getDataMappings();
|
$mappings = $this->getDataMappings();
|
||||||
$values = array();
|
$values = $this->getDataValues($mappings, $q);
|
||||||
foreach($mappings as $m)
|
|
||||||
$values[$m] = $this->$m;
|
|
||||||
|
|
||||||
$this->filter($values);
|
|
||||||
|
|
||||||
foreach($mappings as $m)
|
|
||||||
$values[$m] = $q->q($values[$m]);
|
|
||||||
|
|
||||||
$this->postQuoteFilter($values);
|
|
||||||
|
|
||||||
$q->insert($this->getTableName())
|
$q->insert($this->getTableName())
|
||||||
->columns(array_map(array($q, 'qn'), $mappings))
|
->columns(array_map(array($q, 'qn'), $mappings))
|
||||||
@ -139,16 +130,7 @@ abstract class AbstractClubsModel
|
|||||||
$q = $dbo->getQuery(true);
|
$q = $dbo->getQuery(true);
|
||||||
|
|
||||||
$mapping = $this->getDataMappings();
|
$mapping = $this->getDataMappings();
|
||||||
$values = array();
|
$values = $this->getDataValues($mapping, $q);
|
||||||
foreach($mapping as $m)
|
|
||||||
$values[$m] = $this->$m;
|
|
||||||
|
|
||||||
$this->filter($values);
|
|
||||||
|
|
||||||
foreach($mapping as $m)
|
|
||||||
$values[$m] = $q->q($values[$m]);
|
|
||||||
|
|
||||||
$this->postQuoteFilter($values);
|
|
||||||
|
|
||||||
$q->update($this->getTableName());
|
$q->update($this->getTableName());
|
||||||
foreach($mapping as $m)
|
foreach($mapping as $m)
|
||||||
@ -159,6 +141,32 @@ abstract class AbstractClubsModel
|
|||||||
$dbo->execute();
|
$dbo->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getDataValues($mapping, $q)
|
||||||
|
{
|
||||||
|
$rawValues = array();
|
||||||
|
|
||||||
|
foreach($mapping as $m)
|
||||||
|
$rawValues[$m] = $this->$m;
|
||||||
|
|
||||||
|
$this->filter($rawValues);
|
||||||
|
|
||||||
|
$quotedValues = array();
|
||||||
|
|
||||||
|
foreach($mapping as $m)
|
||||||
|
{
|
||||||
|
if(is_bool($rawValues[$m]))
|
||||||
|
$quotedValues[$m] = $rawValues[$m] ? 'TRUE' : 'FALSE';
|
||||||
|
else if(is_numeric($rawValues[$m]))
|
||||||
|
$quotedValues[$m] = $rawValues[$m];
|
||||||
|
else
|
||||||
|
$quotedValues[$m] = $q->q($rawValues[$m]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->postQuoteFilter($quotedValues);
|
||||||
|
|
||||||
|
return $quotedValues;
|
||||||
|
}
|
||||||
|
|
||||||
protected function prepareDelete($dbo){}
|
protected function prepareDelete($dbo){}
|
||||||
|
|
||||||
public function delete()
|
public function delete()
|
||||||
@ -186,7 +194,7 @@ abstract class AbstractClubsModel
|
|||||||
{
|
{
|
||||||
foreach($this->getRequiredDataMappings() as $m)
|
foreach($this->getRequiredDataMappings() as $m)
|
||||||
{
|
{
|
||||||
if(!isset($this->$m) || empty($this->$m) || $this->$m === null)
|
if(!isset($this->$m) || is_null($this->$m) || $this->$m === null)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
39
src/admin/controllers/club.php
Normal file
39
src/admin/controllers/club.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
// No direct access.
|
||||||
|
defined('_JEXEC') or die;
|
||||||
|
|
||||||
|
class ClubsControllerClub extends AbstractClubsController
|
||||||
|
{
|
||||||
|
protected function getNameOfElement()
|
||||||
|
{
|
||||||
|
return 'club';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getDataMapping()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
// 'name' => array('required'=>true, 'name'=>'Bezeichnung', 'filter'=>'string')
|
||||||
|
'name' => array('required'=>true, 'name'=>'Club-Name', 'filter'=>'string'),
|
||||||
|
'address' => array('required'=>true, 'name'=>'Adresse', 'filter'=>'string'),
|
||||||
|
'city' => array('required'=>true, 'name'=>'Stadt', 'filter'=>'string'),
|
||||||
|
'homepage' => array('required'=>false, 'name'=>'Homepage', 'filter'=>'string'),
|
||||||
|
'mail' => array('required'=>true, 'name'=>'E-Mail', 'filter'=>'string'),
|
||||||
|
'iban' => array('required'=>true, 'name'=>'IBAN', 'filter'=>'string'),
|
||||||
|
'bic' => array('required'=>true, 'name'=>'BIC', 'filter'=>'string'),
|
||||||
|
'charitable' => array('skip_null_check'=>True),
|
||||||
|
'president' => array('required'=>true, 'name'=>'Vorsitzender', 'skip_null_check'=>True)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function filterPreCheck(&$values)
|
||||||
|
{
|
||||||
|
if(is_null($values['charitable']))
|
||||||
|
$values['charitable'] = false;
|
||||||
|
else
|
||||||
|
$values['charitable'] = true;
|
||||||
|
|
||||||
|
$values['president'] = ClubsUser::loadUser((int)($values['president']));
|
||||||
|
}
|
||||||
|
}
|
@ -108,7 +108,7 @@ class ClubsClub extends AbstractClubsModel
|
|||||||
/**
|
/**
|
||||||
* @param string $homapge
|
* @param string $homapge
|
||||||
*/
|
*/
|
||||||
public function setHomapge(string $homapge)
|
public function setHomepage(string $homapge)
|
||||||
{
|
{
|
||||||
$this->homepage = $homapge;
|
$this->homepage = $homapge;
|
||||||
}
|
}
|
||||||
@ -232,12 +232,12 @@ class ClubsClub extends AbstractClubsModel
|
|||||||
|
|
||||||
protected function getDataMappings()
|
protected function getDataMappings()
|
||||||
{
|
{
|
||||||
return array('name', 'address', 'city', 'homepage', 'mail', 'iban', 'bic', 'charitable');
|
return array('name', 'address', 'city', 'homepage', 'mail', 'iban', 'bic', 'charitable', 'president');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getRequiredDataMappings()
|
protected function getRequiredDataMappings()
|
||||||
{
|
{
|
||||||
return array('name', 'address', 'city', 'mail', 'iban', 'bic', 'charitable');
|
return array('name', 'address', 'city', 'mail', 'iban', 'bic');
|
||||||
}
|
}
|
||||||
|
|
||||||
private const tableName = '#__club_clubs';
|
private const tableName = '#__club_clubs';
|
||||||
|
@ -8,20 +8,72 @@ defined('_JEXEC') or die;
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<form method="post" action="<?php echo $this->address; ?>">
|
<form method="post" action="<?php echo $this->address; ?>">
|
||||||
<input type='hidden' name='id' value='<?php echo $this->offer->getId(); ?>'>
|
<input type='hidden' name='id' value='<?php echo $this->object->getId(); ?>'>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Bezeichnung</td>
|
<td>Bezeichnung</td>
|
||||||
<td><input type='text' name='name' value='<?php echo htmlentities($this->offer->getName()); ?>'></td>
|
<td><input type='text' name='name' value='<?php echo htmlentities($this->object->getName()); ?>'></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>Adresse</td>
|
||||||
|
<td>
|
||||||
|
<textarea name='address' rows='5'><?php echo htmlentities($this->object->getAddress()); ?></textarea>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>Stadt</td>
|
||||||
|
<td><input type='text' name='city' value='<?php echo htmlentities($this->object->getCity()); ?>'></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>Homepage</td>
|
||||||
|
<td><input type='text' name='homepage' value='<?php echo htmlentities($this->object->getHomepage()); ?>'></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>E-Mail</td>
|
||||||
|
<td><input type='text' name='mail' value='<?php echo htmlentities($this->object->getMail()); ?>'></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>IBAN</td>
|
||||||
|
<td><input type='text' name='iban' value='<?php echo htmlentities($this->object->getIban()); ?>'></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>BIC</td>
|
||||||
|
<td><input type='text' name='bic' value='<?php echo htmlentities($this->object->getBic()); ?>'></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>Gemeinnützig</td>
|
||||||
|
<td><input type='checkbox' name='charitable' value='1' <?php echo $this->object->isCharitable() ? 'checked' : ''; ?>></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>Vorsitzende/r</td>
|
||||||
|
<td>
|
||||||
|
<!-- <input type='text' name='president' value='<?php echo htmlentities($this->object->getName()); ?>'> -->
|
||||||
|
<select name='president'>
|
||||||
|
<?php foreach($this->users as $u): ?>
|
||||||
|
<option value='<?php echo $u->getId(); ?>' <?php if ($this->object->getPresident()->getId() == $u->getId()) echo 'selected="selected"'; ?>>
|
||||||
|
<?php echo htmlentities("{$u->getName()}, {$u->getCity()}"); ?>
|
||||||
|
</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
|
||||||
<?php if(! $this->isNew): ?>
|
<?php if(! $this->isNew): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td>ID</td>
|
<td>ID</td>
|
||||||
<td><?php echo $this->offer->getId(); ?></td>
|
<td><?php echo $this->object->getId(); ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<input type='submit' value='Speichern'> <br /><a href='<?php echo Route::_('index.php?option=com_clubs&view=offers'); ?>'>Zurück zur Übersicht</a>
|
<input type='submit' value='Speichern'> <br /><a href='<?php echo Route::_('index.php?option=com_clubs&view=clubs'); ?>'>Zurück zur Übersicht</a>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
@ -1,47 +1,31 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Joomla\CMS\Factory;
|
|
||||||
use Joomla\CMS\MVC\View\HtmlView;
|
|
||||||
use Joomla\CMS\Router\Route;
|
|
||||||
use Joomla\CMS\Toolbar\ToolbarHelper;
|
use Joomla\CMS\Toolbar\ToolbarHelper;
|
||||||
|
|
||||||
// No direct access.
|
// No direct access.
|
||||||
defined('_JEXEC') or die;
|
defined('_JEXEC') or die;
|
||||||
|
|
||||||
class ClubsViewOffer extends HtmlView
|
JLoader::register("ClubsControllerClub", JPATH_ROOT . "/administrator/components/com_clubs/controllers/club.php");
|
||||||
|
|
||||||
|
class ClubsViewClub extends AbstractClubsViewSingle
|
||||||
{
|
{
|
||||||
function display($tpl = null)
|
function display($tpl = null)
|
||||||
{
|
{
|
||||||
|
ToolbarHelper::title('Club-Management - Verein');
|
||||||
|
|
||||||
$input = Factory::getApplication()->input;
|
$this->users = ClubsUser::loadUsers();
|
||||||
$id = $input->get->get('id');
|
|
||||||
|
|
||||||
if($id === 'new')
|
|
||||||
{
|
|
||||||
$this->address = Route::_('index.php?option=com_clubs&task=offer.new');
|
|
||||||
$this->offer = ClubsOffer::createOffer();
|
|
||||||
$this->isNew = true;
|
|
||||||
}
|
|
||||||
else if(is_numeric($id))
|
|
||||||
{
|
|
||||||
$this->address = Route::_('index.php?option=com_clubs&task=offer.change');
|
|
||||||
$this->offer = ClubsOffer::loadOffer((int) $id);
|
|
||||||
$this->isNew = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
throw new Exception('Need a user 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->offer->setName($data['name']);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ToolbarHelper::title('Club-Management - Angebot');
|
|
||||||
parent::display($tpl);
|
parent::display($tpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getViewName()
|
||||||
|
{
|
||||||
|
return 'club';
|
||||||
|
}
|
||||||
|
protected function getElementController()
|
||||||
|
{
|
||||||
|
return new ClubsControllerClub();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user