Completed
Push — master ( efd6c7...e843b5 )
by vistart
04:27
created

OrganizationSearchWidget::init()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
rs 9.2
cc 4
eloc 8
nc 4
nop 0
1
<?php
2
3
/**
4
 *  _   __ __ _____ _____ ___  ____  _____
5
 * | | / // // ___//_  _//   ||  __||_   _|
6
 * | |/ // /(__  )  / / / /| || |     | |
7
 * |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link https://vistart.me/
9
 * @copyright Copyright (c) 2016 - 2017 vistart
10
 * @license https://vistart.me/license/
11
 */
12
13
namespace rhosocial\organization\widgets;
14
15
use rhosocial\organization\OrganizationSearch;
16
use yii\base\InvalidParamException;
17
use yii\base\Widget;
18
19
/**
20
 * Class OrganizationSearchWidget
21
 * @package rhosocial\organization\widgets
22
 * @version 1.0
23
 * @author vistart <[email protected]>
24
 */
25
class OrganizationSearchWidget extends Widget
26
{
27
    public $formId = 'organization-search-form';
28
    /**
29
     * @var null|array
30
     */
31
    public $formConfig = null;
32
    /**
33
     * @var OrganizationSearch
34
     */
35
    public $model;
36
37
    /**
38
     * @throws InvalidConfigException
39
     */
40
    public function init()
41
    {
42
        if ($this->model == null) {
43
            throw new InvalidConfigException("The search model should not be empty.");
44
        }
45
        if ($this->formConfig == null) {
46
            $this->formConfig = [
47
                'id' => !empty($this->formId) ? $this->formId : 'organization-search-form',
48
                'action' => ['index'],
49
                'method' => 'post',
50
            ];
51
        }
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function run()
58
    {
59
        return $this->render('organization-search', [
60
            'formId' => $this->formId,
61
            'formConfig' => $this->formConfig,
62
            'model' => $this->model,
63
        ]);
64
    }
65
}
66