Allowed changing of club's offers

This commit is contained in:
Christian Wolf 2019-06-26 19:21:17 +02:00
parent 3f96022176
commit 45d3e09c7e
4 changed files with 119 additions and 28 deletions

View File

@ -247,9 +247,10 @@ class ClubsHelperControllerClub extends AbstractClubsHelperController
$this->registerFcn('mail', 'editMail');
$this->registerFcn('iban', 'editIban');
$this->registerFcn('bic', 'editBic');
$this->registerFcn('offers', 'editOffers');
}
public function editName($user, $post)
protected function editName($user, $post)
{
$name = trim($post->getString('value'));
$this->checkLen($name, 6, 'Der Name des Vereins muss mindestens 6 Zeichen lang sein.');
@ -260,7 +261,7 @@ class ClubsHelperControllerClub extends AbstractClubsHelperController
$this->club->save();
}
public function editAddress($user, $post)
protected function editAddress($user, $post)
{
$address = trim($post->getString('value'));
$this->checkLen($address, 10, 'Die Adresse muss mindestens 10 Zeichen lang sein.');
@ -278,7 +279,7 @@ class ClubsHelperControllerClub extends AbstractClubsHelperController
$this->club->save();
}
public function editCity($user, $post)
protected function editCity($user, $post)
{
$city = trim($post->getString('value'));
$this->checkLen($city, 4, 'Die Stadt muss aus mindestens 4 Zeichen bestehen.');
@ -289,7 +290,7 @@ class ClubsHelperControllerClub extends AbstractClubsHelperController
$this->club->save();
}
public function editHomepage($user, $post)
protected function editHomepage($user, $post)
{
$homepage = trim($post->getString('value'));
$validator = new ClubsHelperValidator();
@ -302,7 +303,7 @@ class ClubsHelperControllerClub extends AbstractClubsHelperController
$this->club->save();
}
public function editMail($user, $post)
protected function editMail($user, $post)
{
$mail = trim($post->getString('value'));
$this->checkLen($mail, 8, "Die Mail-Adresse muss aus mindestens 8 Zeichen bestehen.");
@ -315,7 +316,7 @@ class ClubsHelperControllerClub extends AbstractClubsHelperController
$this->club->save();
}
public function editIban($user, $post)
protected function editIban($user, $post)
{
$iban = trim($post->getString('value'));
$this->checkLen($iban, 10, 'Die IBAN muss aus mindestens 10 Zeichen bestehen.');
@ -331,7 +332,7 @@ class ClubsHelperControllerClub extends AbstractClubsHelperController
$this->club->save();
}
public function editBic($user, $post)
protected function editBic($user, $post)
{
$bic = trim($post->getString('value'));
$this->checkLen($bic, 6, 'Die BIC muss aus mindestens 6 Zeichen bestehen.');
@ -342,7 +343,15 @@ class ClubsHelperControllerClub extends AbstractClubsHelperController
$this->club->save();
}
protected function editOffers($user, $post)
{
$ids = $post->getInt('offers');
// TODO ACL needed
$this->club->setOfferIds($ids);
$this->club->save();
}
}
class ClubsControllerParts extends BaseController

View File

@ -0,0 +1,87 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class ClubsPartClubOffers extends ClubsHelperParts
{
protected function getPartName()
{
return 'club.offers';
}
protected function getEditContent()
{
throw new Exception();
}
protected function getEditMarkup()
{
$ret = '';
$factory = new CommonClubsModelFactoryClub();
$club = $factory->loadById($this->id);
$offers = $club->getOffers();
$first = true;
foreach($offers as $o)
{
if(!$first)
$ret .= '<br />';
$checked = $o['valid'] ? ' checked' : '';
$ret .= "<input type='checkbox' name='offers[]' value='{$o['offer']->getId()}'$checked>";
$ret .= htmlentities($o['offer']->getName());
$first = false;
}
return $ret;
}
protected function getViewContent()
{
$ret = '';
$factory = new CommonClubsModelFactoryClub();
$club = $factory->loadById($this->id);
$offers = $club->getOffers();
$hasOffers = false;
$first = true;
foreach($offers as $o)
{
if($o['valid'])
{
$iconCls = 'ok';
$hasOffers = true;
}
else
{
$iconCls = 'cancel-2';
}
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)
{
// Reset to info string
$ret = '<i>Der Verein hat keine Angebote festgelegt.</i>';
}
return $ret;
}
}

View File

@ -79,10 +79,14 @@ $clubid = $this->club->getId();
</div>
</div>
<!--
<div class='clubs_row'>
<div class='clubs_title_row'>Gemeinn&uuml;tzigkeit</div>
<div class='clubs_content_row'><span class='icon-<?php echo $this->club->isCharitable() ? 'ok' : 'cancel'; ?>'></span> Der Verein ist <?php echo $this->club->isCharitable() ? '' : '<b>nicht</b>'; ?> gemeinn&uuml;tzig.</div>
<div class='clubs_content_row'>
<span class='icon-<?php echo $this->club->isCharitable() ? 'ok' : 'cancel'; ?>'></span> Der Verein ist <?php echo $this->club->isCharitable() ? '' : '<b>nicht</b>'; ?> gemeinn&uuml;tzig.
</div>
</div>
-->
<!--<div class='clubs_row'>
<div class='clubs_title_row'>Telefon</div>
@ -92,29 +96,16 @@ $clubid = $this->club->getId();
<div class='clubs_row'>
<div class='clubs_title_row'>Angebote</div>
<div class='clubs_content_row'>
<?php if($this->hasOffers):
// Put all options there
foreach($this->club->getOffers() as $o):
?>
<span class='icon-<?php echo $o['valid'] ? 'ok' : 'cancel-2'; ?>'></span>&nbsp;
<?php if($o['valid']) echo '<b>'; ?>
<?php echo htmlentities($o['offer']->getName()); ?><br />
<?php if($o['valid']) echo '</b>'; ?>
<?php
endforeach;
else:
// No options specified in the database
?>Der Verein hat keine Angebote festgelegt.<?php
endif; ?>
<?php
$partHandler = new ClubsPartClubOffers($clubid);
echo $partHandler->getViewPart();
?>
</div>
</div>
<?php if(count($this->club->getPlaces()) > 0): ?>
<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 />
@ -123,9 +114,11 @@ endif; ?>
<?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'><a href='<?php echo ""; ?>'><span class='icon-new'></span>&nbsp; Neue Assoziation anlegen</a></div>
</div>
<?php endif; ?>
<div class='clubs_row'>
<div class='clubs_title_row'>Pr&auml;sident</div>

View File

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