Club frontend partly created, missing the special cases

This commit is contained in:
Christian Wolf 2019-06-26 14:29:24 +02:00
parent 7dae1d826e
commit 3f96022176
15 changed files with 505 additions and 24 deletions

View File

@ -16,46 +16,91 @@ class CommonClubsModelClub extends AbstractCommonClubsModel
return $this->getValues()['name']; return $this->getValues()['name'];
} }
public function setName($name)
{
$this->setValue('name', $name);
}
public function getAddress() public function getAddress()
{ {
return $this->getValues()['address']; return $this->getValues()['address'];
} }
public function setAddress($address)
{
$this->setValue('address', $address);
}
public function getCity() public function getCity()
{ {
return $this->getValues()['city']; return $this->getValues()['city'];
} }
public function setCity($city)
{
$this->setValue('city', $city);
}
public function getHomepage() public function getHomepage()
{ {
return $this->getValues()['homepage']; return $this->getValues()['homepage'];
} }
public function setHomepage($homepage)
{
$this->setValue('homepage', $homepage);
}
public function getMail() public function getMail()
{ {
return $this->getValues()['mail']; return $this->getValues()['mail'];
} }
public function setMail($mail)
{
$this->setValue('mail', $mail);
}
public function getIban() public function getIban()
{ {
return $this->getValues()['iban']; return $this->getValues()['iban'];
} }
public function setIban($iban)
{
$this->setValue('iban', $iban);
}
public function getBic() public function getBic()
{ {
return $this->getValues()['bic']; return $this->getValues()['bic'];
} }
public function setBic($bic)
{
$this->setValue('bic', $bic);
}
public function isCharitable() public function isCharitable()
{ {
return $this->getValues()['charitable']; return $this->getValues()['charitable'];
} }
public function setCharitable($charitable)
{
$this->setValue('charitable', $charitable);
}
public function getPresident() public function getPresident()
{ {
return $this->getValues()['president']; return $this->getValues()['president'];
} }
public function setPresident($user)
{
$this->setValue('president', $user);
}
public function getPlaces() public function getPlaces()
{ {
return $this->fetchAssociatedElements(new CommonClubsModelFactoryPlace(), 'clubid'); return $this->fetchAssociatedElements(new CommonClubsModelFactoryPlace(), 'clubid');

View File

@ -39,7 +39,7 @@ abstract class AbstractClubsHelperController
protected function checkLen($value, $len, $msg) protected function checkLen($value, $len, $msg)
{ {
if(strlen($value) < 5) if(strlen($value) < $len)
throw new InvalidUserDataException($msg); throw new InvalidUserDataException($msg);
} }
@ -138,11 +138,13 @@ class ClubsHelperControllerUser extends AbstractClubsHelperController
$address = trim($post->getString('value')); $address = trim($post->getString('value'));
$this->checkLen($address, 10, 'Die Adresse muss mindestens 10 Zeichen lang sein.'); $this->checkLen($address, 10, 'Die Adresse muss mindestens 10 Zeichen lang sein.');
$parts = array_filter(explode("\n", str_replace("\r", "\n", $address))); $validator = new ClubsHelperValidator();
if(count($parts) < 2) $addr = '';
$valid = $validator->validateAddress($address, $addr);
if(! $valid)
throw new InvalidUserDataException('Die Adresse muss mindestens aus 2 Zeilen bestehen.'); throw new InvalidUserDataException('Die Adresse muss mindestens aus 2 Zeilen bestehen.');
$addr = join("\n", $parts);
$user->setAddress($addr); $user->setAddress($addr);
$user->save(); $user->save();
} }
@ -160,7 +162,8 @@ class ClubsHelperControllerUser extends AbstractClubsHelperController
{ {
$mail = trim($post->getString('value')); $mail = trim($post->getString('value'));
$this->checkLen($mail, 8, "Die Mail-Adresse muss aus mindestens 8 Zeichen bestehen."); $this->checkLen($mail, 8, "Die Mail-Adresse muss aus mindestens 8 Zeichen bestehen.");
if(! preg_match('/..*@..*\...*/', $mail)) $validator = new ClubsHelperValidator();
if(! $validator->validateMail($mail))
throw new InvalidUserDataException('Die Mail-Adresse hat kein gültiges Format.'); throw new InvalidUserDataException('Die Mail-Adresse hat kein gültiges Format.');
$user->setMail($mail); $user->setMail($mail);
@ -219,8 +222,125 @@ class ClubsHelperControllerUser extends AbstractClubsHelperController
class ClubsHelperControllerClub extends AbstractClubsHelperController class ClubsHelperControllerClub extends AbstractClubsHelperController
{ {
private $id;
/**
* @var CommonClubsModelClub
*/
private $club;
public function __construct($id)
{
parent::__construct();
$this->id = $id;
$factory = new CommonClubsModelFactoryClub();
$this->club = $factory->loadById($id, false);
}
protected function registerAll() protected function registerAll()
{} {
$this->registerFcn('name', 'editName');
$this->registerFcn('address', 'editAddress');
$this->registerFcn('city', 'editCity');
$this->registerFcn('homepage', 'editHomepage');
$this->registerFcn('mail', 'editMail');
$this->registerFcn('iban', 'editIban');
$this->registerFcn('bic', 'editBic');
}
public function editName($user, $post)
{
$name = trim($post->getString('value'));
$this->checkLen($name, 6, 'Der Name des Vereins muss mindestens 6 Zeichen lang sein.');
// TODO ACL needed
$this->club->setName($name);
$this->club->save();
}
public function editAddress($user, $post)
{
$address = trim($post->getString('value'));
$this->checkLen($address, 10, 'Die Adresse muss mindestens 10 Zeichen lang sein.');
$validator = new ClubsHelperValidator();
$addr = '';
$valid = $validator->validateAddress($address, $addr);
if(! $valid)
throw new InvalidUserDataException('Die Adresse muss mindestens aus 2 Zeilen bestehen.');
// TODO ACL needed
$this->club->setAddress($addr);
$this->club->save();
}
public function editCity($user, $post)
{
$city = trim($post->getString('value'));
$this->checkLen($city, 4, 'Die Stadt muss aus mindestens 4 Zeichen bestehen.');
// TODO ACL needed
$this->club->setCity($city);
$this->club->save();
}
public function editHomepage($user, $post)
{
$homepage = trim($post->getString('value'));
$validator = new ClubsHelperValidator();
if(!$validator->validateHomepage($homepage))
throw new InvalidUserDataException('Die URL muss mit "http(s)://domain.tld" beginnen.');
// TODO ACL needed
$this->club->setHomepage($homepage);
$this->club->save();
}
public function editMail($user, $post)
{
$mail = trim($post->getString('value'));
$this->checkLen($mail, 8, "Die Mail-Adresse muss aus mindestens 8 Zeichen bestehen.");
$validator = new ClubsHelperValidator();
if(! $validator->validateMail($mail))
throw new InvalidUserDataException('Die Mail-Adresse hat kein gültiges Format.');
$this->club->setMail($mail);
$this->club->save();
}
public function editIban($user, $post)
{
$iban = trim($post->getString('value'));
$this->checkLen($iban, 10, 'Die IBAN muss aus mindestens 10 Zeichen bestehen.');
$validator = new ClubsHelperValidator();
$formattedIban = null;
if(! $validator->validateIban($iban, $formattedIban))
throw new InvalidUserDataException('Die IBAN ist nicht korrekt.');
// TODO ACL needed
$this->club->setIban($iban);
$this->club->save();
}
public function editBic($user, $post)
{
$bic = trim($post->getString('value'));
$this->checkLen($bic, 6, 'Die BIC muss aus mindestens 6 Zeichen bestehen.');
// TODO ACL needed
$this->club->setBic($bic);
$this->club->save();
}
} }
@ -267,14 +387,21 @@ class ClubsControllerParts extends BaseController
break; break;
case 'club': case 'club':
$obj = new ClubsHelperControllerClub(); $clubid = $post->getInt('id', -1);
$obj = new ClubsHelperControllerClub($clubid);
$obj->handle($fcnName, $user, $post); // TODO User!?!?! $obj->handle($fcnName, $user, $post); // TODO User!?!?!
break; break;
default: default:
throw new Exception(); throw new Exception();
} }
return "index.php?option=com_clubs&view=part&type=$partname";
$id = (int) $post->getInt('id', -1);
$addId = '';
if($id != -1)
$addId = "&id=$id";
return "index.php?option=com_clubs&view=part&type=$partname$addId";
} }
} }

View File

@ -5,6 +5,12 @@
padding-left: 2em; padding-left: 2em;
margin-bottom: 10px; margin-bottom: 10px;
} }
h1 > .clubs_content_row
{
padding-left: 0px;
}
.clubs_title_row .clubs_title_row
{ {
font-weight: bold; font-weight: bold;
@ -35,12 +41,15 @@ table.clubs > tbody > tr > th
line-height: 120%; line-height: 120%;
} }
.clubs_content_row .clubs-hidden .clubs_content_row .clubs-hidden,
h1 .clubs-hidden
{ {
display: none; display: none;
} }
.clubs_content_row:hover > a > .edit-icon .clubs_content_row:hover > a > .edit-icon,
.clubs_content_row > div:hover > a > .edit-icon,
h1:hover > a > .edit-icon
{ {
display: inline-block; display: inline-block;
} }
@ -49,3 +58,8 @@ form.clubs-part, form.clubs-part > input
{ {
margin: 0pt; margin: 0pt;
} }
form.clubs-part
{
display: inline-block;
}

View File

@ -11,6 +11,16 @@ abstract class ClubsHelperParts
*/ */
abstract protected function getPartName(); abstract protected function getPartName();
/**
* @var int
*/
protected $id;
public function __construct($id = null)
{
$this->id = $id;
}
/** /**
* @return string * @return string
*/ */
@ -18,11 +28,16 @@ abstract class ClubsHelperParts
{ {
$partname = $this->getPartName(); $partname = $this->getPartName();
$ret = "<form method='POST' action='index.php?option=com_clubs&task=parts.edit&format=json' class='clubs-part'>"; $ret = "<form method='POST' action='index.php?option=com_clubs&task=parts.edit&format=json' class='clubs-part'>";
$ret .= "<input type='hidden' name='partname' value='$partname'>"; $ret .= "<input type='hidden' name='partname' value='$partname'>";
if(isset($this->id))
$ret .= "<input type='hidden' name='id' value='{$this->id}'>";
$ret .= $this->getEditMarkup(); $ret .= $this->getEditMarkup();
$ret .= '&nbsp;<a class="clubs-save" href="#"><span class="icon-ok"></span></a>&nbsp;'; $ret .= '&nbsp;<a class="clubs-save" href="#"><span class="icon-ok"></span></a>&nbsp;';
$ret .= '<a class="clubs-abort" href="index.php?option=com_clubs&view=part&type='.$partname.'"><span class="icon-cancel-2"></span></a>'; $idPart = '';
if(isset($this->id))
$idPart = "&id=" . $this->id;
$ret .= '<a class="clubs-abort" href="index.php?option=com_clubs&view=part&type='.$partname.$idPart.'"><span class="icon-cancel-2"></span></a>';
$ret .= '</form>'; $ret .= '</form>';
return $ret; return $ret;
@ -54,12 +69,19 @@ abstract class ClubsHelperParts
*/ */
public function getViewPart() public function getViewPart()
{ {
$ret = ''; $idPart = '';
if(isset($this->id))
$idPart = "&id={$this->id}";
$ret = "<a class='clubs-edit' href='index.php?option=com_clubs&view=part&mode=edit&type=" . $this->getPartName(). "'>"; $ret = "<a class='clubs-edit' href='index.php?option=com_clubs&view=part&mode=edit&type=" . $this->getPartName(). "$idPart'>";
$ret .= $this->getViewContent(); $ret .= $this->getViewContent();
$ret .= "<span class='icon-apply clubs-hidden edit-icon' style='font-size: 200%; margin-left: 0.75em;'></span></a>"; $ret .= "<span class='icon-apply clubs-hidden edit-icon' style='font-size: {$this->getEditSymbolSize()}; margin-left: 0.75em; margin-right: 0.4em; '></span></a>";
return $ret; return $ret;
} }
protected function getEditSymbolSize()
{
return '120%';
}
} }

View File

@ -42,4 +42,31 @@ class ClubsHelperValidator
return self::USERNAME_VALID; return self::USERNAME_VALID;
} }
public function validateAddress($address, &$addr = null)
{
$parts = array_filter(explode("\n", str_replace("\r", "\n", $address)));
if(count($parts) < 2)
return false;
if($addr !== null)
$addr = join("\n", $parts);
return true;
}
public function validateHomepage($address)
{
return preg_match('@^https?://[a-zA-Z0-9].*\.[a-zA-Z0-9]{2,}@', $address);
}
public function validateMail($mail)
{
return preg_match('/..*@..*\...*/', $mail);
}
public function validateIban($iban, &$formattedIban)
{
return true; // FIXME Implement useful tests
}
} }

View File

@ -0,0 +1,31 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class ClubsPartClubAddress extends ClubsHelperPartTextarea
{
protected function getPartName()
{
return 'club.address';
}
protected function getEditContent()
{
$clubFactory = new CommonClubsModelFactoryClub();
$club = $clubFactory->loadById($this->id);
return htmlentities($club->getAddress());
}
protected function getViewContent()
{
return nl2br(parent::getViewContent());
}
protected function additionalParams()
{
return 'rows="4"';
}
}

View File

@ -0,0 +1,21 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class ClubsPartClubBic extends ClubsHelperPartTextfield
{
protected function getPartName()
{
return 'club.bic';
}
protected function getEditContent()
{
$clubFactory = new CommonClubsModelFactoryClub();
$club = $clubFactory->loadById($this->id);
return htmlentities($club->getBic());
}
}

View File

@ -0,0 +1,21 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class ClubsPartClubCity extends ClubsHelperPartTextfield
{
protected function getPartName()
{
return 'club.city';
}
protected function getEditContent()
{
$clubFactory = new CommonClubsModelFactoryClub();
$club = $clubFactory->loadById($this->id);
return htmlentities($club->getCity());
}
}

View File

@ -0,0 +1,21 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class ClubsPartClubHomepage extends ClubsHelperPartTextfield
{
protected function getPartName()
{
return 'club.homepage';
}
protected function getEditContent()
{
$clubFactory = new CommonClubsModelFactoryClub();
$club = $clubFactory->loadById($this->id);
return htmlentities($club->getHomepage());
}
}

View File

@ -0,0 +1,21 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class ClubsPartClubIban extends ClubsHelperPartTextfield
{
protected function getPartName()
{
return 'club.iban';
}
protected function getEditContent()
{
$clubFactory = new CommonClubsModelFactoryClub();
$club = $clubFactory->loadById($this->id);
return htmlentities($club->getIban());
}
}

View File

@ -0,0 +1,21 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class ClubsPartClubMail extends ClubsHelperPartTextfield
{
protected function getPartName()
{
return 'club.mail';
}
protected function getEditContent()
{
$clubFactory = new CommonClubsModelFactoryClub();
$club = $clubFactory->loadById($this->id);
return htmlentities($club->getMail());
}
}

View File

@ -0,0 +1,26 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class ClubsPartClubName extends ClubsHelperPartTextfield
{
protected function getPartName()
{
return 'club.name';
}
protected function getEditContent()
{
$clubFactory = new CommonClubsModelFactoryClub();
$club = $clubFactory->loadById($this->id);
return htmlentities($club->getName());
}
protected function getEditSymbolSize()
{
return '100%';
}
}

View File

@ -5,33 +5,78 @@ use Joomla\CMS\Router\Route;
// No direct access. // No direct access.
defined('_JEXEC') or die; defined('_JEXEC') or die;
$clubid = $this->club->getId();
?> ?>
<h1><?php echo htmlentities($this->club->getName()); ?></h1> <h1><span class='clubs_content_row'><?php
// echo htmlentities($this->club->getName());
$partHandler = new ClubsPartClubName($clubid);
echo $partHandler->getViewPart();
?></span></h1>
<div class='clubs_row'> <div class='clubs_row'>
<div class='clubs_title_row'>Adresse</div> <div class='clubs_title_row'>Adresse</div>
<div class='clubs_content_row'><?php echo nl2br(htmlentities($this->club->getAddress())); ?></div> <div class='clubs_content_row'>
<?php
$partHandler = new ClubsPartClubAddress($clubid);
echo $partHandler->getViewPart();
?>
</div>
</div> </div>
<div class='clubs_row'> <div class='clubs_row'>
<div class='clubs_title_row'>Stadt</div> <div class='clubs_title_row'>Stadt</div>
<div class='clubs_content_row'><?php echo htmlentities($this->club->getCity()); ?></div> <div class='clubs_content_row'>
<?php
$partHandler = new ClubsPartClubCity($clubid);
echo $partHandler->getViewPart();
?>
</div>
</div> </div>
<div class='clubs_row'> <div class='clubs_row'>
<div class='clubs_title_row'>Homepage</div> <div class='clubs_title_row'>Homepage</div>
<div class='clubs_content_row'><a href='<?php echo htmlentities($this->club->getHomepage()); ?>' target='_blank'><?php echo htmlentities($this->club->getHomepage()); ?></a></div> <div class='clubs_content_row'>
<?php
$partHandler = new ClubsPartClubHomepage($clubid);
echo $partHandler->getViewPart();
?><!-- <a href='<?php echo htmlentities($this->club->getHomepage()); ?>' target='_blank'><?php echo htmlentities($this->club->getHomepage()); ?></a>-->
</div>
</div> </div>
<div class='clubs_row'> <div class='clubs_row'>
<div class='clubs_title_row'>Mail-Adresse</div> <div class='clubs_title_row'>Mail-Adresse</div>
<div class='clubs_content_row'><a href='mailto:<?php echo htmlentities($this->club->getMail()); ?>'><?php echo htmlentities($this->club->getMail()); ?></a></div> <div class='clubs_content_row'>
<?php
$partHandler = new ClubsPartClubMail($clubid);
echo $partHandler->getViewPart();
?>
<!--
<a href='mailto:<?php echo htmlentities($this->club->getMail()); ?>'><?php echo htmlentities($this->club->getMail()); ?></a>
-->
</div>
</div> </div>
<div class='clubs_row'> <div class='clubs_row'>
<div class='clubs_title_row'>IBAN / BIC</div> <div class='clubs_title_row'>IBAN / BIC</div>
<div class='clubs_content_row'><?php echo htmlentities($this->club->getIban()); ?> / <?php echo htmlentities($this->club->getBic()); ?></div> <div class='clubs_content_row' style='display: flex;'>
<div style='flex: 1 0 0;'>
<?php
$partHandler = new ClubsPartClubIban($clubid);
echo $partHandler->getViewPart();
// echo htmlentities($this->club->getIban());
?>
</div>
<span style='margin: 0px 0.75em'>/</span>
<div style='flex: 1 0 0;'>
<?php
$partHandler = new ClubsPartClubBic($clubid);
echo $partHandler->getViewPart();
// echo htmlentities($this->club->getBic());
?>
</div>
</div>
</div> </div>
<div class='clubs_row'> <div class='clubs_row'>

View File

@ -1,7 +1,9 @@
<?php <?php
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\MVC\View\HtmlView; use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\Uri\Uri;
// No direct access. // No direct access.
defined('_JEXEC') or die; defined('_JEXEC') or die;
@ -24,6 +26,9 @@ class ClubsViewClub extends HtmlView
$this->hasOffers = true; $this->hasOffers = true;
break; break;
} }
HTMLHelper::_('jquery.framework');
Factory::getDocument()->addScript(Uri::base(true) . "components/com_clubs/js/edit.js");
parent::display($tpl); parent::display($tpl);
} }
} }

View File

@ -19,7 +19,11 @@ class ClubsViewPart extends HtmlView
$mode = $input->get->getCmd('mode', 'view'); $mode = $input->get->getCmd('mode', 'view');
$type = $input->get->getCmd('type'); $type = $input->get->getCmd('type');
$parthandler = $this->getPart($type); $id = (int) $input->get->getInt('id', -1);
if($id == -1)
$id = null;
$parthandler = $this->getPart($type, $id);
if($mode === 'view') if($mode === 'view')
$this->view($parthandler); $this->view($parthandler);
@ -45,7 +49,7 @@ class ClubsViewPart extends HtmlView
echo $parthandler->getEditPart(); echo $parthandler->getEditPart();
} }
private function getPart($type) private function getPart($type, $id)
{ {
if(! preg_match('/.*\..*/', $type)) if(! preg_match('/.*\..*/', $type))
throw new Exception(); throw new Exception();
@ -70,7 +74,37 @@ class ClubsViewPart extends HtmlView
return new ClubsPartUserPhone(); return new ClubsPartUserPhone();
case 'mobile': case 'mobile':
return new ClubsPartUserMobile(); return new ClubsPartUserMobile();
default:
throw new Exception('Internal Error');
} }
break;
case 'club':
switch($fcn)
{
case 'name':
return new ClubsPartClubName($id);
case 'address':
return new ClubsPartClubAddress($id);
case 'city':
return new ClubsPartClubCity($id);
case 'homepage':
return new ClubsPartClubHomepage($id);
case 'mail':
return new ClubsPartClubMail($id);
case 'iban':
return new ClubsPartClubIban($id);
case 'bic':
return new ClubsPartClubBic($id);
default:
throw new Exception('Internal Error');
}
break;
default:
throw new Exception("Internal Error");
} }
} }
} }