Completed
Push — master ( 5abd28...83c676 )
by Klochok
22:57
created

ReminderButton::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
1
<?php
2
3
namespace hipanel\widgets;
4
5
use kartik\date\DatePickerAsset;
6
use omnilight\assets\MomentAsset;
7
use Yii;
8
use yii\base\Widget;
9
use yii\bootstrap\Modal;
10
use yii\helpers\Html;
11
use yii\helpers\Url;
12
13
class ReminderButton extends Widget
14
{
15
    public $object_id;
16
17
    public $toggleButton = [];
18
19
    public function init()
20
    {
21
        $this->registerCLientScript();
22
    }
23
24
    public function run()
25
    {
26
        $modalId = 'reminder-modal-' . $this->object_id;
27
        $this->getView()->registerCss("button[data-target='#{$modalId}'] {margin-top: -3px;}");
28
        return AjaxModal::widget([
29
            'bulkPage' => false,
30
            'id' => $modalId,
31
            'modalFormId' => 'reminder-form-' . $this->object_id,
32
            'scenario' => 'create',
33
            'actionUrl' => ['@reminder/create-modal', 'object_id' => $this->object_id],
34
            'handleSubmit' => Url::toRoute('@reminder/create'),
35
            'size' => Modal::SIZE_DEFAULT,
36
            'header' => Html::tag('h4', Yii::t('hipanel/reminder', 'Create new reminder'), ['class' => 'modal-title']),
37
            'toggleButton' => $this->getToggleButton(),
38
        ]);
39
    }
40
41
    /**
42
     * @return mixed
43
     */
44
    public function getToggleButton()
45
    {
46
        return (!empty($this->toggleButton)) ?
47
            $this->toggleButton :
48
            [
49
                'label' => '<i class="fa fa-bell-o"></i>&nbsp;&nbsp;' . Yii::t('hipanel/reminder', 'Create reminder'),
50
                'class' => 'btn margin-bottom btn-info pull-right'
51
            ];
52
    }
53
54
    /**
55
     * @param mixed $toggleButton
56
     */
57
    public function setToggleButton($toggleButton)
58
    {
59
        $this->toggleButton = $toggleButton;
0 ignored issues
show
Documentation Bug introduced by
It seems like $toggleButton of type * is incompatible with the declared type array of property $toggleButton.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
60
    }
61
62
    public function registerClientScript()
63
    {
64
        $view = $this->getView();
65
        MomentAsset::register($view);
66
        DatePickerAsset::register($view);
67
    }
68
}
69
70