|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Handles requests for creating or editing transitions. |
|
4
|
|
|
* |
|
5
|
|
|
* @package silverstripe-advancedworkflow |
|
6
|
|
|
*/ |
|
7
|
|
|
class WorkflowFieldTransitionController extends RequestHandler { |
|
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
public static $url_handlers = array( |
|
10
|
|
|
'new/$ParentID!' => 'handleAdd', |
|
11
|
|
|
'item/$ID!' => 'handleItem' |
|
12
|
|
|
); |
|
13
|
|
|
|
|
14
|
|
|
public static $allowed_actions = array( |
|
15
|
|
|
'handleAdd', |
|
16
|
|
|
'handleItem' |
|
17
|
|
|
); |
|
18
|
|
|
|
|
19
|
|
|
protected $parent; |
|
20
|
|
|
protected $name; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct($parent, $name) { |
|
23
|
|
|
$this->parent = $parent; |
|
24
|
|
|
$this->name = $name; |
|
25
|
|
|
|
|
26
|
|
|
parent::__construct(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function handleAdd() { |
|
30
|
|
|
$parent = $this->request->param('ParentID'); |
|
31
|
|
|
$action = WorkflowAction::get()->byID($this->request->param('ParentID')); |
|
32
|
|
|
|
|
33
|
|
|
if(!$action || $action->WorkflowDefID != $this->RootField()->Definition()->ID) { |
|
34
|
|
|
$this->httpError(404); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
if(!singleton('WorkflowTransition')->canCreate()) { |
|
38
|
|
|
$this->httpError(403); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$transition = new WorkflowTransition(); |
|
42
|
|
|
$transition->ActionID = $action->ID; |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
return new WorkflowFieldItemController($this, "new/$parent", $transition); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
View Code Duplication |
public function handleItem() { |
|
|
|
|
|
|
48
|
|
|
$id = $this->request->param('ID'); |
|
49
|
|
|
$trans = WorkflowTransition::get()->byID($id); |
|
50
|
|
|
|
|
51
|
|
|
if(!$trans || $trans->Action()->WorkflowDefID != $this->RootField()->Definition()->ID) { |
|
|
|
|
|
|
52
|
|
|
$this->httpError(404); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
if(!$trans->canEdit()) { |
|
56
|
|
|
$this->httpError(403); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return new WorkflowFieldItemController($this, "item/$id", $trans); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function RootField() { |
|
63
|
|
|
return $this->parent; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function Link($action = null) { |
|
67
|
|
|
return Controller::join_links($this->parent->Link(), $this->name, $action); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.