Newsletter KW 30 and the weeks before

This commit is contained in:
marko
2023-07-29 16:55:49 +02:00
parent 2e7c5f86e5
commit 662830460c
42 changed files with 830 additions and 256 deletions

View File

@@ -10,51 +10,66 @@ class User
* @todo Document parameter
* @todo Input sanitation
*/
public function __construct($id, $loginName, $name, $firstName, $dateOfBirth=null, $eMail=null, $config=null, $pwHash=null)
public function __construct($id, $loginName, $name, $firstName, $dateOfBirth = null, $eMail = null, $config = null, $pwHash = null)
{
$this->id = filterId($id);
$this->loginName = $loginName;
$this->name = $name;
$this->firstName = $firstName;
$this->dateOfBirth = ($dateOfBirth != null) ? DateTime::createFromFormat('Y-m-d', $dateOfBirth) : null;
$this->eMail = ($eMail!=null) ? filter_var($eMail, FILTER_VALIDATE_EMAIL,['options'=>['default'=>null]]):null;
$this->eMail = ($eMail != null) ? filter_var($eMail, FILTER_VALIDATE_EMAIL, ['options' => ['default' => null]]) : null;
$this->config = $config;
$this->pwHash = $pwHash;
}
/** return users year of birth as int
*
* @retval int>=0 on success,
* @retval null failure
*/
public function yearOfBirth()
{
if (isset($this->dateOfBirth)) {
return filterPosInt($this->dateOfBirth->format('Y'));
}
return null;
}
////
// dbInterface
////
public function addToDb(){
public function addToDb()
{
// if the user has an Id set it has to come from the Db. Hence don't add an User that is already added.
if(isset($this->id) || !participo::isUserAdmin()){
if (isset($this->id) || !participo::isUserAdmin()) {
return;
}
$this->id = self::dbInsert(
$this->loginName
, $this->name
, $this->firstName
, (isset($this->dateOfBirth))?($this->dateOfBirth->format('Y-m-d')):null
, $this->eMail
, $this->config
, $this->pwHash
$this->loginName,
$this->name,
$this->firstName,
(isset($this->dateOfBirth)) ? ($this->dateOfBirth->format('Y-m-d')) : null,
$this->eMail,
$this->config,
$this->pwHash
);
return $this->id;
}
private static function dbInsert($loginName, $name, $firstName, $dateOfBirth=null, $eMail=null, $config=null, $pwHash=null){
$query = 'INSERT INTO `'.self::$tableName.'` '
.'(loginName, name, vorname, gebDatum, eMail, config, pwHash) '
.' VALUES (:loginName, :name, :vorname, :gebDatum, :eMail, :config, :pwHash);';
private static function dbInsert($loginName, $name, $firstName, $dateOfBirth = null, $eMail = null, $config = null, $pwHash = null)
{
$query = 'INSERT INTO `' . self::$tableName . '` '
. '(loginName, name, vorname, gebDatum, eMail, config, pwHash) '
. ' VALUES (:loginName, :name, :vorname, :gebDatum, :eMail, :config, :pwHash);';
$params = [
':loginName'=>['value'=>$loginName, 'data_type' => self::$dbColumns['loginName']],
':name'=>['value'=>$name, 'data_type' => self::$dbColumns['name']],
':vorname'=>['value'=>$firstName, 'data_type' => self::$dbColumns['vorname']],
':gebDatum'=>['value'=>$dateOfBirth, 'data_type' => self::$dbColumns['gebDatum']],
':eMail'=>['value'=>$eMail, 'data_type' => self::$dbColumns['eMail']],
':config'=>['value'=>$config, 'data_type' => self::$dbColumns['config']],
':pwHash'=>['value'=>$pwHash, 'data_type' => self::$dbColumns['pwHash']],
':loginName' => ['value' => $loginName, 'data_type' => self::$dbColumns['loginName']],
':name' => ['value' => $name, 'data_type' => self::$dbColumns['name']],
':vorname' => ['value' => $firstName, 'data_type' => self::$dbColumns['vorname']],
':gebDatum' => ['value' => $dateOfBirth, 'data_type' => self::$dbColumns['gebDatum']],
':eMail' => ['value' => $eMail, 'data_type' => self::$dbColumns['eMail']],
':config' => ['value' => $config, 'data_type' => self::$dbColumns['config']],
':pwHash' => ['value' => $pwHash, 'data_type' => self::$dbColumns['pwHash']],
];
$response = dbConnector::query($query, $params);
return dbConnector::getLastInsertId();
@@ -81,7 +96,6 @@ class User
'pwHash' => PDO::PARAM_STR
];
////
// html interface
////
@@ -89,26 +103,26 @@ class User
public static function getHtmlFormAddUser($options = [])
{
$returnToUrl = $options['returnToUrl'] ?? urlencode(getCurPagesUrl());
$formClass = isset($options['formClass']) ? 'class="'.$options['formClass'].'"' : '';
$formClass = isset($options['formClass']) ? 'class="' . $options['formClass'] . '"' : '';
$form =
'<form ' . $formClass . ' action="api.user.add.php" method="post">'
. '<input type="hidden" name="returnToUrl" id="returnToUrl" value="' . $returnToUrl . '" >'
.'<div><label for="loginName">Benutzername</label> <input type="text" name="loginName" id="loginName"></div>'
.'<div><label for="name">Nachname</label> <input type="text" name="name" id="name"></div>'
.'<div><label for="firstName">Vorname</label> <input type="text" name="firstName" id="firstName"></div>'
.'<div><label for="dateOfBirth">Geb.Datum</label> <input type="text" name="dateOfBirth" id="dateOfBirth"></div>'
.'<div><label for="eMail">eMail</label> <input type="text" name="eMail" id="eMail"></div>'
. '<div><label for="loginName">Benutzername</label> <input type="text" name="loginName" id="loginName"></div>'
. '<div><label for="name">Nachname</label> <input type="text" name="name" id="name"></div>'
. '<div><label for="firstName">Vorname</label> <input type="text" name="firstName" id="firstName"></div>'
. '<div><label for="dateOfBirth">Geb.Datum</label> <input type="text" name="dateOfBirth" id="dateOfBirth"></div>'
. '<div><label for="eMail">eMail</label> <input type="text" name="eMail" id="eMail"></div>'
. '<button class="btn" type="submit" name="submit">erstellen</button>'
. '</form>';
return $form;
}
public static function htmlFormAddUser($options = []){
public static function htmlFormAddUser($options = [])
{
echo(self::getHtmlFormAddUser($options));
}
// member variables
private $id;
private $loginName;
@@ -119,6 +133,49 @@ class User
private $config;
private $pwHash;
// database member data
/** List of ids of the users kids */
private $kidIds = null;
/** List of users kids */
private $kids = null;
public function kidIds(bool $forceLoading = false)
{
if (is_null($this->kidIds) || $forceLoading) {
$this->kidIds = self::getKidIds($id);
}
return self::$kidIds;
}
public function kids(bool $forceLoading = false)
{
if (is_null($this->kids) || $forceLoading) {
$this->kids = participo::getKids($this->id);
}
return $this->kids;
}
private static function getKidIds(int $id)
{
$response = dbConnector::query(
'SELECT * FROM `wkParticipo_Users` WHERE `' . $name . '` = :' . $name,
[$name => ['value' => $value, 'data_type' => self::$dbColumns[$name]]]
);
$query = <<<SQL
SELECT *
FROM `wkParticipo_Users`
JOIN `vormundschaft`
ON `wkParticipo_Users`.`id` = `vormundschaft`.`kidId`
WHERE `vormundschaft`.`userId` = :userId;
SQL;
$params = [
':userId' => ['value' => $userId, 'data_type' => PDO::PARAM_INT]
];
$response = dbConnector::query($query, $params);
return $response;
}
/** Export the User data into an associative array
*
* @return array associative array representing the user
@@ -192,7 +249,9 @@ class User
}
return new User(
$member[$columnMappings['id']] ?? null,
$member[
$columnMappings['id']
] ?? null,
$member[$columnMappings['loginName']] ?? null,
$member[$columnMappings['name']] ?? null,
$member[$columnMappings['vorname']] ?? null,
@@ -244,7 +303,6 @@ class User
if (count($response) != 1) {
return null;
}
return User::fromDbArray($response[0]);
}
}