Completed
Push — master ( 9d0cba...630902 )
by Paweł
02:59
created

NotesSideWidget::init()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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 function renderModalContent()
31
    {
32
        $form = ActiveForm::begin([
33
            'method' => 'post',
34
            'action' => ['account/update-note', 'id' => $this->model->id],
35
        ]);
36
        $note = $this->getNote();
37
        echo $form
38
            ->field(new AccountNote(), 'note')
39
            ->label(false)
40
            ->textarea([
41
                'maxlength' => true,
42
                'rows' => 5,
43
                'placeholder' => true,
44
                'autofocus' => true,
45
                'value' => $note,
46
            ]);
47
48
        echo Html::submitButton('Update', ['class' => 'btn btn-small btn-primary']);
49
50
        ActiveForm::end();
51
    }
52
53
    protected function renderBoxContent()
54
    {
55
        $note = $this->getNote();
56
        echo "<p class=\"text-muted\">\n";
57
        echo \Yii::$app->formatter->asNtext($note);
58
        echo "</p>\n";
59
    }
60
61
    protected function getNote()
62
    {
63
        /** @var AccountNote $note */
64
        $note = $this->model->getAccountNotes()->limit(1)->one();
65
66
        return $note ? $note->note : null;
0 ignored issues
show
introduced by
$note is of type app\models\AccountNote, thus it always evaluated to true. If $note can have other possible types, add them to modules/admin/widgets/NotesSideWidget.php:63
Loading history...
67
    }
68
}