added dynamic user preferences #7 #9 (#90)

- fixed user settings database #9
- added dynamic user preferences #9
- added form to edit user preferences #9
- removed user language #7
This commit is contained in:
Kevin Papst
2018-01-14 22:47:20 +01:00
committed by GitHub
parent 023fef6a70
commit 49d8796f6b
23 changed files with 758 additions and 181 deletions

View File

@@ -0,0 +1,76 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Event;
use App\Entity\User;
use App\Entity\UserPreference;
use Symfony\Component\EventDispatcher\Event;
/**
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class UserPreferenceEvent extends Event
{
const CONFIGURE = 'app.user_preferences';
/**
* @var User
*/
protected $user;
/**
* @var UserPreference[]
*/
protected $preferences;
/**
* UserPreferenceEvent constructor.
* @param User $user
* @param UserPreference[] $preferences
*/
public function __construct(User $user, array $preferences)
{
$this->user = $user;
$this->preferences = $preferences;
}
/**
* @return User
*/
public function getUser()
{
return $this->user;
}
/**
* @return UserPreference[]
*/
public function getPreferences()
{
return $this->preferences;
}
/**
* @param UserPreference $preference
*/
public function addUserPreference(UserPreference $preference)
{
foreach ($this->preferences as $pref) {
if ($pref->getName() == $preference->getName()) {
throw new \InvalidArgumentException(
'Cannot add preference, a preference with the name "'.$preference->getName().'" is already existing'
);
}
}
$this->preferences[] = $preference;
}
}