PHP code example of denisbespyatov / notifications
1. Go to this page and download the library: Download denisbespyatov/notifications library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
/**
* Get the notification's delivery channels.
* @return boolean
*/
public function shouldSend($channel)
{
if($channel->id == 'screen'){
if(!in_array($this->key, [self::KEY_NEW_ACCOUNT])){
return false;
}
}
return true;
}
/**
* Override send to email channel
*
* @param $channel the email channel
* @return void
*/
public function toEmail($channel){
switch($this->key){
case self::KEY_NEW_ACCOUNT:
$subject = 'Welcome to MySite';
$template = 'newAccount';
break;
case self::KEY_RESET_PASSWORD:
$subject = 'Password reset for MySite';
$template = 'resetPassword';
break;
}
$message = $channel->mailer->compose($template, [
'user' => $this->user,
'notification' => $this,
]);
Yii::configure($message, $channel->message);
$message->setTo($this->user->email);
$message->setSubject($subject);
$message->send($channel->mailer);
}
namespace app\channels;
use denisbespyatov\notifications\Channel;
use denisbespyatov\notifications\Notification;
class VoiceChannel extends Channel
{
/**
* Send the given notification.
*
* @param Notification $notification
* @return void
*/
public function send(Notification $notification)
{
// use $notification->getTitle() ou $notification->getDescription();
// Send your notification in this channel...
}
}