forked from ricco381/yii2-ticket
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Mailer.php
executable file
·84 lines (72 loc) · 2.37 KB
/
Mailer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace ricco\ticket;
use yii\helpers\Url;
class Mailer extends \yii\swiftmailer\Mailer
{
public $viewPath = '@ricco/ticket/views/ticket/mail';
private $nameTicket; /** @var string Название тикета */
private $textTicket; /** @var string Тест сообщения */
private $status; /** @var integer Статус тикета */
private $subject; /** @var string Тема email сообщения */
private $urlTicket; /** @var string url тикета на который был дан ответ */
private $setTo; /** @var string email юзера которому будет отправлено сообщение */
/** @var \yii\swiftmailer\Mailer $mail */
protected $mail;
public function init()
{
$this->mail = \Yii::$app->mailer;
$this->mail->viewPath = $this->viewPath;
$this->mail->getView()->theme = \Yii::$app->view->theme;
parent::init();
}
/**
* @param $nameTicket
* @param $textTicket
* @param $status integer Статус
* @param $id int
* @return $this
*/
public function sendMailDataTicket($nameTicket, $status, $id, $textTicket = '')
{
$this->nameTicket = $nameTicket;
$this->textTicket = $textTicket;
$this->status = $status;
$this->urlTicket = $this->getLinkTicket($id);
return $this;
}
/**
* @param $userEmail
* @param $subject
* @return $this
*/
public function setDataFrom($userEmail, $subject)
{
$this->setTo = $userEmail;
$this->subject = $subject;
return $this;
}
/**
* @param $view string Вит отображения email сообщения
*/
public function senda($view)
{
$this->mail->compose($view, [
'nameTicket' => $this->nameTicket,
'textTicket' => $this->textTicket,
'status' => $this->status,
'link' => $this->urlTicket,
])
->setFrom(\Yii::$app->params['adminEmail'])
->setTo($this->setTo)
->setSubject($this->subject)
->send();
}
/**
* @param $id int Id Тикета
* @return string Возвращает ссылку на тикет
*/
private function getLinkTicket($id)
{
return Url::to(['/ticket/ticket/view'], true) . "?id=" . $id;
}
}