Show netmails to admins, record netmail path in the DB

This commit is contained in:
2023-06-18 23:33:26 +10:00
parent f147b33b60
commit 58341db0fb
10 changed files with 214 additions and 17 deletions

View File

@@ -5,8 +5,11 @@ namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use App\Casts\CompressedString;
use App\Classes\FTN\Message;
use App\Interfaces\Packet;
use App\Traits\{EncodeUTF8,MsgID};
@@ -17,6 +20,8 @@ final class Netmail extends Model implements Packet
use SoftDeletes,EncodeUTF8,MsgID;
private Collection $set_path;
private const cast_utf8 = [
'to',
'from',
@@ -30,6 +35,44 @@ final class Netmail extends Model implements Packet
protected $dates = ['datetime','sent_at'];
protected $casts = [
'msg' => CompressedString::class,
'msg_src' => CompressedString::class,
];
public function __set($key,$value)
{
switch ($key) {
case 'set_path':
$this->{$key} = $value;
break;
default:
parent::__set($key,$value);
}
}
public static function boot()
{
parent::boot();
static::created(function($model) {
// Save the Path
$ppoid = NULL;
foreach ($model->set_path as $path) {
$po = DB::select('INSERT INTO netmail_path (netmail_id,address_id,parent_id,datetime,program) VALUES (?,?,?,?,?) RETURNING id',[
$model->id,
$path['node']->id,
$ppoid,
(string)$path['datetime'],
$path['program'],
]);
$ppoid = $po[0]->id;
}
});
}
/* RELATIONS */
public function fftn()
@@ -39,6 +82,12 @@ final class Netmail extends Model implements Packet
->withTrashed();
}
public function path()
{
return $this->belongsToMany(Address::class,'netmail_path')
->withPivot(['id','parent_id','datetime','program']);
}
public function tftn()
{
return $this
@@ -113,4 +162,16 @@ final class Netmail extends Model implements Packet
return $o;
}
public function pathorder(string $display='ftn2d',int $start=NULL): Collection
{
$result = collect();
if ($x=$this->path->firstWhere('pivot.parent_id',$start)) {
$result->push($x->$display);
$result->push($this->pathorder($display,$x->pivot->id));
};
return $result->flatten()->filter();
}
}