/
home
/
sditechnicalteam
/
public_html
/
app
/
Notifications
/
File Upload :
llllll
Current File: //home/sditechnicalteam/public_html/app/Notifications/NewAppreciation.php
<?php namespace App\Notifications; use App\Models\EmailNotificationSetting; use App\Models\SlackSetting; use App\Models\Task; use App\Models\Appreciation; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Notifications\Notification; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use NotificationChannels\OneSignal\OneSignalChannel; use NotificationChannels\OneSignal\OneSignalMessage; class NewAppreciation extends BaseNotification { /** * Create a new notification instance. * * @return void */ private $userAppreciation; private $emailSetting; public function __construct(Appreciation $userAppreciation) { $this->userAppreciation = $userAppreciation; $this->emailSetting = EmailNotificationSetting::where('slug', 'appreciation-notification')->first(); $this->company = $this->userAppreciation->company; } /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { $via = ['database']; if ($this->emailSetting->send_email == 'yes' && $notifiable->email_notifications && $notifiable->email != '') { array_push($via, 'mail'); } if ($this->emailSetting->send_slack == 'yes' && slack_setting()->status == 'active') { array_push($via, 'slack'); } if ($this->emailSetting->send_push == 'yes') { array_push($via, OneSignalChannel::class); } return $via; } /** * Get the mail representation of the notification. * * @param mixed $notifiable * @return \Illuminate\Notifications\Messages\MailMessage */ public function toMail($notifiable) { return parent::build() ->subject(__('email.newAppreciation.subject')) ->greeting(__('email.hello') . ' ' . mb_ucwords($notifiable->name) . ',') ->line(__('email.newAppreciation.text', ['award' => $this->userAppreciation->award->title, 'award_at' => $this->userAppreciation->award_date->format($this->company->date_format)])) ->action(__('email.newAppreciation.action'), route('appreciations.show', $this->userAppreciation->id)) ->line(__('email.thankyouNote')); } /** * Get the array representation of the notification. * * @return array */ public function toArray() { return [ 'id' => $this->userAppreciation->id, 'created_at' => $this->userAppreciation->created_at->format('Y-m-d H:i:s'), 'award_at' => $this->userAppreciation->award_date->format('Y-m-d H:i:s'), 'heading' => $this->userAppreciation->award->title, 'icon' => $this->userAppreciation->award->awardIcon->icon, 'color_code' => $this->userAppreciation->award->color_code, 'image_url' => $this->userAppreciation->addedBy->image_url ]; } /** * Get the Slack representation of the notification. * * @param mixed $notifiable * @return SlackMessage */ public function toSlack($notifiable) { $slack = SlackSetting::setting(); if (count($notifiable->employee) > 0 && (!is_null($notifiable->employee[0]->slack_username) && ($notifiable->employee[0]->slack_username != ''))) { return (new SlackMessage()) ->from(config('app.name')) ->image($slack->slack_logo_url) ->to('@' . $notifiable->employee[0]->slack_username) ->content('*' . __('email.newAppreciation.subject') . '*' . "\n" . '<' . route('appreciations.show', $this->userAppreciation->id) . '|' . ucfirst($this->userAppreciation->award->title) . '>'); } return (new SlackMessage()) ->from(config('app.name')) ->image($slack->slack_logo_url) ->content('This is a redirected notification. Add slack username for *' . mb_ucwords($notifiable->name) . '*'); } // phpcs:ignore public function toOneSignal($notifiable) { return OneSignalMessage::create() ->subject(__('email.newAppreciation.subject')) ->body($this->userAppreciation->award->title); } }
Copyright ©2k19 -
Hexid
|
Tex7ure