Completed
Push — master ( 8e4a64...521cc3 )
by Paweł
04:47
created

ProfileButton::getLabel()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
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\Account;
12
use app\models\Favorite;
13
use app\modules\admin\widgets\AjaxButton;
14
use yii\base\Widget;
15
use yii\helpers\Html;
16
use yii\helpers\Url;
17
18
class ProfileButton extends Widget
19
{
20
    public $model;
21
22
    public $addLabel = '<span class="fa fa-star text-yellow"></span> Add to favorites';
23
    public $removeLabel = '<span class="fa fa-star-o text-yellow"></span> Remove from favorites';
24
25
    public function run()
26
    {
27
        $url = Url::to(['/admin/account/dashboard', 'id' => $this->model->id]);
28
29
        $model = Favorite::findOne([
30
            'user_id' => \Yii::$app->user->id,
31
            'url' => $url,
32
        ]);
33
34
        return AjaxButton::widget([
35
            'confirm' => isset($model),
36
            'text' => $model ? $this->removeLabel : $this->addLabel,
37
            'url' => $model ? ['favorite/delete', 'id' => $model->id] : ['favorite/create'],
38
            'data' => [
39
                'url' => $url,
40
                'label' => $this->model->usernamePrefixed,
41
            ],
42
            'options' => [
43
                'class' => 'btn btn-block btn-default btn-sm',
44
                'data' => [
45
                    'style' => 'zoom-out',
46
                ],
47
            ],
48
        ]);
49
    }
50
}