mein-sterntours/app/Models/NewsletterLog.php
2026-01-23 17:34:40 +01:00

86 lines
2.1 KiB
PHP

<?php
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
/**
* Class NewsletterLog
*
* @property int $id
* @property int $newsletter_contact_id
* @property string $action
* @property string|null $description
* @property array|null $metadata
* @property int|null $user_id
* @property Carbon $created_at
* @property Carbon $updated_at
* @property-read NewsletterContact $newsletter_contact
* @property-read SfGuardUser|null $user
* @package App\Models
*/
class NewsletterLog extends Model
{
protected $connection = 'mysql';
protected $table = 'newsletter_logs';
protected $casts = [
'newsletter_contact_id' => 'int',
'user_id' => 'int',
'metadata' => 'array',
];
protected $fillable = [
'newsletter_contact_id',
'action',
'description',
'metadata',
'user_id',
];
// Aktions-Konstanten
const ACTION_SUBSCRIBED = 'subscribed';
const ACTION_UNSUBSCRIBED = 'unsubscribed';
const ACTION_BOOKING_ADDED = 'booking_added';
const ACTION_STATUS_CHANGED = 'status_changed';
const ACTION_GROUP_CHANGED = 'group_changed';
const ACTION_EMAIL_SENT = 'email_sent';
const ACTION_BOUNCED = 'bounced';
public static $actionLabels = [
self::ACTION_SUBSCRIBED => 'Angemeldet',
self::ACTION_UNSUBSCRIBED => 'Abgemeldet',
self::ACTION_BOOKING_ADDED => 'Buchung hinzugefügt',
self::ACTION_STATUS_CHANGED => 'Status geändert',
self::ACTION_GROUP_CHANGED => 'Gruppe geändert',
self::ACTION_EMAIL_SENT => 'E-Mail versendet',
self::ACTION_BOUNCED => 'Bounced',
];
/**
* Beziehung zum Newsletter-Kontakt
*/
public function newsletter_contact()
{
return $this->belongsTo(NewsletterContact::class, 'newsletter_contact_id');
}
/**
* Beziehung zum Admin-User
*/
public function user()
{
return $this->belongsTo(SfGuardUser::class, 'user_id');
}
/**
* Action-Label
*/
public function getActionLabelAttribute()
{
return self::$actionLabels[$this->action] ?? $this->action;
}
}