|
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\grid; |
|
14
|
|
|
|
|
15
|
|
|
use rhosocial\user\User; |
|
16
|
|
|
use rhosocial\organization\Organization; |
|
17
|
|
|
use Yii; |
|
18
|
|
|
use yii\grid\ActionColumn; |
|
19
|
|
|
use yii\helpers\Url; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class AddMemberActionColumn |
|
23
|
|
|
* @version 1.0 |
|
24
|
|
|
* @author vistart <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class AddMemberActionColumn extends ActionColumn |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
public $template = '{add}'; |
|
32
|
|
|
/** |
|
33
|
|
|
* @var bool |
|
34
|
|
|
*/ |
|
35
|
|
|
public $addConfirm = false; |
|
36
|
|
|
/** |
|
37
|
|
|
* @var Organization |
|
38
|
|
|
*/ |
|
39
|
|
|
public $organization; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Initializes the default button rendering callbacks. |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function initDefaultButtons() |
|
45
|
|
|
{ |
|
46
|
|
|
$buttonAddOptions = [ |
|
47
|
|
|
'data-method' => 'post', |
|
48
|
|
|
]; |
|
49
|
|
|
if ($this->addConfirm) { |
|
50
|
|
|
$buttonAddOptions['data-confirm'] = Yii::t('organization', 'Are you sure to add this user to the organization / department?'); |
|
51
|
|
|
} |
|
52
|
|
|
$this->initDefaultButton('add', 'plus', $buttonAddOptions); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function init() |
|
56
|
|
|
{ |
|
57
|
|
|
parent::init(); |
|
58
|
|
|
$this->initUrlCreator(); |
|
59
|
|
|
$this->initVisibleButtons(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
protected function initUrlCreator() |
|
63
|
|
|
{ |
|
64
|
|
|
if (isset($this->urlCreator)) { |
|
65
|
|
|
return; |
|
66
|
|
|
} |
|
67
|
|
|
$this->urlCreator = function ($action, $model, $key, $index, AddMemberActionColumn $column) { |
|
68
|
|
|
/* @var $model User */ |
|
69
|
|
|
if ($action == 'add') { |
|
70
|
|
|
return Url::to(['add-member', 'org' => $column->organization->getID(), 'u' => $model->id]); |
|
71
|
|
|
} |
|
72
|
|
|
return '#'; |
|
73
|
|
|
}; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
protected function initVisibleButtons() |
|
77
|
|
|
{ |
|
78
|
|
|
if (!empty($this->visibleButtons)) { |
|
79
|
|
|
return; |
|
80
|
|
|
} |
|
81
|
|
|
$this->visibleButtons = [ |
|
82
|
|
|
'add' => function ($model, $key, $index) { |
|
|
|
|
|
|
83
|
|
|
return !$this->organization->hasMember($model->id); |
|
84
|
|
|
} |
|
85
|
|
|
]; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.