File: /home/imensosw/www/mpl.imenso.co/app/Listeners/SendParticipantsEventCancelledNotification.php
<?php
namespace App\Listeners;
use App\Events\EventCancelled;
use App\Models\Notification;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\Facades\View;
class SendParticipantsEventCancelledNotification
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param EventCancelled $event
* @return void
*/
public function handle(EventCancelled $event)
{
if (isset($event->event->promoter) && Auth::user() != $event->event->promoter) {
$html = view('notifications/user/participating-event-cancelled')->with([
'event' => $event->event,
])->render();
$notification = $event->event->promoter->addNotification(
405,
$html,
[
'event_id' => $event->event->id,
]
);
if ($notification) {
$parsed_html = '<a href="javascript: void(0)" onclick="clearNotification('.$notification->id.')" class="clear-btn"><i class="fa fa-close"></i></a>';
$parsed_html .= Notification::parseNotification(
view('notifications/user/participating-event-cancelled')->with([
'event' => $event->event,
])->render()
);
$parsed_html .= '<div class="time-ago">'.$notification->created_at->diffForHumans().'</div>';
if ($notification->getActions()) {
$parsed_html .= '<div class="action-row">'.$notification->getActions().'</div>';
}
$data = [
'action' => 'add-notification',
'html' => $parsed_html,
'id' => $notification->id,
];
Broadcast::broadcast(
[
'private-user_'.$event->event->promoter->id,
],
'notification',
$data
);
}
}
foreach ($event->event->artists() as $user) {
if ($user != Auth::user()) {
$html = view('notifications/user/participating-event-cancelled')->with([
'event' => $event->event,
])->render();
$notification = $user->addNotification(
405,
$html,
[
'event_id' => $event->event->id,
]
);
if ($notification) {
$parsed_html = '<a href="javascript: void(0)" onclick="clearNotification('.$notification->id.')" class="clear-btn"><i class="fa fa-close"></i></a>';
$parsed_html .= Notification::parseNotification(
view('notifications/user/participating-event-cancelled')->with([
'event' => $event->event,
])->render()
);
$parsed_html .= '<div class="time-ago">'.$notification->created_at->diffForHumans().'</div>';
if ($notification->getActions()) {
$parsed_html .= '<div class="action-row">'.$notification->getActions().'</div>';
}
$data = [
'action' => 'add-notification',
'html' => $parsed_html,
];
Broadcast::broadcast(
[
'private-user_'.$user->id,
],
'notification',
$data
);
}
}
}
}
}