fix: profile view

This commit is contained in:
grandeljay 2023-09-06 11:09:13 +02:00
parent b12548656e
commit 15bf22ba80
2 changed files with 65 additions and 22 deletions

View file

@ -1,8 +1,6 @@
<?php
/**
* user.php
*
* A wishthis user.
*
* @author Jay Trees <github.jay@grandel.anonaddy.me>
@ -107,9 +105,9 @@ class User
/**
* A unix timestamp of the users birthdate.
*
* @var int|null
* @var string
*/
private ?int $birthdate;
private string $birthdate;
/**
* More accurately, this is the users locale (e. g. `en_GB`).
@ -176,7 +174,7 @@ class User
$this->password_reset_valid_until = \strtotime($fields['password_reset_valid_until']);
$this->last_login = \strtotime($fields['last_login']);
$this->power = $fields['power'];
$this->birthdate = \strtotime($fields['birthdate'] ?? 0);
$this->birthdate = $fields['birthdate'] ?? '';
$this->language = $fields['language'];
$this->currency = $fields['currency'];
$this->name_first = $fields['name_first'] ?? '';
@ -477,4 +475,49 @@ class User
{
return $this->power;
}
public function getFirstName(): string
{
return $this->name_first;
}
public function getLastName(): string
{
return $this->name_last;
}
public function getNickName(): string
{
return $this->name_nick;
}
public function getBirthdate(): string
{
return $this->birthdate;
}
public function setBirthdate(string $birthdate): void
{
$this->birthdate = $birthdate;
}
public function getChannel(): string
{
return $this->channel;
}
public function setChannel(string $channel): void
{
$this->channel = $channel;
}
public function getAdvertisements(): bool
{
return $this->advertisements;
}
public function setAdvertisements(bool $advertisements): void
{
$this->advertisements = $advertisements;
}
}

View file

@ -53,7 +53,7 @@ if (isset($_POST['user-id'], $_POST['section'])) {
}
}
if (!empty($_POST['user-email']) && $_POST['user-email'] !== $user->email) {
if (!empty($_POST['user-email']) && $_POST['user-email'] !== $user->getEmail()) {
$loginRequired = true;
}
@ -62,13 +62,13 @@ if (isset($_POST['user-id'], $_POST['section'])) {
*/
if (isset($_POST['user-birthdate'])) {
if (empty($_POST['user-birthdate'])) {
$user->birthdate = null;
$user->setBirthdate('');
$set[] = '`birthdate` = NULL';
} else {
$user->birthdate = date('Y-m-d', strtotime($_POST['user-birthdate']));
$user->setBirthdate($_POST['user-birthdate']);
$set[] = '`birthdate` = "' . $user->birthdate . '"';
$set[] = '`birthdate` = "' . $_POST['user-birthdate'] . '"';
}
}
@ -122,25 +122,25 @@ if (isset($_POST['user-id'], $_POST['section'])) {
}
/** Channel */
if (isset($_POST['user-channel']) && $_POST['user-channel'] !== $user->channel) {
if (isset($_POST['user-channel']) && $_POST['user-channel'] !== $user->getChannel()) {
if (empty($_POST['user-channel'])) {
$user->channel = null;
$user->setChannel('');
$set[] = '`channel` = NULL';
} else {
$user->channel = $_POST['user-channel'];
$user->setChannel($_POST['user-channel']);
$set[] = '`channel` = "' . $user->channel . '"';
$set[] = '`channel` = "' . $_POST['user-channel'] . '"';
}
}
/** Advertisements */
if (isset($_POST['enable-advertisements'])) {
$user->advertisements = true;
$user->setAdvertisements(true);
$set[] = '`advertisements` = TRUE';
} else {
$user->advertisements = false;
$user->setAdvertisements(false);
$set[] = '`advertisements` = FALSE';
}
@ -225,19 +225,19 @@ $page->navigation();
<div class="field">
<label><?= __('First name') ?></label>
<input type="text" name="user-name-first" value="<?= $user->name_first ?>" />
<input type="text" name="user-name-first" value="<?= $user->getFirstName() ?>" />
</div>
<div class="field">
<label><?= __('Last name') ?></label>
<input type="text" name="user-name-last" value="<?= $user->name_last ?>" />
<input type="text" name="user-name-last" value="<?= $user->getLastName() ?>" />
</div>
<div class="field">
<label><?= __('Nickname') ?></label>
<input type="text" name="user-name-nick" value="<?= $user->name_nick ?>" />
<input type="text" name="user-name-nick" value="<?= $user->getNickName() ?>" />
</div>
</div>
@ -245,7 +245,7 @@ $page->navigation();
<div class="field">
<label><?= __('Email') ?></label>
<input type="email" name="user-email" value="<?= $user->email ?>" />
<input type="email" name="user-email" value="<?= $user->getEmail() ?>" />
</div>
<div class="field" data-content="<?= __('Used to suggest a wishlist called "Birthday", if it\'s coming up.') ?>">
@ -260,7 +260,7 @@ $page->navigation();
<input type="text"
name="user-birthdate"
placeholder="<?= __('Pick a date') ?>"
value="<?= $user->birthdate ?>"
value="<?= $user->getBirthdate() ?>"
/>
</div>
</div>
@ -462,7 +462,7 @@ $page->navigation();
<option value=""><?= __('Select channel') ?></option>
<?php foreach (CHANNELS as $channel) { ?>
<?php if ($channel['branch'] === $user->channel) { ?>
<?php if ($channel['branch'] === $user->getChannel()) { ?>
<option value="<?= $channel['branch'] ?>" selected><?= $channel['label'] ?></option>
<?php } else { ?>
<option value="<?= $channel['branch'] ?>"><?= $channel['label'] ?></option>
@ -519,7 +519,7 @@ $page->navigation();
<label><?= __('Advertisements') ?></label>
<div class="ui toggle checkbox advertisements">
<?php if (true === $user->advertisements) { ?>
<?php if (true === $user->getAdvertisements()) { ?>
<input type="checkbox" name="enable-advertisements" checked="checked" />
<?php } else { ?>
<input type="checkbox" name="enable-advertisements" />