From 3f96022176c0dc10a0fb62f2d0fff9e5addbb0db Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Wed, 26 Jun 2019 14:29:24 +0200 Subject: [PATCH] Club frontend partly created, missing the special cases --- src/admin/common/models/club.php | 45 +++++++++ src/site/controllers/parts.json.php | 143 +++++++++++++++++++++++++-- src/site/css/clubs.css | 18 +++- src/site/helpers/parts.php | 32 +++++- src/site/helpers/validator.php | 29 +++++- src/site/parts/club/address.php | 31 ++++++ src/site/parts/club/bic.php | 21 ++++ src/site/parts/club/city.php | 21 ++++ src/site/parts/club/homepage.php | 21 ++++ src/site/parts/club/iban.php | 21 ++++ src/site/parts/club/mail.php | 21 ++++ src/site/parts/club/name.php | 26 +++++ src/site/views/club/tmpl/default.php | 57 +++++++++-- src/site/views/club/view.html.php | 5 + src/site/views/part/view.html.php | 38 ++++++- 15 files changed, 505 insertions(+), 24 deletions(-) create mode 100644 src/site/parts/club/address.php create mode 100644 src/site/parts/club/bic.php create mode 100644 src/site/parts/club/city.php create mode 100644 src/site/parts/club/homepage.php create mode 100644 src/site/parts/club/iban.php create mode 100644 src/site/parts/club/mail.php create mode 100644 src/site/parts/club/name.php diff --git a/src/admin/common/models/club.php b/src/admin/common/models/club.php index 96bfcb5..1855e3c 100644 --- a/src/admin/common/models/club.php +++ b/src/admin/common/models/club.php @@ -16,46 +16,91 @@ class CommonClubsModelClub extends AbstractCommonClubsModel return $this->getValues()['name']; } + public function setName($name) + { + $this->setValue('name', $name); + } + public function getAddress() { return $this->getValues()['address']; } + public function setAddress($address) + { + $this->setValue('address', $address); + } + public function getCity() { return $this->getValues()['city']; } + public function setCity($city) + { + $this->setValue('city', $city); + } + public function getHomepage() { return $this->getValues()['homepage']; } + public function setHomepage($homepage) + { + $this->setValue('homepage', $homepage); + } + public function getMail() { return $this->getValues()['mail']; } + public function setMail($mail) + { + $this->setValue('mail', $mail); + } + public function getIban() { return $this->getValues()['iban']; } + public function setIban($iban) + { + $this->setValue('iban', $iban); + } + public function getBic() { return $this->getValues()['bic']; } + public function setBic($bic) + { + $this->setValue('bic', $bic); + } + public function isCharitable() { return $this->getValues()['charitable']; } + public function setCharitable($charitable) + { + $this->setValue('charitable', $charitable); + } + public function getPresident() { return $this->getValues()['president']; } + public function setPresident($user) + { + $this->setValue('president', $user); + } + public function getPlaces() { return $this->fetchAssociatedElements(new CommonClubsModelFactoryPlace(), 'clubid'); diff --git a/src/site/controllers/parts.json.php b/src/site/controllers/parts.json.php index 9b63666..9d2d861 100644 --- a/src/site/controllers/parts.json.php +++ b/src/site/controllers/parts.json.php @@ -39,7 +39,7 @@ abstract class AbstractClubsHelperController protected function checkLen($value, $len, $msg) { - if(strlen($value) < 5) + if(strlen($value) < $len) throw new InvalidUserDataException($msg); } @@ -138,11 +138,13 @@ class ClubsHelperControllerUser extends AbstractClubsHelperController $address = trim($post->getString('value')); $this->checkLen($address, 10, 'Die Adresse muss mindestens 10 Zeichen lang sein.'); - $parts = array_filter(explode("\n", str_replace("\r", "\n", $address))); - if(count($parts) < 2) + $validator = new ClubsHelperValidator(); + $addr = ''; + $valid = $validator->validateAddress($address, $addr); + + if(! $valid) throw new InvalidUserDataException('Die Adresse muss mindestens aus 2 Zeilen bestehen.'); - $addr = join("\n", $parts); $user->setAddress($addr); $user->save(); } @@ -160,7 +162,8 @@ class ClubsHelperControllerUser extends AbstractClubsHelperController { $mail = trim($post->getString('value')); $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.'); $user->setMail($mail); @@ -219,9 +222,126 @@ class ClubsHelperControllerUser 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() - {} + { + $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; case 'club': - $obj = new ClubsHelperControllerClub(); + $clubid = $post->getInt('id', -1); + $obj = new ClubsHelperControllerClub($clubid); $obj->handle($fcnName, $user, $post); // TODO User!?!?! break; default: 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"; } } diff --git a/src/site/css/clubs.css b/src/site/css/clubs.css index 546e863..8a63510 100644 --- a/src/site/css/clubs.css +++ b/src/site/css/clubs.css @@ -5,6 +5,12 @@ padding-left: 2em; margin-bottom: 10px; } + +h1 > .clubs_content_row +{ + padding-left: 0px; +} + .clubs_title_row { font-weight: bold; @@ -35,12 +41,15 @@ table.clubs > tbody > tr > th line-height: 120%; } -.clubs_content_row .clubs-hidden +.clubs_content_row .clubs-hidden, +h1 .clubs-hidden { 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; } @@ -49,3 +58,8 @@ form.clubs-part, form.clubs-part > input { margin: 0pt; } + +form.clubs-part +{ + display: inline-block; +} diff --git a/src/site/helpers/parts.php b/src/site/helpers/parts.php index ae15f75..0ff620b 100644 --- a/src/site/helpers/parts.php +++ b/src/site/helpers/parts.php @@ -11,6 +11,16 @@ abstract class ClubsHelperParts */ abstract protected function getPartName(); + /** + * @var int + */ + protected $id; + + public function __construct($id = null) + { + $this->id = $id; + } + /** * @return string */ @@ -18,11 +28,16 @@ abstract class ClubsHelperParts { $partname = $this->getPartName(); - $ret = "
"; + $ret = ""; $ret .= ""; + if(isset($this->id)) + $ret .= ""; $ret .= $this->getEditMarkup(); $ret .= '  '; - $ret .= ''; + $idPart = ''; + if(isset($this->id)) + $idPart = "&id=" . $this->id; + $ret .= ''; $ret .= '
'; return $ret; @@ -54,12 +69,19 @@ abstract class ClubsHelperParts */ public function getViewPart() { - $ret = ''; + $idPart = ''; + if(isset($this->id)) + $idPart = "&id={$this->id}"; - $ret = ""; + $ret = ""; $ret .= $this->getViewContent(); - $ret .= ""; + $ret .= ""; return $ret; } + + protected function getEditSymbolSize() + { + return '120%'; + } } diff --git a/src/site/helpers/validator.php b/src/site/helpers/validator.php index 417e1ae..a250303 100644 --- a/src/site/helpers/validator.php +++ b/src/site/helpers/validator.php @@ -42,4 +42,31 @@ class ClubsHelperValidator return self::USERNAME_VALID; } -} \ No newline at end of file + 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 + } + +} diff --git a/src/site/parts/club/address.php b/src/site/parts/club/address.php new file mode 100644 index 0000000..936c8b1 --- /dev/null +++ b/src/site/parts/club/address.php @@ -0,0 +1,31 @@ +loadById($this->id); + + return htmlentities($club->getAddress()); + } + + protected function getViewContent() + { + return nl2br(parent::getViewContent()); + } + + protected function additionalParams() + { + return 'rows="4"'; + } + +} diff --git a/src/site/parts/club/bic.php b/src/site/parts/club/bic.php new file mode 100644 index 0000000..97a0a9a --- /dev/null +++ b/src/site/parts/club/bic.php @@ -0,0 +1,21 @@ +loadById($this->id); + + return htmlentities($club->getBic()); + } + +} diff --git a/src/site/parts/club/city.php b/src/site/parts/club/city.php new file mode 100644 index 0000000..e7747db --- /dev/null +++ b/src/site/parts/club/city.php @@ -0,0 +1,21 @@ +loadById($this->id); + + return htmlentities($club->getCity()); + } + +} diff --git a/src/site/parts/club/homepage.php b/src/site/parts/club/homepage.php new file mode 100644 index 0000000..d768fce --- /dev/null +++ b/src/site/parts/club/homepage.php @@ -0,0 +1,21 @@ +loadById($this->id); + + return htmlentities($club->getHomepage()); + } + +} diff --git a/src/site/parts/club/iban.php b/src/site/parts/club/iban.php new file mode 100644 index 0000000..932c7e7 --- /dev/null +++ b/src/site/parts/club/iban.php @@ -0,0 +1,21 @@ +loadById($this->id); + + return htmlentities($club->getIban()); + } + +} diff --git a/src/site/parts/club/mail.php b/src/site/parts/club/mail.php new file mode 100644 index 0000000..fce7a8f --- /dev/null +++ b/src/site/parts/club/mail.php @@ -0,0 +1,21 @@ +loadById($this->id); + + return htmlentities($club->getMail()); + } + +} diff --git a/src/site/parts/club/name.php b/src/site/parts/club/name.php new file mode 100644 index 0000000..e67e685 --- /dev/null +++ b/src/site/parts/club/name.php @@ -0,0 +1,26 @@ +loadById($this->id); + + return htmlentities($club->getName()); + } + + protected function getEditSymbolSize() + { + return '100%'; + } + +} diff --git a/src/site/views/club/tmpl/default.php b/src/site/views/club/tmpl/default.php index de7a078..d61d130 100644 --- a/src/site/views/club/tmpl/default.php +++ b/src/site/views/club/tmpl/default.php @@ -5,33 +5,78 @@ use Joomla\CMS\Router\Route; // No direct access. defined('_JEXEC') or die; +$clubid = $this->club->getId(); + ?> -

club->getName()); ?>

+

club->getName()); + $partHandler = new ClubsPartClubName($clubid); + echo $partHandler->getViewPart(); +?>

Adresse
-
club->getAddress())); ?>
+
+ getViewPart(); + ?> +
Stadt
-
club->getCity()); ?>
+
+ getViewPart(); + ?> +
Homepage
- +
+ getViewPart(); + ?> +
Mail-Adresse
- +
+ getViewPart(); + ?> + +
IBAN / BIC
-
club->getIban()); ?> / club->getBic()); ?>
+
+
+ getViewPart(); +// echo htmlentities($this->club->getIban()); + ?> +
+/ +
+ getViewPart(); +// echo htmlentities($this->club->getBic()); + ?> +
+
diff --git a/src/site/views/club/view.html.php b/src/site/views/club/view.html.php index 74f1288..6d42a13 100644 --- a/src/site/views/club/view.html.php +++ b/src/site/views/club/view.html.php @@ -1,7 +1,9 @@ hasOffers = true; break; } + HTMLHelper::_('jquery.framework'); + Factory::getDocument()->addScript(Uri::base(true) . "components/com_clubs/js/edit.js"); + parent::display($tpl); } } diff --git a/src/site/views/part/view.html.php b/src/site/views/part/view.html.php index 2667356..58b37d9 100644 --- a/src/site/views/part/view.html.php +++ b/src/site/views/part/view.html.php @@ -19,7 +19,11 @@ class ClubsViewPart extends HtmlView $mode = $input->get->getCmd('mode', 'view'); $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') $this->view($parthandler); @@ -45,7 +49,7 @@ class ClubsViewPart extends HtmlView echo $parthandler->getEditPart(); } - private function getPart($type) + private function getPart($type, $id) { if(! preg_match('/.*\..*/', $type)) throw new Exception(); @@ -70,7 +74,37 @@ class ClubsViewPart extends HtmlView return new ClubsPartUserPhone(); case 'mobile': 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"); } } }