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.
132 lines
3.1 KiB
132 lines
3.1 KiB
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class AudienceRegistration extends Model
|
|
{
|
|
public const STATUS_PENDING = 'pending';
|
|
|
|
public const STATUS_APPROVED = 'approved';
|
|
|
|
public const PURPOSES = [
|
|
'networking',
|
|
'collaboration',
|
|
'investment',
|
|
'study',
|
|
'media',
|
|
'other',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'competition_id',
|
|
'audience_session_id',
|
|
'user_id',
|
|
'name',
|
|
'phone',
|
|
'company',
|
|
'job',
|
|
'purpose',
|
|
'answers_json',
|
|
'ticket_code',
|
|
'review_status',
|
|
'approved_event_time_text',
|
|
'approved_event_address_text',
|
|
'reviewed_at',
|
|
'reviewed_by_admin_id',
|
|
'reviewed_by_competition_admin_id',
|
|
'registered_at',
|
|
'checked_in_at',
|
|
'checked_in_by_admin_id',
|
|
'checked_in_by_competition_admin_id',
|
|
];
|
|
|
|
/**
|
|
* @var array<string, string>
|
|
*/
|
|
protected $casts = [
|
|
'registered_at' => 'datetime',
|
|
'reviewed_at' => 'datetime',
|
|
'checked_in_at' => 'datetime',
|
|
'answers_json' => 'array',
|
|
];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $row) {
|
|
if (! filled($row->ticket_code)) {
|
|
$row->ticket_code = self::newTicketCode();
|
|
}
|
|
});
|
|
}
|
|
|
|
public static function newTicketCode(): string
|
|
{
|
|
do {
|
|
$code = bin2hex(random_bytes(8));
|
|
} while (self::query()->where('ticket_code', $code)->exists());
|
|
|
|
return $code;
|
|
}
|
|
|
|
public function competition(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Competition::class);
|
|
}
|
|
|
|
public function session(): BelongsTo
|
|
{
|
|
return $this->belongsTo(AudienceSession::class, 'audience_session_id');
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function checkedInBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(AdminUser::class, 'checked_in_by_admin_id');
|
|
}
|
|
|
|
public function checkedInByCompetitionAdmin(): BelongsTo
|
|
{
|
|
return $this->belongsTo(CompetitionAdmin::class, 'checked_in_by_competition_admin_id');
|
|
}
|
|
|
|
public function reviewedBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(AdminUser::class, 'reviewed_by_admin_id');
|
|
}
|
|
|
|
public function reviewedByCompetitionAdmin(): BelongsTo
|
|
{
|
|
return $this->belongsTo(CompetitionAdmin::class, 'reviewed_by_competition_admin_id');
|
|
}
|
|
|
|
public function isCheckedIn(): bool
|
|
{
|
|
return $this->checked_in_at !== null;
|
|
}
|
|
|
|
public function isApproved(): bool
|
|
{
|
|
return $this->review_status === self::STATUS_APPROVED;
|
|
}
|
|
|
|
public function isPending(): bool
|
|
{
|
|
return $this->review_status === self::STATUS_PENDING;
|
|
}
|
|
|
|
public static function existsForUserCompetition(int $userId, int $competitionId): bool
|
|
{
|
|
return static::query()
|
|
->where('user_id', $userId)
|
|
->where('competition_id', $competitionId)
|
|
->exists();
|
|
}
|
|
}
|