Fixed #16699 - added mutator for user locale
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
65b956143c
commit
ba55dfb841
1 changed files with 24 additions and 0 deletions
|
@ -20,6 +20,7 @@ use Illuminate\Notifications\Notifiable;
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
use Laravel\Passport\HasApiTokens;
|
use Laravel\Passport\HasApiTokens;
|
||||||
use Watson\Validating\ValidatingTrait;
|
use Watson\Validating\ValidatingTrait;
|
||||||
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
|
|
||||||
class User extends SnipeModel implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract, HasLocalePreference
|
class User extends SnipeModel implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract, HasLocalePreference
|
||||||
{
|
{
|
||||||
|
@ -844,10 +845,33 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||||
return $query->leftJoin('companies as companies_user', 'users.company_id', '=', 'companies_user.id')->orderBy('companies_user.name', $order);
|
return $query->leftJoin('companies as companies_user', 'users.company_id', '=', 'companies_user.id')->orderBy('companies_user.name', $order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a mutator to allow the emails to fall back to the system settings if no locale is set.
|
||||||
|
*
|
||||||
|
* @return Attribute
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected function locale(): Attribute
|
||||||
|
{
|
||||||
|
return Attribute::make(
|
||||||
|
set: fn ($value) => $value ?? Setting::getSettings()->locale,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the preferred locale for the user.
|
||||||
|
* This is used via the HasLocalePreference interface, which is part of Laravel. This would
|
||||||
|
* normally work natively, but because we allow the override in the Settings model and we also
|
||||||
|
* manually set it in the notifications (for now), this doesn't handle all use cases.
|
||||||
|
*
|
||||||
|
*/
|
||||||
public function preferredLocale()
|
public function preferredLocale()
|
||||||
{
|
{
|
||||||
return $this->locale;
|
return $this->locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUserTotalCost(){
|
public function getUserTotalCost(){
|
||||||
$asset_cost= 0;
|
$asset_cost= 0;
|
||||||
$license_cost= 0;
|
$license_cost= 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue