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->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() { // 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()) { 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 ); 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);'; $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']], ]; $response = dbConnector::query($query, $params); return dbConnector::getLastInsertId(); } /** Name of the table with all the Users * * @var string */ private static $tableName = 'wkParticipo_Users'; /** columns in the User table (in the database) with their type * * @var array */ private static $dbColumns = [ 'id' => PDO::PARAM_INT, 'loginName' => PDO::PARAM_STR, 'name' => PDO::PARAM_STR, 'vorname' => PDO::PARAM_STR, 'gebDatum' => PDO::PARAM_STR, 'eMail' => PDO::PARAM_STR, 'config' => PDO::PARAM_STR, 'pwHash' => PDO::PARAM_STR ]; //// // html interface //// public static function getHtmlFormAddUser($options = []) { $returnToUrl = $options['returnToUrl'] ?? urlencode(getCurPagesUrl()); $formClass = isset($options['formClass']) ? 'class="' . $options['formClass'] . '"' : ''; $form = '
'; return $form; } public static function htmlFormAddUser($options = []) { echo(self::getHtmlFormAddUser($options)); } // member variables private $id; private $loginName; private $name; private $firstName; private $dateOfBirth; private $eMail; 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 = <<