Club frontend partly created, missing the special cases

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

View File

@@ -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";
}
}