mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
37 lines
837 B
PHP
37 lines
837 B
PHP
<?php
|
|
namespace api\modules\accounts\models;
|
|
|
|
use api\aop\annotations\CollectModelMetrics;
|
|
use api\exceptions\ThisShouldNotHappenException;
|
|
use common\validators\LanguageValidator;
|
|
|
|
class ChangeLanguageForm extends AccountActionForm {
|
|
|
|
public $lang;
|
|
|
|
public function rules(): array {
|
|
return [
|
|
['lang', 'required'],
|
|
['lang', LanguageValidator::class],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @CollectModelMetrics(prefix="accounts.switchLanguage")
|
|
*/
|
|
public function performAction(): bool {
|
|
if (!$this->validate()) {
|
|
return false;
|
|
}
|
|
|
|
$account = $this->getAccount();
|
|
$account->lang = $this->lang;
|
|
if (!$account->save()) {
|
|
throw new ThisShouldNotHappenException('Cannot change user language');
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|