Completed
Push — master ( 090439...148aa2 )
by vistart
19:15
created

JoinOrganizationFormWidget   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 47
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 12 4
A run() 0 8 1
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\forms\JoinOrganizationForm;
16
use rhosocial\organization\Organization;
17
use yii\base\InvalidConfigException;
18
use yii\base\Widget;
19
20
/**
21
 * Class JoinOrganizationFormWidget
22
 * @package rhosocial\organization\widgets
23
 * @version 1.0
24
 * @author vistart <[email protected]>
25
 */
26
class JoinOrganizationFormWidget extends Widget
27
{
28
    /**
29
     * @var JoinOrganizationForm
30
     */
31
    public $model;
32
33
    /**
34
     * @var array
35
     */
36
    public $formConfig;
37
38
    /**
39
     * @var bool
40
     */
41
    public $join = true;
42
43
    /**
44
     * @inheritdoc
45
     * @throws InvalidConfigException
46
     */
47
    public function init()
48
    {
49
        if (!$this->model->organization) {
50
            throw new InvalidConfigException("The organization should not be empty.");
51
        }
52
        if (empty($this->formConfig)) {
53
            $this->formConfig = [
54
                'id' => 'join-organization-form-' . $this->model->organization->getID(),
55
                'action' => [$this->join ? 'join' : 'exit', 'entrance' => $this->model->organization->getJoinEntranceUrl()],
56
            ];
57
        }
58
    }
59
60
    /**
61
     * Run action
62
     * @return string
63
     */
64
    public function run()
65
    {
66
        return $this->render('join-organization-form', [
67
            'model' => $this->model,
68
            'join' => $this->join,
69
            'formConfig' => $this->formConfig,
70
        ]);
71
    }
72
}
73