You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

63 lines
1.6 KiB

<?php
namespace core\helpers;
use core\entities\user\User;
use core\repositories\user\UserRepository;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Json;
use Yii;
class UserHelper
{
public static function statusList(): array
{
return [
User::STATUS_WAIT => Yii::t('user', 'Wait'),
User::STATUS_ACTIVE => Yii::t('user', 'Active'),
];
}
public static function statusName($status): string
{
return ArrayHelper::getValue(self::statusList(), $status);
}
public static function statusLabel($status): string
{
switch ($status) {
case User::STATUS_WAIT:
$class = 'label label-default';
break;
case User::STATUS_ACTIVE:
$class = 'label label-success';
break;
default:
$class = 'label label-default';
}
return Html::tag('span', ArrayHelper::getValue(self::statusList(), $status), [
'class' => $class,
]);
}
public static function getSetting($key, $default = null)
{
$settings = Json::decode(\Yii::$app->user->identity->user->settings, true);
return isset($settings[$key]) ? $settings[$key] : $default;
}
public static function setSetting($key, $value)
{
$settings = Json::decode(\Yii::$app->user->identity->user->settings, true);
$settings[$key] = $value;
$user = User::findOne(\Yii::$app->user->id);
if ($user) {
$user->settings = Json::encode($settings);
$user->save();
}
}
}