Modification of single places is now functional.

This commit is contained in:
Christian Wolf 2019-06-27 16:33:56 +02:00
parent 2da8da6b37
commit b61df340e8
8 changed files with 153 additions and 41 deletions

View File

@ -10,6 +10,7 @@ class CommonClubsModelFactoryPlace extends AbstractCommonClubsModelFactory
return array(
new CommonClubsModelColumnString('name', new CommonClubsControllerMappingString('Bezeichnung')),
new CommonClubsModelColumnRef('club', 'CommonClubsModelClub', 'clubid', new CommonClubsControllerMappingRef('Club', new CommonClubsModelFactoryClub())),
new CommonClubsModelColumnString('address', new CommonClubsControllerMappingString('Adresse')),
new CommonClubsModelColumnInt('area', new CommonClubsControllerMappingInt('Fläche', false))
);
}

View File

@ -25,6 +25,11 @@ class CommonClubsModelPlace extends AbstractCommonClubsModel
return $this->getValues()['area'];
}
public function getAddress()
{
return $this->getValues()['address'];
}
public function setName($name)
{
$this->setValue('name', $name);
@ -40,4 +45,9 @@ class CommonClubsModelPlace extends AbstractCommonClubsModel
$this->setValue('club', $club);
}
public function setAddress($address)
{
$this->setValue('address', $address);
}
}

View File

@ -248,6 +248,7 @@ class ClubsHelperControllerClub extends AbstractClubsHelperController
$this->registerFcn('iban', 'editIban');
$this->registerFcn('bic', 'editBic');
$this->registerFcn('offers', 'editOffers');
$this->registerFcn('place', 'editPlace');
}
protected function editName($user, $post)
@ -358,6 +359,41 @@ class ClubsHelperControllerClub extends AbstractClubsHelperController
throw new InvalidUserDataException('Es gab ein Problem mit der Eingabe. Bitte Seite neu laden und Daten erneut eintragen.');
}
}
protected function editPlace($user, $post)
{
$factory = new CommonClubsModelFactoryPlace();
$place = $factory->loadById($this->id);
$name = trim($post->getString('name'));
$address = $post->getString('address');
$area = $post->getInt('area');
$validator = new ClubsHelperValidator();
$this->checkLen($name, 5, "Der Name des Saals muss mindestens aus 5 Zeichen bestehen.");
$this->checkLen($address, 10, 'Die Adresse muss mindestens 10 Zeichen lang sein.');
$addr = '';
if(!$validator->validateAddress($address, $addr))
{
throw new InvalidUserDataException('Die Adresse muss mindestens aus 2 Zeilen bestehen.');
}
if($area < 0)
throw new InvalidUserDataException('Die Fläche darf nicht negativ sein.');
if($area == 0)
$area = null;
if($area > 2500)
throw new InvalidUserDataException('Die Fläche erscheint zu groß zu sein. Wenden Sie sich bitte ggf an den Support.');
// TODO ACL needed
$place->setName($name);
$place->setAddress($addr);
$place->setArea($area);
$place->save();
}
}
class ClubsControllerParts extends BaseController

View File

@ -42,7 +42,8 @@ table.clubs > tbody > tr > th
}
.clubs_content_row .clubs-hidden,
h1 .clubs-hidden
h1 .clubs-hidden,
.clubs-hidden
{
display: none;
}
@ -63,3 +64,11 @@ form.clubs-part
{
display: inline-block;
}
div.clubs-address
{
line-height: 135%;
margin: 5px 0px;
display: inline-block;
}

View File

@ -0,0 +1,71 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class ClubsPartClubPlace extends ClubsHelperParts
{
protected function getPartName()
{
return 'club.place';
}
protected function getEditContent()
{
throw new Exception();
}
protected function getEditMarkup()
{
$factory = new CommonClubsModelFactoryPlace();
$place = $factory->loadById($this->id);
$content = ob_get_contents();
ob_clean();
try
{
?>
<div>Name:</div>
<div><input type="text" name='name' value='<?php echo htmlentities($place->getName()); ?>'></div>
<div>Adresse:</div>
<div><textarea rows="4" name='address'><?php echo htmlentities($place->getAddress()); ?></textarea></div>
<div>Fl&auml;che:</div>
<div><input type='text' name='area' value='<?php echo $place->getArea(); ?>'> qm</div>
<?php
}
finally
{
$ret = ob_get_contents();
ob_clean();
echo $content;
}
return $ret;
}
protected function getViewContent()
{
$factory = new CommonClubsModelFactoryPlace();
$place = $factory->loadById($this->id);
$ret = '<b>';
$ret .= htmlentities($place->getName());
$ret .= '</b><br />';
$ret .= '<div class="clubs-address"><i>';
$ret .= nl2br(htmlentities($place->getAddress()));
$ret .= '</i></div>';
$area = $place->getArea();
if($area !== null)
{
$ret .= '<br />Fl&auml;che: ';
$ret .= htmlentities($area);
$ret .= ' qm';
}
return $ret;
}
}

View File

@ -48,35 +48,23 @@ class ClubsPartClubPlaces extends ClubsHelperParts
$factory = new CommonClubsModelFactoryClub();
$club = $factory->loadById($this->id);
$offers = $club->getOffers();
$hasOffers = false;
$first = true;
$places = $club->getPlaces();
$hasPlaces = count($places) > 0;
foreach($offers as $o)
foreach($places as $p)
{
if($o['valid'])
{
$iconCls = 'ok';
$hasOffers = true;
}
else
{
$iconCls = 'cancel-2';
$ret .= "<div class='clubs_content_row'><b>";
$ret .= htmlentities($p->getName());
$ret .= "</b><br /><i>";
$ret .= 'Adresse';
$ret .= "</i>";
if($p->getArea() !== null)
$ret .= '<br />Fl&auml;che: ' . htmlentities($p->getArea()) . 'qm';
$ret .= "</div>\n";
}
if(!$first)
$ret .= '<br />';
$first = false;
$ret .= "<span class='icon-$iconCls'></span>&nbsp; ";
if($o['valid'])
$ret .= '<b>';
$ret .= htmlentities($o['offer']->getName());
if($o['valid'])
$ret .= '</b>';
}
if(!$hasOffers)
if(! $hasPlaces)
{
// Reset to info string
$ret = '<i>Der Verein hat keine R&auml;ume eingetragen.</i>';

View File

@ -106,23 +106,18 @@ $clubid = $this->club->getId();
<div class='clubs_row'>
<div class='clubs_title_row'>R&auml;umlichkeiten</div>
<?php if(count($this->club->getPlaces()) > 0): ?>
<?php foreach($this->club->getPlaces() as $p): ?>
<div class='clubs_content_row'>
<b><?php echo htmlentities($p->getName()); ?></b><br />
<i>Adresse</i>
<?php //echo nl2br(htmlentities($p->getAddress())); ?>
<?php echo $p->getArea() === null ? '' : '<br />Fl&auml;che: ' . htmlentities($p->getArea()) . 'qm'; ?>
</div>
<?php endforeach; ?>
<?php else: ?>
Der Verein hat keine Angebote festgelegt.
<?php endif; ?>
<div class='clubs_content_row'>
<?php
$partHandler = new ClubsPartClubPlaces($clubid);
<?php
foreach($this->club->getPlaces() as $p)
{
$partHandler = new ClubsPartClubPlace($p->getId());
echo "<div class='clubs_content_row'>";
echo $partHandler->getViewPart();
?>
</div>
echo '</div>';
}
?>
<?php else: ?>
<div class='message-empty <?php echo count($this->club->getPlaces()) == 0 ? '' : 'clubs-hidden'; ?>'>Der Verein hat keine Angebote festgelegt.</div>
<?php endif; ?>
<div class='clubs_content_row'><a href='<?php echo ""; ?>'><span class='icon-new'></span>&nbsp; Neue Assoziation anlegen</a></div>
</div>

View File

@ -99,6 +99,8 @@ class ClubsViewPart extends HtmlView
return new ClubsPartClubBic($id);
case 'offers':
return new ClubsPartClubOffers($id);
case 'place':
return new ClubsPartClubPlace($id);
default:
throw new Exception('Internal Error');