Completed
Push — master ( c22208...64acfb )
by Igor
04:17
created

Notify::sendMessage()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 1
Metric Value
c 4
b 1
f 1
dl 0
loc 18
rs 9.2
cc 4
eloc 10
nc 4
nop 4
1
<?php
2
3
namespace app\components;
4
5
use Yii;
6
7
/**
8
 * Component for notify user
9
 */
10
class Notify extends \yii\base\Component
11
{
12
    /**
13
     * @var object
14
     */
15
    private $params = null;
16
17
    public function init()
18
    {
19
        parent::init();
20
21
        $this->params = Yii::$app->settings;
22
    }
23
24
    /**
25
     * Send message
26
     *
27
     * @param string $to
28
     * @param string $subject
29
     * @param string $view
30
     * @param array $params
31
     * @return bool
32
     */
33
    public function sendMessage($to, $subject, $view, $params = [])
34
    {
35
        $message = \Yii::$app->getMailer()->compose($view, $params);
36
37
        if (strlen($this->params->emailMain) && strlen($this->params->emailName)) {
38
            $message->setFrom([$this->params->emailMain => $this->params->emailName]);
39
        }
40
41
        $message->setTo($to);
42
43
        if (strlen($this->params->emailPrefix)) {
44
            $message->setSubject($this->params->emailPrefix . ': ' . $subject);
45
        } else {
46
            $message->setSubject($subject);
47
        }
48
49
        return $message->send();
50
    }
51
}
52