Completed
Push — master ( 90fbd0...297549 )
by Alexey
07:11
created

UploadAvatarForm   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
eloc 16
c 1
b 0
f 1
dl 0
loc 48
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 4 2
A renderForm() 0 14 1
A init() 0 4 2
1
<?php
2
3
namespace modules\users\widgets;
4
5
use yii\base\Widget;
6
use yii\bootstrap\ActiveForm;
7
use yii\helpers\Url;
8
use yii\helpers\Html;
9
use modules\users\models\UploadForm;
10
use modules\users\Module;
11
12
/**
13
 * Class AvatarFormWidget
14
 * @package modules\users\widgets
15
 */
16
class UploadAvatarForm extends Widget
17
{
18
    /**
19
     * On/Off widget
20
     * @var bool
21
     */
22
    public $status = true;
23
    /**
24
     * @var UploadForm
25
     */
26
    public $model;
27
28
    /**
29
     * @inheritDoc
30
     */
31
    public function init()
32
    {
33
        parent::init();
34
        $this->model = $this->model ?: new UploadForm();
35
    }
36
37
    /**
38
     * @return string|void
39
     */
40
    public function run()
41
    {
42
        if ($this->status === true) {
43
            $this->renderForm();
44
        }
45
    }
46
47
    /**
48
     * Render upload form
49
     */
50
    public function renderForm()
51
    {
52
        $form = ActiveForm::begin([
53
            'action' => Url::to(['upload-image']),
54
            'options' => [
55
                'enctype' => 'multipart/form-data'
56
            ]
57
        ]);
58
        echo $form->field($this->model, 'imageFile')->fileInput();
59
        echo Html::submitButton('<span class="fa fa-upload"></span> ' . Module::t('module', 'Submit'), [
60
            'class' => 'btn btn-primary',
61
            'name' => 'submit-button',
62
        ]);
63
        ActiveForm::end();
64
    }
65
}
66