user profile
This commit is contained in:
@@ -21,6 +21,8 @@ class TwigGlobalsExtension extends AbstractExtension
|
||||
new TwigFunction('get_current_route', [$this, 'getCurrentRoute'], ['is_safe' => ['html']]),
|
||||
new TwigFunction('render_actions', [$this, 'renderActions'], ['is_safe' => ['html']]),
|
||||
new TwigFunction('render_cell', [$this, 'renderCell'], ['is_safe' => ['html']]),
|
||||
new TwigFunction('get_avatar_url', [$this, 'getAvatarUrl'], ['is_safe' => ['html']]),
|
||||
new TwigFunction('get_avatar', [$this, 'getAvatar'], ['is_safe' => ['html']]),
|
||||
|
||||
// Access functions
|
||||
new TwigFunction('can', [$this, 'can'], ['is_safe' => ['html']]),
|
||||
@@ -155,6 +157,44 @@ class TwigGlobalsExtension extends AbstractExtension
|
||||
return '<span class="badge ' . esc($color) . '">' . esc($label) . '</span>';
|
||||
}
|
||||
|
||||
public function getAvatarUrl($avatar = null, $size = 32): string
|
||||
{
|
||||
if (empty($avatar)) {
|
||||
return '';
|
||||
}
|
||||
return base_url('/uploads/avatars/' . $avatar);
|
||||
}
|
||||
|
||||
public function getAvatar($user = null, $size = 32, $class = ''): string
|
||||
{
|
||||
if (!$user) {
|
||||
$session = session();
|
||||
$userId = $session->get('user_id');
|
||||
if (!$userId) {
|
||||
return '';
|
||||
}
|
||||
$userModel = new \App\Models\UserModel();
|
||||
$user = $userModel->find($userId);
|
||||
}
|
||||
|
||||
$name = $user['name'] ?? 'U';
|
||||
$avatar = $user['avatar'] ?? null;
|
||||
|
||||
if ($avatar) {
|
||||
$url = base_url('/uploads/avatars/' . $avatar);
|
||||
$style = "width: {$size}px; height: {$size}px; object-fit: cover; border-radius: 50%;";
|
||||
return '<img src="' . esc($url) . '" alt="' . esc($name) . '" class="' . esc($class) . '" style="' . esc($style) . '">';
|
||||
}
|
||||
|
||||
// Генерируем фон на основе имени
|
||||
$colors = ['667eea', '764ba2', 'f093fb', 'f5576c', '4facfe', '00f2fe'];
|
||||
$color = $colors[crc32($name) % count($colors)];
|
||||
$initial = strtoupper(substr($name, 0, 1));
|
||||
$style = "width: {$size}px; height: {$size}px; background: linear-gradient(135deg, #{$color} 0%, #{$color}dd 100%); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; font-size: " . ($size / 2) . "px;";
|
||||
|
||||
return '<div class="' . esc($class) . '" style="' . esc($style) . '">' . esc($initial) . '</div>';
|
||||
}
|
||||
|
||||
public function getAllRoles(): array
|
||||
{
|
||||
return \App\Services\AccessService::getAllRoles();
|
||||
@@ -165,6 +205,7 @@ class TwigGlobalsExtension extends AbstractExtension
|
||||
return session();
|
||||
}
|
||||
|
||||
|
||||
public function getCurrentOrg()
|
||||
{
|
||||
$session = session();
|
||||
@@ -412,6 +453,9 @@ class TwigGlobalsExtension extends AbstractExtension
|
||||
$name = $itemArray['user_name'] ?? '';
|
||||
$email = $itemArray['user_email'] ?? $value;
|
||||
$avatar = $itemArray['user_avatar'] ?? '';
|
||||
if (!empty($avatar)) {
|
||||
$avatar = '/uploads/avatars/' . $itemArray['user_avatar'];
|
||||
}
|
||||
$avatarHtml = $avatar
|
||||
? '<img src="' . esc($avatar) . '" alt="" style="width: 32px; height: 32px; object-fit: cover; border-radius: 50%;">'
|
||||
: '<div class="bg-light rounded-circle d-flex align-items-center justify-content-center" style="width: 32px; height: 32px;"><i class="fa-solid fa-user text-muted small"></i></div>';
|
||||
|
||||
Reference in New Issue
Block a user