Passed
Push — master ( f14a0a...1212a9 )
by vistart
04:51
created

OrganizationListWidget   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 11 4
A run() 0 11 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\grid\OrganizationListActionColumn;
16
use Yii;
17
use yii\base\Widget;
18
use yii\data\ActiveDataProvider;
19
use yii\web\ServerErrorHttpException;
20
21
/**
22
 * Class OrganizationListWidget
23
 * @package rhosocial\organization\widgets
24
 * @version 1.0
25
 * @author vistart <[email protected]>
26
 */
27
class OrganizationListWidget extends Widget
28
{
29
    /**
30
     * @var ActiveDataProvider
31
     */
32
    public $dataProvider;
33
34
    const ACTION_COLUMN_DEFAULT = 'default';
35
    /**
36
     * @var array|null|string ActionColumn class configuration. Null if you do not need it.
37
     * 'default' if you want to use the OrganizationListActionColumn.
38
     * Note: If you want to use your own ActionColumn class configuration, please do not
39
     * forget to attach the 'class' key.
40
     */
41
    public $actionColumn;
42
43
    /**
44
     * @var array|null Additional columns' configuration arrays.
45
     * It will be appended after the existed columns.
46
     * If you do not need additional columns, please set null.
47
     */
48
    public $additionalColumns;
49
50
    public $orgOnly = false;
51
    public $showGUID = false;
52
53
    public function init()
54
    {
55
        if (empty($this->dataProvider)) {
56
            throw new ServerErrorHttpException('Invalid Organization Provider.');
57
        }
58
        if (is_string($this->actionColumn) && strtolower($this->actionColumn) == self::ACTION_COLUMN_DEFAULT) {
59
            $this->actionColumn = [
60
                'class' => OrganizationListActionColumn::class,
61
            ];
62
        }
63
    }
64
65
    public function run()
66
    {
67
        return $this->render('organization-list', [
68
            'id' => 'organization-grid-view',
69
            'dataProvider' => $this->dataProvider,
70
            'orgOnly' => $this->orgOnly,
71
            'showGUID' => $this->showGUID,
72
            'additionalColumns' => $this->additionalColumns,
73
            'actionColumn' => $this->actionColumn,
74
        ]);
75
    }
76
}
77