1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* A workflow action that allows additional users or groups to be assigned to |
4
|
|
|
* the workflow part-way through the workflow path. |
5
|
|
|
* |
6
|
|
|
* @license BSD License (http://silverstripe.org/bsd-license/) |
7
|
|
|
* @package advancedworkflow |
8
|
|
|
* @subpackage actions |
9
|
|
|
*/ |
10
|
|
|
class AssignUsersToWorkflowAction extends WorkflowAction { |
11
|
|
|
|
12
|
|
|
private static $db = array( |
13
|
|
|
'AssignInitiator' => 'Boolean', |
14
|
|
|
); |
15
|
|
|
|
16
|
|
|
private static $many_many = array( |
17
|
|
|
'Users' => 'Member', |
18
|
|
|
'Groups' => 'Group' |
19
|
|
|
); |
20
|
|
|
|
21
|
|
|
public static $icon = 'advancedworkflow/images/assign.png'; |
22
|
|
|
|
23
|
|
|
public function execute(WorkflowInstance $workflow) { |
24
|
|
|
$workflow->Users()->removeAll(); |
25
|
|
|
//Due to http://open.silverstripe.org/ticket/8258, there are errors occuring if Group has been extended |
26
|
|
|
//We use a direct delete query here before ticket 8258 fixed |
27
|
|
|
//$workflow->Groups()->removeAll(); |
28
|
|
|
$workflowID = $workflow->ID; |
29
|
|
|
$query = <<<SQL |
30
|
|
|
DELETE FROM "WorkflowInstance_Groups" WHERE ("WorkflowInstance_Groups"."WorkflowInstanceID" = '$workflowID'); |
31
|
|
|
SQL; |
32
|
|
|
DB::query($query); |
33
|
|
|
$workflow->Users()->addMany($this->Users()); |
34
|
|
|
$workflow->Groups()->addMany($this->Groups()); |
35
|
|
|
if ($this->AssignInitiator) { |
|
|
|
|
36
|
|
|
$workflow->Users()->add($workflow->Initiator()); |
|
|
|
|
37
|
|
|
} |
38
|
|
|
return true; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getCMSFields() { |
42
|
|
|
$fields = parent::getCMSFields(); |
43
|
|
|
|
44
|
|
|
$cmsUsers = Member::mapInCMSGroups(); |
45
|
|
|
|
46
|
|
|
$fields->addFieldsToTab('Root.Main', array( |
47
|
|
|
new HeaderField('AssignUsers', $this->fieldLabel('AssignUsers')), |
48
|
|
|
new CheckboxField('AssignInitiator', $this->fieldLabel('AssignInitiator')), |
49
|
|
|
$users = CheckboxSetField::create('Users', $this->fieldLabel('Users'), $cmsUsers), |
50
|
|
|
new TreeMultiselectField('Groups', $this->fieldLabel('Groups'), 'Group') |
51
|
|
|
)); |
52
|
|
|
|
53
|
|
|
// limit to the users which actually can access the CMS |
54
|
|
|
$users->setSource(Member::mapInCMSGroups()); |
55
|
|
|
|
56
|
|
|
return $fields; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function fieldLabels($relations = true) { |
60
|
|
|
return array_merge(parent::fieldLabels($relations), array( |
61
|
|
|
'AssignUsers' => _t('AssignUsersToWorkflowAction.ASSIGNUSERS', 'Assign Users'), |
62
|
|
|
'Users' => _t('AssignUsersToWorkflowAction.USERS', 'Users'), |
63
|
|
|
'Groups' => _t('AssignUsersToWorkflowAction.GROUPS', 'Groups'), |
64
|
|
|
'AssignInitiator' => _t('AssignUsersToWorkflowAction.INITIATOR', 'Assign Initiator'), |
65
|
|
|
)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Returns a set of all Members that are assigned to this WorkflowAction subclass, either directly or via a group. |
70
|
|
|
* |
71
|
|
|
* @return ArrayList |
72
|
|
|
*/ |
73
|
|
|
public function getAssignedMembers() { |
74
|
|
|
$members = $this->Users(); |
75
|
|
|
$groups = $this->Groups(); |
76
|
|
|
|
77
|
|
|
// Can't merge instances of DataList so convert to something where we can |
78
|
|
|
$_members = ArrayList::create(); |
79
|
|
|
$members->each(function($item) use(&$_members) { |
80
|
|
|
$_members->push($item); |
81
|
|
|
}); |
82
|
|
|
|
83
|
|
|
$_groups = ArrayList::create(); |
84
|
|
|
$groups->each(function($item) use(&$_groups) { |
85
|
|
|
$_groups->push($item); |
86
|
|
|
}); |
87
|
|
|
|
88
|
|
|
foreach($_groups as $group) { |
89
|
|
|
$_members->merge($group->Members()); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$_members->removeDuplicates(); |
93
|
|
|
return $_members; |
94
|
|
|
} |
95
|
|
|
} |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.