GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

NewsletterController::actionNewslist()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace app\backend\controllers;
4
5
use app\backend\models\NewsletterConfig;
6
use app\modules\page\models\Page;
7
use app\models\SubscribeEmail;
8
use Yii;
9
use yii\filters\AccessControl;
10
use yii\web\Controller;
11
12
class NewsletterController extends Controller
13
{
14 View Code Duplication
    public function behaviors()
15
    {
16
        return [
17
            'access' => [
18
                'class' => AccessControl::className(),
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
19
                'rules' => [
20
                    [
21
                        'allow' => true,
22
                        'roles' => ['newsletter manage'],
23
                    ],
24
                ],
25
            ],
26
        ];
27
    }
28
29
    public function actionConfig()
30
    {
31
        $model = new NewsletterConfig();
32
33
        if ($model->load(Yii::$app->request->get())) {
34
            $model->saveConfig();
35
        }
36
37
        return $this->render(
38
            'config',
39
            [
40
                'model' => $model
41
            ]
42
        );
43
    }
44
45
    public function actionEmailList()
46
    {
47
        $searchModel = new SubscribeEmail();
48
        $dataProvider = $searchModel->search($_GET);
49
50
        return $this->render(
51
            'emaillist',
52
            [
53
                'dataProvider' => $dataProvider,
54
                'searchModel' => $searchModel
55
            ]
56
        );
57
    }
58
59
    public function actionUpdate($id)
60
    {
61
        $pk = SubscribeEmail::primaryKey();
62
        $pk = $pk[0];
63
        $condition = [$pk => $id];
64
65
        $model = SubscribeEmail::findOne($condition);
66
67
        if (null === $model) {
68
            Yii::$app->session->setFlash('error', Yii::t('app', 'Entries with this ID does not exist'));
69
        } else {
70
            if ($model->load(Yii::$app->request->get())) {
71
                $model->save();
72
            }
73
        }
74
75
        return $this->render(
76
            'update',
77
            [
78
                'model' => $model
79
            ]
80
        );
81
    }
82
83
    public function actionDelete($id)
84
    {
85
        $pk = SubscribeEmail::primaryKey();
86
        $pk = $pk[0];
87
        $condition = [$pk => $id];
88
89
        $model = SubscribeEmail::findOne($condition);
90
91
        if (null !== $model) {
92
            SubscribeEmail::deleteAll($condition);
93
        }
94
95
        return Yii::$app->response->redirect('email-list', 301);
96
    }
97
98
    public function actionNewslist()
99
    {
100
        $searchModel = new Page();
101
        $dataProvider = $searchModel->search($_GET);
102
103
        return $this->render(
104
            'newslist',
105
            [
106
                'dataProvider' => $dataProvider,
107
                'searchModel' => $searchModel
108
            ]
109
        );
110
    }
111
112
    public function actionSendnow($id)
113
    {
114
        $model = Page::findById($id);
115
        if (null === $model) {
116
            Yii::$app->session->setFlash('error', Yii::t('app', 'Document with this ID does not exist'));
117
            return $this->render('@app/views/notifications/newsletter/sendnow');
118
        }
119
120
        $emailsOk = [];
121
        $emailsBad = [];
122
        $activeSubscribes = (new SubscribeEmail())->getActiveSubscribes();
123
        foreach ($activeSubscribes as $sEmail) {
124
            $status = Yii::$app->mail->compose(
125
                '@app/views/notifications/newsletter/sendnow-notify.php',
126
                [
127
                    'user' => $sEmail->name,
128
                    'page' => $model
129
                ]
130
            )->setTo($sEmail->email)
131
                ->setFrom(Yii::$app->mail->transport->getUserName())
132
                ->setSubject(Yii::t('app', 'New notify'))
133
                ->send();
134
135
            if ($status) {
136
                array_push($emailsOk, $sEmail);
137
            } else {
138
                array_push($emailsBad, $sEmail);
139
            }
140
        }
141
142
        $params = [
143
            'emailsBad' => $emailsBad,
144
            'emailsOk' => $emailsOk
145
        ];
146
147
        if (count($emailsBad) > 0) {
148
            Yii::$app->session->setFlash('warning', Yii::t('app', 'There are addresses that email could not be sent'));
149
        } else {
150
            Yii::$app->session->setFlash('info', Yii::t('app', 'Subscribe completed'));
151
        }
152
153
        return $this->render('sendnow', $params);
154
    }
155
}
156