configure first day of week for calendar and date-picker (#1952)
This commit is contained in:
@@ -32,7 +32,7 @@ class HomepageController extends AbstractController
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$userRoute = $user->getPreferenceValue('login.initial_view', InitialViewType::DEFAULT_VIEW);
|
||||
$userLanguage = $user->getLocale();
|
||||
$userLanguage = $user->getLanguage();
|
||||
$requestLanguage = $request->getLocale();
|
||||
|
||||
if (empty($requestLanguage)) {
|
||||
|
||||
@@ -271,7 +271,7 @@ class ProfileController extends AbstractController
|
||||
/** @var UserPreference $pref */
|
||||
foreach ($iterator as $pref) {
|
||||
if ($pref->isEnabled()) {
|
||||
$sections[$pref->getSection()][] = $pref->getName();
|
||||
$sections[$pref->getSection()] = $pref->getSection();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Constants;
|
||||
use App\Export\Annotation as Exporter;
|
||||
use App\Utils\StringHelper;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
@@ -69,7 +70,8 @@ class User extends BaseUser implements UserInterface
|
||||
public const ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN';
|
||||
|
||||
public const DEFAULT_ROLE = self::ROLE_USER;
|
||||
public const DEFAULT_LANGUAGE = 'en';
|
||||
public const DEFAULT_LANGUAGE = Constants::DEFAULT_LOCALE;
|
||||
public const DEFAULT_FIRST_WEEKDAY = 'monday';
|
||||
|
||||
public const AUTH_INTERNAL = 'kimai';
|
||||
public const AUTH_LDAP = 'ldap';
|
||||
@@ -367,6 +369,11 @@ class User extends BaseUser implements UserInterface
|
||||
$this->setPreferenceValue(UserPreference::LOCALE, $language);
|
||||
}
|
||||
|
||||
public function getFirstDayOfWeek(): string
|
||||
{
|
||||
return $this->getPreferenceValue(UserPreference::FIRST_WEEKDAY, User::DEFAULT_FIRST_WEEKDAY);
|
||||
}
|
||||
|
||||
public function setTimezone(?string $timezone)
|
||||
{
|
||||
if ($timezone === null) {
|
||||
|
||||
@@ -31,6 +31,7 @@ class UserPreference
|
||||
public const SKIN = 'skin';
|
||||
public const LOCALE = 'language';
|
||||
public const TIMEZONE = 'timezone';
|
||||
public const FIRST_WEEKDAY = 'first_weekday';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
|
||||
@@ -15,6 +15,7 @@ use App\Entity\UserPreference;
|
||||
use App\Event\PrepareUserEvent;
|
||||
use App\Event\UserPreferenceEvent;
|
||||
use App\Form\Type\CalendarViewType;
|
||||
use App\Form\Type\FirstWeekDayType;
|
||||
use App\Form\Type\InitialViewType;
|
||||
use App\Form\Type\LanguageType;
|
||||
use App\Form\Type\SkinType;
|
||||
@@ -126,10 +127,17 @@ class UserPreferenceSubscriber implements EventSubscriberInterface
|
||||
(new UserPreference())
|
||||
->setName(UserPreference::LOCALE)
|
||||
->setValue($this->getDefaultLanguage())
|
||||
->setOrder(300)
|
||||
->setOrder(250)
|
||||
->setSection('locale')
|
||||
->setType(LanguageType::class),
|
||||
|
||||
(new UserPreference())
|
||||
->setName(UserPreference::FIRST_WEEKDAY)
|
||||
->setValue(User::DEFAULT_FIRST_WEEKDAY)
|
||||
->setOrder(300)
|
||||
->setSection('locale')
|
||||
->setType(FirstWeekDayType::class),
|
||||
|
||||
(new UserPreference())
|
||||
->setName(UserPreference::SKIN)
|
||||
->setValue($this->getDefaultTheme())
|
||||
|
||||
46
src/Form/Type/FirstWeekDayType.php
Normal file
46
src/Form/Type/FirstWeekDayType.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Custom form field type to select the first of the week.
|
||||
*/
|
||||
class FirstWeekDayType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$choices = [
|
||||
'Monday' => 'monday',
|
||||
'Sunday' => 'sunday'
|
||||
];
|
||||
|
||||
$resolver->setDefaults([
|
||||
'multiple' => false,
|
||||
'choices' => $choices,
|
||||
'label' => 'first_weekday',
|
||||
'translation_domain' => 'system-configuration'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return ChoiceType::class;
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ final class UserMails implements FOSMailerInterface
|
||||
public function sendConfirmationEmailMessage(UserInterface $user)
|
||||
{
|
||||
$username = $user->getUsername();
|
||||
$language = 'en';
|
||||
$language = User::DEFAULT_LANGUAGE;
|
||||
|
||||
if ($user instanceof User) {
|
||||
$username = $user->getDisplayName();
|
||||
@@ -70,7 +70,7 @@ final class UserMails implements FOSMailerInterface
|
||||
public function sendResettingEmailMessage(UserInterface $user)
|
||||
{
|
||||
$username = $user->getUsername();
|
||||
$language = 'en';
|
||||
$language = User::DEFAULT_LANGUAGE;
|
||||
|
||||
if ($user instanceof User) {
|
||||
$username = $user->getDisplayName();
|
||||
|
||||
@@ -42,9 +42,24 @@ class Extensions extends AbstractExtension
|
||||
{
|
||||
return [
|
||||
new TwigFunction('class_name', [$this, 'getClassName']),
|
||||
new TwigFunction('iso_day_by_name', [$this, 'getIsoDayByName']),
|
||||
];
|
||||
}
|
||||
|
||||
public function getIsoDayByName(string $weekDay): int
|
||||
{
|
||||
$key = array_search(
|
||||
strtolower($weekDay),
|
||||
['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']
|
||||
);
|
||||
|
||||
if (false === $key) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return ++$key;
|
||||
}
|
||||
|
||||
public function color(EntityWithMetaFields $entity): ?string
|
||||
{
|
||||
if ($entity instanceof Activity) {
|
||||
@@ -77,7 +92,7 @@ class Extensions extends AbstractExtension
|
||||
* @param object $object
|
||||
* @return null|string
|
||||
*/
|
||||
public function getClassName($object)
|
||||
public function getClassName($object): ?string
|
||||
{
|
||||
if (!\is_object($object)) {
|
||||
return null;
|
||||
@@ -107,11 +122,7 @@ class Extensions extends AbstractExtension
|
||||
return implode(PHP_EOL, $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @return string
|
||||
*/
|
||||
public function documentationLink($url = '')
|
||||
public function documentationLink(?string $url = ''): string
|
||||
{
|
||||
return Constants::HOMEPAGE . '/documentation/' . $url;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user