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.
51 lines
1.9 KiB
51 lines
1.9 KiB
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
|
|
class CameraDevice extends \Illuminate\Database\Eloquent\Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'venue_id','venue_name','name','ip','sdk_port','http_port','channel','device_slot','group_id','username',
|
|
'password_encrypted','monitor_enabled','notification_enabled','include_in_venue_stats','maintenance_until',
|
|
'push_timeout_seconds','remark',
|
|
];
|
|
|
|
protected $hidden = ['password_encrypted'];
|
|
|
|
protected $casts = [
|
|
'monitor_enabled' => 'boolean', 'notification_enabled' => 'boolean',
|
|
'include_in_venue_stats' => 'boolean', 'maintenance_until' => 'datetime',
|
|
'sdk_port' => 'integer', 'http_port' => 'integer', 'channel' => 'integer',
|
|
'device_slot' => 'integer', 'push_timeout_seconds' => 'integer',
|
|
];
|
|
|
|
public function venue(): BelongsTo { return $this->belongsTo(Venue::class); }
|
|
public function health(): HasOne { return $this->hasOne(CameraHealthState::class); }
|
|
public function alerts(): HasMany { return $this->hasMany(CameraAlert::class); }
|
|
|
|
public function setPlainPassword(?string $password): void
|
|
{
|
|
$this->password_encrypted = $password === null || $password === '' ? null : Crypt::encryptString($password);
|
|
}
|
|
|
|
public function plainPassword(): string
|
|
{
|
|
if (! $this->password_encrypted) return '';
|
|
try { return Crypt::decryptString($this->password_encrypted); } catch (\Throwable) { return ''; }
|
|
}
|
|
|
|
public function isInMaintenance(): bool
|
|
{
|
|
return $this->maintenance_until !== null && $this->maintenance_until->isFuture();
|
|
}
|
|
}
|