|
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\user\widgets; |
|
14
|
|
|
|
|
15
|
|
|
use rhosocial\user\grid\ActionColumn; |
|
16
|
|
|
use Yii; |
|
17
|
|
|
use yii\base\Widget; |
|
18
|
|
|
use yii\data\ActiveDataProvider; |
|
19
|
|
|
use yii\helpers\Url; |
|
20
|
|
|
use yii\web\ServerErrorHttpException; |
|
21
|
|
|
|
|
22
|
|
|
class UserListWidget extends Widget |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var ActiveDataProvider |
|
26
|
|
|
*/ |
|
27
|
|
|
public $dataProvider; |
|
28
|
|
|
/** |
|
29
|
|
|
* @var array|null|string ActionColumn class configuration. Null if you do not need it. |
|
30
|
|
|
* 'default' if you want to use the default configuration. |
|
31
|
|
|
* Note: If you want to use your own ActionColumn class configuration, please do not |
|
32
|
|
|
* forget to attach the 'class' key. |
|
33
|
|
|
*/ |
|
34
|
|
|
public $actionColumn; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var array|null Additional columns' configuration arrays. |
|
38
|
|
|
* It will be appended after the existed columns. |
|
39
|
|
|
* If you do not need additional columns, please set null. |
|
40
|
|
|
*/ |
|
41
|
|
|
public $additionalColumns; |
|
42
|
|
|
|
|
43
|
|
|
const ACTION_COLUMN_DEFAULT = 'default'; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var array Column visibles. |
|
47
|
|
|
*/ |
|
48
|
|
|
public $visible = [ |
|
49
|
|
|
'guid' => false, |
|
50
|
|
|
]; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var boolean|array Tips. |
|
54
|
|
|
* If you do not want to show tips, please set false. |
|
55
|
|
|
* If you want to show default tips, please set true. |
|
56
|
|
|
* If you want to show tips including default ones and your owns, please set an array contains all tip text. |
|
57
|
|
|
*/ |
|
58
|
|
|
public $tips = true; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Initialize attributes. |
|
62
|
|
|
*/ |
|
63
|
|
|
public function init() |
|
64
|
|
|
{ |
|
65
|
|
|
if (empty($this->dataProvider)) { |
|
66
|
|
|
throw new ServerErrorHttpException('Invalid User Provider.'); |
|
67
|
|
|
} |
|
68
|
|
|
if (is_string($this->actionColumn) && strtolower($this->actionColumn) == self::ACTION_COLUMN_DEFAULT) { |
|
69
|
|
|
$this->actionColumn = [ |
|
70
|
|
|
'class' => ActionColumn::class, |
|
71
|
|
|
'header' => Yii::t('user', 'Action'), |
|
72
|
|
|
'useIcon' => false, |
|
73
|
|
|
'urlCreator' => function ($action, $model, $key, $index, ActionColumn $column) { |
|
|
|
|
|
|
74
|
|
|
/* @var $model User */ |
|
75
|
|
|
if ($action == 'view') { |
|
76
|
|
|
return Url::to(['view', 'id' => $model->id]); |
|
77
|
|
|
} elseif ($action == 'update') { |
|
78
|
|
|
return Url::to(['update', 'id' => $model->id]); |
|
79
|
|
|
} elseif ($action == 'delete') { |
|
80
|
|
|
return Url::to(['deregister', 'id' => $model->id]); |
|
81
|
|
|
} |
|
82
|
|
|
return '#'; |
|
83
|
|
|
}, |
|
84
|
|
|
'visibleButtons' => [ |
|
85
|
|
|
'view' => Yii::$app->user->can('viewUser'), |
|
86
|
|
|
'update' => Yii::$app->user->can('updateUser'), |
|
87
|
|
|
'delete' => Yii::$app->user->can('deleteUser'), |
|
88
|
|
|
], |
|
89
|
|
|
]; |
|
90
|
|
|
} |
|
91
|
|
|
parent::init(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Run action. |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
public function run() |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->render('user-list', [ |
|
101
|
|
|
'dataProvider' => $this->dataProvider, |
|
102
|
|
|
'additionalColumns' => $this->additionalColumns, |
|
103
|
|
|
'actionColumn' => $this->actionColumn, |
|
104
|
|
|
'visible' => $this->visible, |
|
105
|
|
|
'tips' => $this->tips, |
|
106
|
|
|
]); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.