ProfileButton   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 21 3
1
<?php
2
/**
3
 * Created for IG Monitoring.
4
 * User: jakim <[email protected]>
5
 * Date: 02.02.2018
6
 */
7
8
namespace app\modules\admin\widgets\favorites;
9
10
11
use app\models\Favorite;
12
use app\modules\admin\widgets\AjaxButton;
13
use Yii;
14
use yii\base\Widget;
15
use yii\helpers\Url;
16
17
class ProfileButton extends Widget
18
{
19
    public $model;
20
21
    public $addLabel = '<span class="fa fa-star text-yellow"></span> Add to favorites';
22
    public $removeLabel = '<span class="fa fa-star-o text-yellow"></span> Remove from favorites';
23
24
    public function run()
25
    {
26
        $url = Url::to(['/admin/account/dashboard', 'id' => $this->model->id]);
27
28
        $model = Favorite::findOne([
29
            'user_id' => Yii::$app->user->id,
30
            'url' => $url,
31
        ]);
32
33
        return AjaxButton::widget([
34
            'confirm' => isset($model),
35
            'text' => $model ? $this->removeLabel : $this->addLabel,
0 ignored issues
show
introduced by
$model is of type yii\db\ActiveRecord, thus it always evaluated to true.
Loading history...
36
            'url' => $model ? ['favorite/delete', 'id' => $model->id] : ['favorite/create'],
0 ignored issues
show
introduced by
$model is of type yii\db\ActiveRecord, thus it always evaluated to true.
Loading history...
37
            'data' => [
38
                'url' => $url,
39
                'label' => $this->model->usernamePrefixed,
40
            ],
41
            'options' => [
42
                'class' => 'btn btn-block btn-default btn-sm',
43
                'data' => [
44
                    'style' => 'zoom-out',
45
                ],
46
            ],
47
        ]);
48
    }
49
}