23-01-2026
This commit is contained in:
parent
07959c0ba2
commit
854ce02bf6
166 changed files with 32909 additions and 1262 deletions
89
app/Models/DisplayFooterContent.php
Normal file
89
app/Models/DisplayFooterContent.php
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DisplayFooterContent extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'headline',
|
||||
'subline',
|
||||
'url',
|
||||
'short_code',
|
||||
'clicks',
|
||||
'sort_order',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'sort_order' => 'integer',
|
||||
'clicks' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Boot-Methode für automatische Short-Code-Generierung
|
||||
*/
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
// Short-Code nur generieren wenn URL vorhanden ist
|
||||
if ($model->url && empty($model->short_code)) {
|
||||
$model->short_code = self::generateUniqueShortCode();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Generiert einen eindeutigen Short-Code
|
||||
*/
|
||||
public static function generateUniqueShortCode(): string
|
||||
{
|
||||
do {
|
||||
// Generiere einen 6-stelligen alphanumerischen Code
|
||||
$code = strtolower(substr(str_shuffle('abcdefghijklmnopqrstuvwxyz0123456789'), 0, 6));
|
||||
} while (self::where('short_code', $code)->exists());
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die Short-URL zurück (dynamisch je nach Umgebung)
|
||||
*/
|
||||
public function getShortUrlAttribute(): string
|
||||
{
|
||||
$basePath = config('display.base_path', '_display-b2in-eu');
|
||||
$subdomain = config('display.subdomain');
|
||||
$domain = config('display.domain', 'b2in.eu');
|
||||
|
||||
// Wenn Subdomain konfiguriert ist, verwende diese (Live-Server)
|
||||
if ($subdomain) {
|
||||
// Nutze HTTPS für Produktion
|
||||
$protocol = config('app.env') === 'production' ? 'https' : 'http';
|
||||
return "{$protocol}://{$subdomain}.{$domain}/go.php?z={$this->short_code}";
|
||||
}
|
||||
|
||||
// Ansonsten verwende APP_URL + Base-Path (Testserver)
|
||||
$baseUrl = rtrim(config('app.url'), '/');
|
||||
return "{$baseUrl}/{$basePath}/go.php?z={$this->short_code}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Erhöht den Klick-Zähler
|
||||
*/
|
||||
public function incrementClicks(): void
|
||||
{
|
||||
$this->increment('clicks');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope für aktive Footer-Inhalte in sortierter Reihenfolge
|
||||
*/
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('is_active', true)->orderBy('sort_order');
|
||||
}
|
||||
}
|
||||
38
app/Models/DisplayVideo.php
Normal file
38
app/Models/DisplayVideo.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DisplayVideo extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'filename',
|
||||
'title',
|
||||
'position',
|
||||
'sort_order',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'position' => 'integer',
|
||||
'sort_order' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Scope für aktive Videos in sortierter Reihenfolge
|
||||
*/
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('is_active', true)->orderBy('sort_order');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den vollständigen Pfad zum Video zurück
|
||||
*/
|
||||
public function getFullPathAttribute(): string
|
||||
{
|
||||
return "assets/{$this->filename}";
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
class Partner extends Model
|
||||
{
|
||||
|
|
@ -13,9 +14,22 @@ class Partner extends Model
|
|||
|
||||
protected $fillable = [
|
||||
'company_name',
|
||||
'display_name',
|
||||
'slug',
|
||||
'type',
|
||||
'brand',
|
||||
'hub_id',
|
||||
'parent_partner_id',
|
||||
'salutation',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'street',
|
||||
'house_number',
|
||||
'zip',
|
||||
'city',
|
||||
'country',
|
||||
'phone',
|
||||
'website',
|
||||
'description',
|
||||
'logo_url',
|
||||
'is_active',
|
||||
|
|
@ -50,6 +64,46 @@ class Partner extends Model
|
|||
return $this->hasMany(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Für Kunden: Zugeordneter Makler/Händler (Parent-Partner)
|
||||
*/
|
||||
public function parentPartner(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Partner::class, 'parent_partner_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Für Makler/Händler: Zugeordnete Kunden (Child-Partners)
|
||||
*/
|
||||
public function childPartners(): HasMany
|
||||
{
|
||||
return $this->hasMany(Partner::class, 'parent_partner_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias für parentPartner (für bessere Lesbarkeit im Code)
|
||||
*/
|
||||
public function broker(): BelongsTo
|
||||
{
|
||||
return $this->parentPartner();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias für childPartners (für bessere Lesbarkeit im Code)
|
||||
*/
|
||||
public function customers(): HasMany
|
||||
{
|
||||
return $this->childPartners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ein Partner (Manufacturer) kann eine Marke haben
|
||||
*/
|
||||
public function brand(): HasOne
|
||||
{
|
||||
return $this->hasOne(Brand::class);
|
||||
}
|
||||
|
||||
// TODO: Später die Beziehung zu Products hinzufügen
|
||||
// public function products(): HasMany
|
||||
// {
|
||||
|
|
|
|||
87
app/Models/RegistrationCode.php
Normal file
87
app/Models/RegistrationCode.php
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class RegistrationCode extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public const STATUS_AVAILABLE = 'available';
|
||||
public const STATUS_USED = 'used';
|
||||
public const STATUS_EXPIRED = 'expired';
|
||||
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'role',
|
||||
'name',
|
||||
'status',
|
||||
'broker_partner_id',
|
||||
'partner_id',
|
||||
'assigned_to_code_id',
|
||||
'used_by_user_id',
|
||||
'used_at',
|
||||
'expires_at',
|
||||
'metadata',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'metadata' => 'array',
|
||||
'expires_at' => 'datetime',
|
||||
'used_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function broker(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Partner::class, 'broker_partner_id');
|
||||
}
|
||||
|
||||
public function partner(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Partner::class);
|
||||
}
|
||||
|
||||
public function usedBy(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'used_by_user_id');
|
||||
}
|
||||
|
||||
public function assignedToCode(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(RegistrationCode::class, 'assigned_to_code_id');
|
||||
}
|
||||
|
||||
public function scopeAvailable($query)
|
||||
{
|
||||
return $query->where('status', self::STATUS_AVAILABLE);
|
||||
}
|
||||
|
||||
public function isAvailable(): bool
|
||||
{
|
||||
if ($this->status !== self::STATUS_AVAILABLE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->expires_at && now()->greaterThan($this->expires_at)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function markUsed(?User $user = null): void
|
||||
{
|
||||
$this->status = self::STATUS_USED;
|
||||
$this->used_at = now();
|
||||
if ($user) {
|
||||
$this->used_by_user_id = $user->id;
|
||||
if ($user->partner_id && !$this->partner_id) {
|
||||
$this->partner_id = $user->partner_id;
|
||||
}
|
||||
}
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
|
|
@ -2,8 +2,11 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use App\Notifications\CustomResetPasswordNotification;
|
||||
use App\Notifications\CustomVerifyEmailNotification;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Str;
|
||||
|
|
@ -11,11 +14,12 @@ use Laravel\Fortify\TwoFactorAuthenticatable;
|
|||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
class User extends Authenticatable
|
||||
class User extends Authenticatable implements MustVerifyEmail
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasApiTokens, HasFactory, HasRoles, Notifiable, TwoFactorAuthenticatable;
|
||||
use HasApiTokens, HasFactory, HasRoles, Notifiable, TwoFactorAuthenticatable, SoftDeletes;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
|
|
@ -25,6 +29,7 @@ class User extends Authenticatable
|
|||
protected $fillable = [
|
||||
'partner_id',
|
||||
'name',
|
||||
'display_name',
|
||||
'email',
|
||||
'password',
|
||||
'email_verified_at',
|
||||
|
|
@ -49,6 +54,7 @@ class User extends Authenticatable
|
|||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'deleted_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
|
@ -57,6 +63,15 @@ class User extends Authenticatable
|
|||
{
|
||||
return $this->belongsTo(Partner::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the registration code used by this user
|
||||
*/
|
||||
public function registrationCode(): HasOne
|
||||
{
|
||||
return $this->hasOne(RegistrationCode::class, 'used_by_user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's initials
|
||||
*/
|
||||
|
|
@ -67,4 +82,56 @@ class User extends Authenticatable
|
|||
->map(fn(string $name) => Str::of($name)->substr(0, 1))
|
||||
->implode('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Anonymize user data (for users with dependencies)
|
||||
*/
|
||||
public function anonymize(): void
|
||||
{
|
||||
$this->update([
|
||||
'name' => 'Gelöschter Benutzer #' . $this->id,
|
||||
'display_name' => null,
|
||||
'email' => 'deleted_' . $this->id . '@anonymized.local',
|
||||
'password' => bcrypt(Str::random(64)),
|
||||
]);
|
||||
|
||||
// Entferne alle Rollen
|
||||
$this->syncRoles([]);
|
||||
|
||||
// Soft Delete
|
||||
$this->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user has dependencies that require anonymization instead of deletion
|
||||
*/
|
||||
public function hasDependencies(): bool
|
||||
{
|
||||
// TODO: Später erweitern mit weiteren Verknüpfungen
|
||||
// Beispiele: Orders, Projects, Documents, etc.
|
||||
|
||||
// Aktuell: Prüfe ob Partner existiert
|
||||
return $this->partner_id !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the password reset notification.
|
||||
*
|
||||
* @param string $token
|
||||
* @return void
|
||||
*/
|
||||
public function sendPasswordResetNotification($token): void
|
||||
{
|
||||
$this->notify(new CustomResetPasswordNotification($token));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the email verification notification.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function sendEmailVerificationNotification(): void
|
||||
{
|
||||
$this->notify(new CustomVerifyEmailNotification);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue