Add currency option
This commit is contained in:
parent
d9f4d45a06
commit
d30126bfec
7 changed files with 126 additions and 30 deletions
|
@ -68,11 +68,14 @@ $(function() {
|
|||
* Preferences
|
||||
*/
|
||||
|
||||
/** Language */
|
||||
$('.ui.dropdown.locale').dropdown({
|
||||
sortSelect : 'natural',
|
||||
fullTextSearch : true,
|
||||
});
|
||||
/** Locale */
|
||||
var dropdown_locale_settings = {
|
||||
'sortSelect' : 'natural',
|
||||
'fullTextSearch' : true,
|
||||
};
|
||||
|
||||
$('.ui.dropdown.language').dropdown(dropdown_locale_settings);
|
||||
$('.ui.dropdown.currency').dropdown(dropdown_locale_settings);
|
||||
|
||||
/** Channel */
|
||||
$('.ui.dropdown.channel').dropdown();
|
||||
|
|
|
@ -44,7 +44,8 @@ class User
|
|||
/**
|
||||
* Private
|
||||
*/
|
||||
private string $locale;
|
||||
private string $language;
|
||||
private string $currency;
|
||||
|
||||
/**
|
||||
* Non-Static
|
||||
|
@ -61,12 +62,12 @@ class User
|
|||
}
|
||||
}
|
||||
|
||||
/** Set Locale */
|
||||
if (!isset($this->locale)) {
|
||||
$this->locale = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']) : DEFAULT_LOCALE;
|
||||
/** Set Language */
|
||||
if (!isset($this->language)) {
|
||||
$this->language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']) : DEFAULT_LOCALE;
|
||||
}
|
||||
|
||||
$this->setLocale($this->locale);
|
||||
$this->setLocale($this->language);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,15 +85,34 @@ class User
|
|||
if (file_exists($translationFilepath)) {
|
||||
$loader = new \Gettext\Loader\PoLoader();
|
||||
$this->translations = $loader->loadFile($translationFilepath);
|
||||
} else {
|
||||
trigger_error('Unable to find translations for ' . $locale . ', defaulting to ' . DEFAULT_LOCALE . '.', E_USER_NOTICE);
|
||||
}
|
||||
|
||||
/** Set locale */
|
||||
$this->locale = $locale;
|
||||
$this->language = $locale;
|
||||
}
|
||||
|
||||
public function getLocale(): string
|
||||
{
|
||||
return $this->locale;
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user currency
|
||||
*
|
||||
* @param string $locale
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setCurrency(string $locale): void
|
||||
{
|
||||
$this->currency = $locale;
|
||||
}
|
||||
|
||||
public function getCurrency(): string
|
||||
{
|
||||
return $this->currency;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -121,7 +121,7 @@ class Wish
|
|||
|
||||
$userCard = User::getFromID($ofUser);
|
||||
$numberFormatter = new \NumberFormatter(
|
||||
$userCard->getLocale(),
|
||||
$userCard->getLocale() . '@currency=' . $userCard->getCurrency(),
|
||||
\NumberFormatter::CURRENCY
|
||||
);
|
||||
$userIsCurrent = isset($_SESSION['user']->id) && $_SESSION['user']->id === $userCard->id;
|
||||
|
|
|
@ -108,16 +108,22 @@ $page->navigation();
|
|||
</li>
|
||||
<li>
|
||||
<?php
|
||||
/** TRANSLATORS: Changelog: Roadmap */
|
||||
/** TRANSLATORS: Changelog: Added */
|
||||
echo __('Compact/list view for wishes');
|
||||
?>
|
||||
</li>
|
||||
<li>
|
||||
<?php
|
||||
/** TRANSLATORS: Changelog: Roadmap */
|
||||
/** TRANSLATORS: Changelog: Added */
|
||||
echo __('Option to enable advertisements');
|
||||
?>
|
||||
</li>
|
||||
<li>
|
||||
<?php
|
||||
/** TRANSLATORS: Changelog: Added */
|
||||
echo __('Option to set currency');
|
||||
?>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3 class="ui header"><?= __('Improved') ?></h3>
|
||||
|
|
|
@ -146,6 +146,9 @@ switch ($step) {
|
|||
/**
|
||||
* Users
|
||||
*/
|
||||
$currencyFormatter = new \NumberFormatter(DEFAULT_LOCALE, \NumberFormatter::CURRENCY);
|
||||
$currencyISO = $currencyFormatter->getSymbol(\NumberFormatter::INTL_CURRENCY_SYMBOL);
|
||||
|
||||
$database->query('DROP TABLE IF EXISTS `users`;');
|
||||
$database->query(
|
||||
'CREATE TABLE `users` (
|
||||
|
@ -157,7 +160,8 @@ switch ($step) {
|
|||
`last_login` DATETIME NOT NULL DEFAULT NOW(),
|
||||
`power` INT NOT NULL DEFAULT 0,
|
||||
`birthdate` DATE NULL DEFAULT NULL,
|
||||
`locale` VARCHAR(5) NOT NULL DEFAULT "' . DEFAULT_LOCALE . '",
|
||||
`language` VARCHAR(5) NOT NULL DEFAULT "' . DEFAULT_LOCALE . '",
|
||||
`currency` VARCHAR(3) NOT NULL DEFAULT "' . $currencyISO . '",
|
||||
`name_first` VARCHAR(32) NULL DEFAULT NULL,
|
||||
`name_last` VARCHAR(32) NULL DEFAULT NULL,
|
||||
`name_nick` VARCHAR(32) NULL DEFAULT NULL,
|
||||
|
|
|
@ -87,16 +87,34 @@ if (isset($_POST['user-id'], $_POST['section'])) {
|
|||
/**
|
||||
* Preferences
|
||||
*/
|
||||
/** Locale */
|
||||
if (isset($_POST['user-locale']) && $_POST['user-locale'] !== $_SESSION['user']->getLocale()) {
|
||||
$_SESSION['user']->setLocale($_POST['user-locale']);
|
||||
|
||||
$set[] = '`locale` = "' . $_SESSION['user']->getLocale() . '"';
|
||||
/** Language */
|
||||
if (isset($_POST['user-language']) && $_POST['user-language'] !== $_SESSION['user']->getLocale()) {
|
||||
$_SESSION['user']->setLocale($_POST['user-language']);
|
||||
|
||||
$set[] = '`language` = "' . $_SESSION['user']->getLocale() . '"';
|
||||
|
||||
$page->messages[] = Page::success(
|
||||
sprintf(
|
||||
__('Locale successfully updated!'),
|
||||
'<strong>Locale</strong>'
|
||||
/** TRANSLATORS: %s: The new locale */
|
||||
__('Language set to %s.'),
|
||||
'<strong>' . $_SESSION['user']->getLocale() . '</strong>'
|
||||
),
|
||||
__('Success')
|
||||
);
|
||||
}
|
||||
|
||||
/** Currency */
|
||||
if (isset($_POST['user-currency']) && $_POST['user-currency'] !== $_SESSION['user']->getLocale()) {
|
||||
$_SESSION['user']->setCurrency($_POST['user-currency']);
|
||||
|
||||
$set[] = '`currency` = "' . $_SESSION['user']->getCurrency() . '"';
|
||||
|
||||
$page->messages[] = Page::success(
|
||||
sprintf(
|
||||
/** TRANSLATORS: %s: The new locale */
|
||||
__('Currency set to %s.'),
|
||||
'<strong>' . $_SESSION['user']->getCurrency() . '</strong>'
|
||||
),
|
||||
__('Success')
|
||||
);
|
||||
|
@ -315,23 +333,54 @@ $page->navigation();
|
|||
<div class="field">
|
||||
<label><?= __('Language') ?></label>
|
||||
|
||||
<select class="ui search dropdown locale" name="user-locale">
|
||||
<select class="ui search dropdown language" name="user-language">
|
||||
<?php if (!in_array('en_GB', $locales)) { ?>
|
||||
<option value="<?= 'en_GB' ?>"><?= \Locale::getDisplayName('en_GB', $_SESSION['user']->getLocale()) ?></option>
|
||||
<?php } ?>
|
||||
|
||||
<?php foreach ($locales as $locale) { ?>
|
||||
<?php if (\Locale::getRegion($locale)) { ?>
|
||||
<?php if ($locale === $_SESSION['user']->getLocale()) { ?>
|
||||
<option value="<?= $locale ?>" selected><?= \Locale::getDisplayName($locale, $_SESSION['user']->getLocale()) ?></option>
|
||||
<?php } else { ?>
|
||||
<option value="<?= $locale ?>"><?= \Locale::getDisplayName($locale, $_SESSION['user']->getLocale()) ?></option>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label><?= __('Currency') ?></label>
|
||||
|
||||
<select class="ui search dropdown currency" name="user-currency">
|
||||
<?php
|
||||
$currencies = array();
|
||||
?>
|
||||
|
||||
<?php foreach ($locales as $locale) { ?>
|
||||
<?php
|
||||
$currencyFormatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
|
||||
$currencyISO = $currencyFormatter->getSymbol(\NumberFormatter::INTL_CURRENCY_SYMBOL);
|
||||
$currencySymbol = $currencyFormatter->getSymbol(\NumberFormatter::CURRENCY_SYMBOL);
|
||||
$currencyValue = $currencyISO . ' (' . $currencySymbol . ')';
|
||||
|
||||
if (in_array($currencyISO, $currencies, true) || $currencyISO === $currencySymbol) {
|
||||
continue;
|
||||
} else {
|
||||
$currencies[] = $currencyISO;
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if ($currencyISO === $_SESSION['user']->getCurrency()) { ?>
|
||||
<option value="<?= $currencyISO ?>" selected><?= $currencyValue ?></option>
|
||||
<?php } else { ?>
|
||||
<option value="<?= $currencyISO ?>"><?= $currencyValue ?></option>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<?php if (defined('CHANNELS') && is_array(CHANNELS)) { ?>
|
||||
<script type="text/javascript">
|
||||
var CHANNELS = <?= json_encode(CHANNELS) ?>;
|
||||
|
|
|
@ -6,7 +6,21 @@ TRUNCATE `sessions`;
|
|||
/**
|
||||
* Users
|
||||
*/
|
||||
ALTER TABLE
|
||||
`users` CHANGE COLUMN `locale` `language` VARCHAR(5) NOT NULL DEFAULT 'en_GB'
|
||||
AFTER
|
||||
`birthdate`;
|
||||
|
||||
ALTER TABLE
|
||||
`users`
|
||||
ADD
|
||||
COLUMN `advertisements` TINYINT(1) NOT NULL DEFAULT 0;
|
||||
COLUMN `advertisements` TINYINT(1) NOT NULL DEFAULT 0,
|
||||
ADD
|
||||
COLUMN `currency` VARCHAR(3) NOT NULL DEFAULT 'EUR'
|
||||
AFTER
|
||||
`language`;
|
||||
|
||||
UPDATE
|
||||
`users`
|
||||
SET
|
||||
`currency` = `language`;
|
||||
|
|
Loading…
Reference in a new issue