46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace common\components\user\handlers;
|
|
|
|
use Yii;
|
|
use yii\base\Event;
|
|
use common\helpers\MailHelper;
|
|
use common\components\user\models\User;
|
|
|
|
class UserStatusChangeEventHandler
|
|
{
|
|
static public function run(Event $event)
|
|
{
|
|
/** @var User $user */
|
|
$user = $event->sender;
|
|
|
|
if (!$user || !$user->email) {
|
|
return;
|
|
}
|
|
|
|
self::sendTelegram($user);
|
|
// self::sendEmail($user->email);
|
|
}
|
|
|
|
static private function sendTelegram(User $user): bool
|
|
{
|
|
return Yii::$app->telegram->sendMessage(Yii::$app->params['telega']['accountExpirationChatId'], Yii::t('user', 'Статус изменён: {email}', [
|
|
'email' => $user->email,
|
|
]));
|
|
}
|
|
|
|
static private function sendEmail($email): bool
|
|
{
|
|
return MailHelper::sendMail(
|
|
$email,
|
|
null,
|
|
Yii::t('app', 'Статус изменён'),
|
|
[
|
|
'title' => Yii::t('app', 'Статус изменён'),
|
|
'body' => Yii::t('user', 'Ваш статус изменился, {link}', [
|
|
'link' => Yii::$app->params['webUrl'],
|
|
]),
|
|
]);
|
|
}
|
|
}
|