clrghouz/app/Notifications/Netmails/Areafix/AreaList.php
Deon George f6134c0a98
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 32s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m35s
Create Docker Image / Final Docker Image Manifest (push) Successful in 8s
Added areafix command %LIST
2024-11-02 00:10:38 +11:00

104 lines
2.6 KiB
PHP

<?php
namespace App\Notifications\Netmails\Areafix;
use Illuminate\Support\Facades\Log;
use App\Notifications\Netmails;
use App\Models\Netmail;
use App\Traits\{MessagePath,PageTemplate};
class AreaList extends Netmails
{
use MessagePath,PageTemplate;
private const LOGKEY = 'ACH';
private Netmail $mo;
/**
* Reply to a areafix, commands unknown.
*
* @param Netmail $mo
*/
public function __construct(Netmail $mo)
{
parent::__construct();
$this->mo = $mo->withoutRelations();
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return Netmail
* @throws \Exception
*/
public function toNetmail(object $notifiable): Netmail
{
$o = $this->setupNetmail($notifiable);
$ao = $notifiable->routeNotificationFor(static::via);
Log::info(sprintf('%s:+ Responding to areafix for a node [%s] LIST processed',self::LOGKEY,$ao->ftn));
$o->to = $this->mo->from;
$o->replyid = $this->mo->msgid;
$o->subject = 'Areafix - List';
// Message
$msg = $this->page(FALSE,'Areafix');
$msg->addText("Here are the list of available echoareas:\r\r\r\r");
$areas = $ao->domain
->echoareas
->filter(fn($item)=>$item->active && ($item->can_read($ao->security) || $item->can_write($ao->security)));
if ($areas->count()) {
$msg->addText(sprintf(":---:-%s-:-%s-:-%s-:\r",
str_repeat('-',10),
str_repeat('-',48),
str_repeat('-',4),
));
$msg->addText(sprintf(": : %-10s : %-48s : %-4s :\r",'AREA','DESCRIPTION','MSGS'));
$msg->addText(sprintf(":---:-%s-:-%s-:-%s-:\r",
str_repeat('-',10),
str_repeat('-',48),
str_repeat('-',4),
));
foreach ($areas as $eao) {
$msg->addText(sprintf(":%s%s%s: %-10s : %-48s : %4d :\r",
($x=$ao->echoareas->contains($eao)) ? '*' : ' ',
(! $x ? '+' : ' '),
($eao->can_read($ao->security) && (! $eao->can_write($ao->security)))
? 'R'
: (((! $eao->can_read($ao->security)) && $eao->can_write($ao->security)) ? 'W' : ' '),
$eao->name,
$eao->description,
$eao->messages_count(30),
));
}
$msg->addText(sprintf(":---:-%s-:-%s-:-%s-:\r",
str_repeat('-',10),
str_repeat('-',48),
str_repeat('-',4),
));
$msg->addText("\r'*' = Subscribed, '+' = available, 'R' = read only, 'W' = write only\r");
$msg->addText('(MSGS = Messages in the last month)');
} else {
$msg->addText(sprintf('No areas available to you from domain [%s]',$ao->domain->name));
}
$o->msg = $msg->render();
$o->set_tagline = 'Why did the robot cross the road? The chicken programmed it.';
$o->save();
return $o;
}
}