Completed
Push — master ( 5e4c73...102525 )
by vistart
06:59
created

OrganizationListWidget::init()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 8.8571
cc 5
eloc 8
nc 5
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\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 $showGUID = false;
51
    public $showType = true;
52
    public $showParent = true;
53
    public $showChildren = true;
54
    public $showCreator = true;
55
    public $showAdmin = true;
56
    public $showMember = true;
57
58
    /**
59
     * @var boolean|array Tips.
60
     * If you do not want to show tips, please set false.
61
     * If you want to show default tips, please set true.
62
     * If you want to show tips including default ones and your owns, please set an array contains all tip text.
63
     */
64
    public $tips = true;
65
    public $showCreatedAt = true;
66
    public $showUpdatedAt = false;
67
    /**
68
     * @var string|boolean
69
     */
70
    public $gridCaption = true;
71
72
    public function init()
73
    {
74
        if (empty($this->dataProvider)) {
75
            throw new ServerErrorHttpException('Invalid Organization Provider.');
76
        }
77
        if (is_string($this->actionColumn) && strtolower($this->actionColumn) == self::ACTION_COLUMN_DEFAULT) {
78
            $this->actionColumn = [
79
                'class' => OrganizationListActionColumn::class,
80
            ];
81
        }
82
        if ($this->gridCaption === true) {
83
            $this->gridCaption = Yii::t('organization', "Here are all the organizations / departments you have joined:");
84
        }
85
    }
86
87
    public function run()
88
    {
89
        return $this->render('organization-list', [
90
            'id' => 'organization-grid-view',
91
            'gridCaption' => $this->gridCaption,
92
            'dataProvider' => $this->dataProvider,
93
            'showGUID' => $this->showGUID,
94
            'showType' => $this->showType,
95
            'showParent' => $this->showParent,
96
            'showChildren' => $this->showChildren,
97
            'showCreator' => $this->showCreator,
98
            'showAdmin' => $this->showAdmin,
99
            'showMember' => $this->showMember,
100
            'additionalColumns' => $this->additionalColumns,
101
            'actionColumn' => $this->actionColumn,
102
            'tips' => $this->tips,
103
            'showCreatedAt' => $this->showCreatedAt,
104
            'showUpdatedAt' => $this->showUpdatedAt,
105
        ]);
106
    }
107
}
108