Add DBID back to messages, add path/seen-by to generated messages, other minor cosmetic fixes
This commit is contained in:
@@ -5,6 +5,7 @@ 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 Rennokki\QueryCache\Traits\QueryCacheable;
|
||||
@@ -67,6 +68,13 @@ final class Echomail extends Model implements Packet
|
||||
return;
|
||||
}
|
||||
|
||||
// Our address
|
||||
$ftns = Setup::findOrFail(config('app.id'))->system->match($model->fftn->zone);
|
||||
|
||||
// Add our address to the seenby;
|
||||
$model->set_seenby = array_merge($model->set_seenby,$ftns->pluck('id')->toArray());
|
||||
$model->set_path = array_merge($model->set_path,$ftns->pluck('id')->toArray());
|
||||
|
||||
// Save the seenby
|
||||
foreach ($model->set_seenby as $aoid) {
|
||||
DB::insert('INSERT INTO echomail_seenby (echomail_id,address_id,packet) VALUES (?,?,?)',[
|
||||
@@ -133,7 +141,8 @@ final class Echomail extends Model implements Packet
|
||||
|
||||
public function path()
|
||||
{
|
||||
return $this->belongsToMany(Address::class,'echomail_path');
|
||||
return $this->belongsToMany(Address::class,'echomail_path')
|
||||
->withPivot(['id','parent_id']);
|
||||
}
|
||||
|
||||
/* METHODS */
|
||||
@@ -190,11 +199,23 @@ final class Echomail extends Model implements Packet
|
||||
if ($this->origin)
|
||||
$o->origin = $this->origin;
|
||||
|
||||
// @todo SEENBY
|
||||
// @todo PATH
|
||||
$o->seenby = $this->seenby->pluck('ftn2d');
|
||||
$o->path = $this->path->pluck('ftn2d');
|
||||
|
||||
$o->packed = TRUE;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
78
app/Models/OldEchomail.php
Normal file
78
app/Models/OldEchomail.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Jenssegers\Mongodb\Eloquent\Model;
|
||||
use Jenssegers\Mongodb\Eloquent\SoftDeletes;
|
||||
|
||||
use App\Interfaces\Packet;
|
||||
|
||||
final class OldEchomail extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
private const LOGKEY = 'ME-';
|
||||
protected $table = 'echomails';
|
||||
|
||||
protected $collection = FALSE;
|
||||
|
||||
protected $casts = [ 'kludges' => 'json' ];
|
||||
|
||||
private const cast_utf8 = [
|
||||
'to',
|
||||
'from',
|
||||
'subject',
|
||||
'msg',
|
||||
'origin',
|
||||
'tearline',
|
||||
'tagline',
|
||||
];
|
||||
protected $dates = ['datetime'];
|
||||
|
||||
public static function resolveConnection($connection = null)
|
||||
{
|
||||
return static::$resolver->connection('mongodb');
|
||||
}
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function echoarea()
|
||||
{
|
||||
return $this->belongsTo(Echoarea::class);
|
||||
}
|
||||
|
||||
public function fftn()
|
||||
{
|
||||
return $this
|
||||
->setConnection('pgsql')
|
||||
->belongsTo(Address::class)
|
||||
->withTrashed();
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
public function getKludgesAttribute(?string $value): Collection
|
||||
{
|
||||
return collect($this->castAttribute('kludges',$value));
|
||||
}
|
||||
|
||||
public function getPathAttribute(?array $value): Collection
|
||||
{
|
||||
if (is_null($value))
|
||||
return collect();
|
||||
|
||||
return Address::whereIn('id',$value)
|
||||
->orderBy(DB::raw(sprintf("position (id::text in '(%s)')",join(',',$value))))
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getSeenByAttribute(?array $value): Collection
|
||||
{
|
||||
if (is_null($value))
|
||||
return collect();
|
||||
|
||||
return Address::whereIn('id',$value)->get();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user