Passed
Push — master ( f3a025...35a3f9 )
by vistart
04:23
created

ProfileFormWidget::init()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
rs 9.2
cc 4
eloc 5
nc 3
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\Organization;
16
use rhosocial\organization\Profile;
17
use yii\base\Widget;
18
19
/**
20
 * @version 1.0
21
 * @author vistart <[email protected]>
22
 */
23
class ProfileFormWidget extends Widget
24
{
25
    /**
26
     * @var Organization 
27
     */
28
    public $organization;
29
    /**
30
     * @var Profile 
31
     */
32
    public $model;
33
34
    public function init()
35
    {
36
        if (is_null($this->model) || !($this->model instanceof Profile)) {
37
            if (!$this->organization) {
38
                throw new \yii\base\InvalidConfigException("Organization or Profile should either be valid.");
39
            }
40
            $this->model = $this->organization->createProfile(['scenario' => Profile::SCENARIO_UPDATE]);
41
        }
42
    }
43
44
    public function run()
45
    {
46
        return $this->render('profile-form-widget', ['model' => $this->model]);
47
    }
48
}
49