NotesSideWidget   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 31
c 2
b 0
f 0
dl 0
loc 54
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A renderBoxContent() 0 5 1
A init() 0 9 2
A renderModalContent() 0 20 1
1
<?php
2
/**
3
 * Created for IG Monitoring.
4
 * User: jakim <[email protected]>
5
 * Date: 17.02.2018
6
 */
7
8
namespace app\modules\admin\widgets;
9
10
11
use app\models\AccountNote;
12
use app\modules\admin\widgets\base\ProfileSideWidget;
13
use Yii;
14
use yii\helpers\Html;
15
use yii\widgets\ActiveForm;
16
17
class NotesSideWidget extends ProfileSideWidget
18
{
19
    public $header = 'Note';
20
    public $headerIcon = 'comment';
21
    public $modalToggleButton = [
22
        'label' => 'Update',
23
        'class' => 'btn btn-xs btn-link',
24
    ];
25
26
    /**
27
     * @var \app\modules\admin\models\Account
28
     */
29
    public $model;
30
31
    protected $note;
32
33
    public function init()
34
    {
35
        parent::init();
36
        /** @var AccountNote $model */
37
        $model = $this->model
38
            ->getAccountNotes()
39
            ->limit(1)
40
            ->one();
41
        $this->note = $model ? $model->note : null;
0 ignored issues
show
introduced by
$model is of type app\models\AccountNote, thus it always evaluated to true.
Loading history...
42
    }
43
44
    protected function renderModalContent()
45
    {
46
        $form = ActiveForm::begin([
47
            'method' => 'post',
48
            'action' => ['account/update-note', 'id' => $this->model->id],
49
        ]);
50
        echo $form
51
            ->field(new AccountNote(), 'note')
52
            ->label(false)
53
            ->textarea([
54
                'maxlength' => true,
55
                'rows' => 5,
56
                'placeholder' => true,
57
                'autofocus' => true,
58
                'value' => $this->note,
59
            ]);
60
61
        echo Html::submitButton('Update', ['class' => 'btn btn-small btn-primary']);
62
63
        ActiveForm::end();
64
    }
65
66
    protected function renderBoxContent()
67
    {
68
        echo "<p class=\"text-muted\">\n";
69
        echo Yii::$app->formatter->asNtext($this->note);
70
        echo "</p>\n";
71
    }
72
}