This commit is contained in:
@@ -338,7 +338,7 @@ final class AccountPages
|
||||
'email' => '',
|
||||
'contact_phone' => '',
|
||||
'location_tracking_preference' => 'prompt',
|
||||
'avatar_preset' => 'modern_01',
|
||||
'avatar_preset' => 'modern_001',
|
||||
'avatar_skin_tone' => 'warm',
|
||||
'avatar_hair_style' => 'short',
|
||||
'avatar_hair_color' => 'brown',
|
||||
@@ -421,6 +421,8 @@ final class AccountPages
|
||||
$section = 'profile';
|
||||
}
|
||||
$avatarOptions = Avatar::options();
|
||||
$avatarPresetOptions = Avatar::presetOptions();
|
||||
$avatarPresetGroups = Avatar::presetGroups();
|
||||
|
||||
return compact(
|
||||
'flash',
|
||||
@@ -438,6 +440,8 @@ final class AccountPages
|
||||
'communityCanApply',
|
||||
'communityRestrictions',
|
||||
'avatarOptions',
|
||||
'avatarPresetOptions',
|
||||
'avatarPresetGroups',
|
||||
'section',
|
||||
'allowedSections'
|
||||
);
|
||||
|
||||
@@ -8,7 +8,7 @@ final class Avatar
|
||||
public static function defaults(): array
|
||||
{
|
||||
return [
|
||||
'avatar_preset' => 'modern_01',
|
||||
'avatar_preset' => 'modern_001',
|
||||
'avatar_skin_tone' => 'warm',
|
||||
'avatar_hair_style' => 'parted',
|
||||
'avatar_hair_color' => 'brown',
|
||||
@@ -98,6 +98,35 @@ final class Avatar
|
||||
];
|
||||
}
|
||||
|
||||
public static function presetGroups(): array
|
||||
{
|
||||
return [
|
||||
'fair' => ['label' => 'Helle Hauttöne', 'range' => [1, 20]],
|
||||
'warm' => ['label' => 'Warme Hauttöne', 'range' => [21, 40]],
|
||||
'golden' => ['label' => 'Goldene Hauttöne', 'range' => [41, 60]],
|
||||
'deep' => ['label' => 'Tiefere Hauttöne', 'range' => [61, 80]],
|
||||
'rich' => ['label' => 'Kräftige Hauttöne', 'range' => [81, 100]],
|
||||
];
|
||||
}
|
||||
|
||||
public static function presetOptions(): array
|
||||
{
|
||||
$presets = [];
|
||||
foreach (self::presetGroups() as $groupKey => $group) {
|
||||
[$start, $end] = $group['range'];
|
||||
for ($index = $start; $index <= $end; $index++) {
|
||||
$value = sprintf('modern_%03d', $index);
|
||||
$presets[$groupKey][$value] = [
|
||||
'label' => 'Variante ' . $index,
|
||||
'group' => $groupKey,
|
||||
'image' => self::presetPublicPath($value),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $presets;
|
||||
}
|
||||
|
||||
public static function selectColumns(string $alias = 'p'): string
|
||||
{
|
||||
$columns = array_keys(self::defaults());
|
||||
@@ -127,8 +156,22 @@ final class Avatar
|
||||
public static function render(array $row, string $name = 'Mitglied', string $size = 'md'): string
|
||||
{
|
||||
$avatar = self::normalize($row);
|
||||
$options = self::options();
|
||||
$presetPath = self::presetPublicPath($avatar['avatar_preset']);
|
||||
|
||||
if ($presetPath !== null) {
|
||||
return sprintf(
|
||||
'<span class="%s" role="img" aria-label="%s"><img class="pkt-avatar__img" src="%s" alt=""></span>',
|
||||
htmlspecialchars(implode(' ', [
|
||||
'pkt-avatar',
|
||||
'pkt-avatar--' . preg_replace('/[^a-z0-9\-]/', '', strtolower($size)),
|
||||
'pkt-avatar--preset',
|
||||
]), ENT_QUOTES),
|
||||
htmlspecialchars('Avatar von ' . $name, ENT_QUOTES),
|
||||
htmlspecialchars($presetPath, ENT_QUOTES)
|
||||
);
|
||||
}
|
||||
|
||||
$options = self::options();
|
||||
$classes = [
|
||||
'pkt-avatar',
|
||||
'pkt-avatar--' . preg_replace('/[^a-z0-9\-]/', '', strtolower($size)),
|
||||
@@ -192,4 +235,15 @@ final class Avatar
|
||||
{
|
||||
return dirname(__DIR__, 2) . '/public/assets/avatars/layers/modern/' . $category . '/' . $variant . '.svg';
|
||||
}
|
||||
|
||||
public static function presetPublicPath(string $preset): ?string
|
||||
{
|
||||
$preset = preg_replace('/[^a-z0-9_]/', '', strtolower($preset)) ?: '';
|
||||
$file = dirname(__DIR__, 2) . '/public/assets/avatars/presets/' . $preset . '.png';
|
||||
if (!is_file($file)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return '/assets/avatars/presets/' . $preset . '.png';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ final class ProfileSettings
|
||||
}
|
||||
|
||||
$avatarColumns = [
|
||||
'avatar_preset' => "ALTER TABLE user_profiles ADD COLUMN avatar_preset VARCHAR(32) NOT NULL DEFAULT 'modern_01' AFTER location_tracking_preference",
|
||||
'avatar_preset' => "ALTER TABLE user_profiles ADD COLUMN avatar_preset VARCHAR(32) NOT NULL DEFAULT 'modern_001' AFTER location_tracking_preference",
|
||||
'avatar_skin_tone' => "ALTER TABLE user_profiles ADD COLUMN avatar_skin_tone VARCHAR(24) NOT NULL DEFAULT 'warm' AFTER location_tracking_preference",
|
||||
'avatar_hair_style' => "ALTER TABLE user_profiles ADD COLUMN avatar_hair_style VARCHAR(24) NOT NULL DEFAULT 'short' AFTER avatar_skin_tone",
|
||||
'avatar_hair_color' => "ALTER TABLE user_profiles ADD COLUMN avatar_hair_color VARCHAR(24) NOT NULL DEFAULT 'brown' AFTER avatar_hair_style",
|
||||
|
||||
Reference in New Issue
Block a user