Added areafix command %LIST
This commit is contained in:
104
app/Notifications/Netmails/Areafix/AreaList.php
Normal file
104
app/Notifications/Netmails/Areafix/AreaList.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user