Completed
Push — master ( 630902...b2c5cd )
by Paweł
05:18
created

NotesSideWidget   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
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\helpers\Html;
14
use yii\widgets\ActiveForm;
15
16
class NotesSideWidget extends ProfileSideWidget
17
{
18
    public $header = 'Note';
19
    public $headerIcon = 'comment';
20
    public $modalToggleButton = [
21
        'label' => 'Update',
22
        'class' => 'btn btn-xs btn-link',
23
    ];
24
25
    /**
26
     * @var \app\modules\admin\models\Account
27
     */
28
    public $model;
29
30
    protected $note;
31
32
    public function init()
33
    {
34
        parent::init();
35
        /** @var AccountNote $model */
36
        $model = $this->model
37
            ->getAccountNotes()
38
            ->limit(1)
39
            ->one();
40
        $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. If $model can have other possible types, add them to modules/admin/widgets/NotesSideWidget.php:35
Loading history...
41
    }
42
43
    protected function renderModalContent()
44
    {
45
        $form = ActiveForm::begin([
46
            'method' => 'post',
47
            'action' => ['account/update-note', 'id' => $this->model->id],
48
        ]);
49
        echo $form
50
            ->field(new AccountNote(), 'note')
51
            ->label(false)
52
            ->textarea([
53
                'maxlength' => true,
54
                'rows' => 5,
55
                'placeholder' => true,
56
                'autofocus' => true,
57
                'value' => $this->note,
58
            ]);
59
60
        echo Html::submitButton('Update', ['class' => 'btn btn-small btn-primary']);
61
62
        ActiveForm::end();
63
    }
64
65
    protected function renderBoxContent()
66
    {
67
        echo "<p class=\"text-muted\">\n";
68
        echo \Yii::$app->formatter->asNtext($this->note);
69
        echo "</p>\n";
70
    }
71
}