Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Malebestia committed Sep 4, 2023
1 parent 9f3a48b commit 7713866
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?php
<<<<<<< HEAD

<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
// https://blog.quickadminpanel.com/laravel-notifications-with-database-driver-internal-messages/
=======
>>>>>>> 602db11 (up)
=======
//https://blog.quickadminpanel.com/laravel-notifications-with-database-driver-internal-messages/
>>>>>>> 0cbdb01 (up)
declare(strict_types=1);

use Illuminate\Database\Schema\Blueprint;
Expand Down
29 changes: 29 additions & 0 deletions Datas/NotificationData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@

namespace Modules\Notify\Datas;

<<<<<<< HEAD
use Illuminate\Notifications\Notification;
use Modules\Notify\Models\Notification as NotificationModel;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\DataCollection;

class NotificationData extends Data
{
=======
use Spatie\LaravelData\Data;

class NotificationData extends Data {
>>>>>>> 0cbdb01 (up)
// public string $mobile_phone;
// public string $token;
// public int $q;
public string $from;
<<<<<<< HEAD
public ?string $from_email = null;
public string $to;
public ?string $subject = null;
Expand Down Expand Up @@ -52,4 +59,26 @@ public function getSmsData(): SmsData
'body' => $this->body,
]);
}
=======
public ?string $from_email=null;
public string $to;
public ?string $subject=null;
public ?string $body_html=null;
public string $body;




/** Get the notification routing information for the given driver.
*
* @param string $driver
*
* @return mixed
*/
public function routeNotificationFor($driver) {
dddx($driver);
//return $this->routes[$driver] ?? null;
}

>>>>>>> 0cbdb01 (up)
}
42 changes: 42 additions & 0 deletions Models/Panels/Actions/TrySendNotificationAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* --.
*/
declare(strict_types=1);

namespace Modules\Notify\Models\Panels\Actions;

// -------- services --------

use Exception;
use ErrorException;
use Illuminate\Support\Facades\Mail;
use Modules\UI\Services\ThemeService;
use Modules\Notify\Emails\BeautyEmail;
use Modules\Notify\Notifications\Notify;
use Illuminate\Support\Facades\Notification;
use Modules\Notify\Notifications\HtmlNotification;
use Modules\Notify\Notifications\TestNotification;
use Modules\Cms\Models\Panels\Actions\XotBasePanelAction;

// -------- bases -----------

/**
* Class TrySendNotificationAction.
*/
class TrySendNotificationAction extends XotBasePanelAction {
public bool $onItem = true;
public string $icon = '<i class="fas fa-vial"></i>TrySendNotification';

/**
* @return mixed
*/
public function handle() {

Notification::route('mail', [
'[email protected]' => 'Davide Cavallini',
])->notify(new HtmlNotification('[email protected]','Soggetto a caso','<h1>Ciao</h1>'));

return 'done';
}
}
21 changes: 21 additions & 0 deletions Models/Panels/Actions/TrySmsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
use Modules\Cms\Models\Panels\Actions\XotBasePanelAction;
use Modules\Notify\Services\SmsService;
use Modules\UI\Services\ThemeService;
use Illuminate\Broadcasting\Channel;
use Illuminate\Support\Facades\Notification;

use Modules\Notify\Notifications\ThemeNotification;
use Modules\Notify\Notifications\SampleNotification;
use Modules\Notify\Datas\NotificationData;;

// -------- bases -----------
<<<<<<< HEAD
Expand Down Expand Up @@ -79,6 +85,7 @@ public function handle()

public function postHandle() {
$data = request()->all();
<<<<<<< HEAD
$vars = collect($data)->only(['driver', 'from', 'to', 'body'])->all();
SmsService::make()->setLocalVars($vars)->send();
<<<<<<< HEAD
Expand All @@ -95,5 +102,19 @@ public function postHandle(){
>>>>>>> 42aa20e (.)
=======
>>>>>>> 9f492fe (up)
=======

//$hows=NotificationData::collection([$data]);
$hows=NotificationData::from($data);

//$vars = collect($data)->only(['driver', 'from', 'to', 'body'])->all();
//SmsService::make()->setLocalVars($vars)->send();
//Notification::route($data['driver'], $data['to'])
//Notification::route($data['driver'], $data['to'])
// ->notify(new SampleNotification($data));
Notification::send([$hows], new SampleNotification($data));
//Call to a member function routeNotificationFor() on string
dddx('fine');
>>>>>>> 0cbdb01 (up)
}
}
7 changes: 7 additions & 0 deletions Models/Panels/Policies/_ModulePanelPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,11 @@ public function testMail(UserContract $user,PanelContract $panel):bool{
public function TryAlert(UserContract $user, PanelContract $panel): bool {
return true;
}

/**
* --.
*/
public function trySendNotification(UserContract $user, PanelContract $panel): bool {
return true;
}
}
4 changes: 4 additions & 0 deletions Models/Panels/_ModulePanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function actions(): array {
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 42aa20e (.)
=======
Expand All @@ -30,6 +31,9 @@ public function actions(): array {
//new Actions\TryAlertAction(),
>>>>>>> a5593ab (.)
=======
=======
new Actions\TrySendNotificationAction(),
>>>>>>> 0cbdb01 (up)
// new Actions\TryAlertAction(),
>>>>>>> df8079b (up)
];
Expand Down
6 changes: 4 additions & 2 deletions Notifications/Channels/EsendexChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

namespace Modules\Notify\Notifications\Channels;

use Illuminate\Support\Facades\Notification;
//use Illuminate\Support\Facades\Notification;
use Modules\Notify\Actions\EsendexSendAction;
use Modules\Notify\Notifications\SmsNotification;
use Illuminate\Notifications\Notification;
use Modules\Xot\Contracts\ModelContactContract;

class EsendexChannel {
public function __construct() {
}

public function send($notifiable, SmsNotification $notification) {
//public function send($notifiable, SmsNotification $notification) {
public function send(object $notifiable, Notification $notification): void {
// Send notification to the $notifiable instance...
$message = $notification->toSms($notifiable);
// Send notification to the $notifiable instance...
Expand Down
3 changes: 2 additions & 1 deletion Notifications/HtmlNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function __construct(string $from, string $subject, string $html) {
* @return array
*/
public function via($notifiable) {

return ['mail'];
}

Expand Down Expand Up @@ -76,7 +77,7 @@ public function toSms($notifiable) {
* @return array
*/
public function toArray($notifiable) {
dddx($notifiable);


return [
];
Expand Down
95 changes: 95 additions & 0 deletions Notifications/SampleNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

namespace Modules\Notify\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Modules\Notify\Data\SmsData;

use Modules\Notify\Notifications\Channels\EsendexChannel;

class SampleNotification extends Notification
{
use Queueable;

/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(array $data)
{
//
$this->data=$data;
}

/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable):array
{
$channels = [];
$channels[]=EsendexChannel::class;
//$channels[]='esendex'; //Driver [esendex] not supported.
//$channels[]='database';
return $channels;
}

/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toEssendex($notifiable){
dddx($notifiable);
}


public function toSms($notifiable){

$res= SmsData::from([
'from' => $this->data['from'],
//'to' => $notifiable->routeNotificationFor('sms'),
'to' => $this->data['to'],
'body' => $this->data['body'],
]);
dddx($res);
return $res;
}


/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
dddx('oo');
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', 'https://laravel.com')
->line('Thank you for using our application!');
}

/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
dddx('oo');
return [
//
];
}
}
Loading

0 comments on commit 7713866

Please sign in to comment.