Normalise tagline/tearline/origin
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 39s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m51s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s

This commit is contained in:
2024-06-03 19:08:40 +10:00
parent 1d354da6e3
commit 8fb3a21fcd
29 changed files with 313 additions and 88 deletions

View File

@@ -11,7 +11,7 @@ use Illuminate\Support\Facades\Log;
use Illuminate\Support\MessageBag;
use App\Classes\FTN\Message;
use App\Models\{Address,Echomail};
use App\Models\{Address,Echomail,Origin,Tagline,Tearline};
trait MessageAttributes
{
@@ -28,26 +28,35 @@ trait MessageAttributes
$this->set = collect();
}
/* RELATIONS */
public function fftn()
{
return $this
->belongsTo(Address::class)
->withTrashed();
}
public function origin()
{
return $this->belongsTo(Origin::class);
}
public function tagline()
{
return $this->belongsTo(Tagline::class);
}
public function tearline()
{
return $this->belongsTo(Tearline::class);
}
/* ATTRIBUTES */
public function getContentAttribute(): string
{
if ($this->msg_src)
return $this->msg_src;
// If we have a msg_src attribute, we'll use that
$result = $this->msg."\r\r";
if ($this->tagline)
$result .= sprintf("%s\r",$this->tagline);
if ($this->tearline)
$result .= sprintf("%s\r",$this->tearline);
if ($this->origin)
$result .= sprintf("%s",$this->origin);
return rtrim($result,"\r");
return ($this->msg_src) ? $this->msg_src : $this->rebuildMessage();
}
public function getDateAttribute(): Carbon
@@ -57,38 +66,35 @@ trait MessageAttributes
public function getOriginAttribute(string $val=NULL): ?string
{
if ($this->exists && (! $val))
return $val;
if (($x=$this->getRelationValue('origin')) && $x->value)
return $x->complete($this->fftn);
// If $val is not set, then it may be an unsaved object
return sprintf(' * Origin: %s',
((! $this->exists) && $this->set->has('set_origin'))
? $this->set->get('set_origin')
: $val);
if (($this->set->has('set_origin')) || ($val))
return sprintf(' * Origin: %s',$this->set->get('set_origin',$val));
return NULL;
}
public function getTaglineAttribute(string $val=NULL): ?string
{
if ($this->exists && (! $val))
return $val;
if (($x=$this->getRelationValue('tagline')) && $x->value)
return $x->complete();
// If $val is not set, then it may be an unsaved object
return sprintf('... %s',
((! $this->exists) && $this->set->has('set_tagline'))
? $this->set->get('set_tagline')
: $val);
if (($this->set->has('set_tagline')) || ($val))
return sprintf('... %s',$this->set->get('set_tagline',$val));
return NULL;
}
public function getTearlineAttribute(string $val=NULL): ?string
{
if ($this->exists && (! $val))
return $val;
if (($x=$this->getRelationValue('tearline')) && $x->value)
return $x->complete();
// If $val is not set, then it may be an unsaved object
return sprintf('--- %s',
((! $this->exists) && $this->set->has('set_tearline'))
? $this->set->get('set_tearline')
: $val);
if (($this->set->has('set_tearline')) || ($val))
return sprintf('--- %s',$this->set->get('set_tearline',$val));
return NULL;
}
/* METHODS */
@@ -164,6 +170,23 @@ trait MessageAttributes
return Message::packMessage($this);
}
public function rebuildMessage(): string
{
// If we have a msg_src attribute, we'll use that
$result = $this->msg."\r";
if ($x=$this->tagline)
$result .= sprintf("%s\r",$x);
if ($x=$this->tearline)
$result .= sprintf("%s\r",$x);
if ($x=$this->origin)
$result .= sprintf("%s",$x);
return rtrim($result,"\r");
}
/**
* Return our path in order
*