|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Symbiote\AdvancedWorkflow\FormFields; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Control\Controller; |
|
6
|
|
|
use SilverStripe\Control\RequestHandler; |
|
7
|
|
|
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowAction; |
|
8
|
|
|
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowTransition; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Handles requests for creating or editing transitions. |
|
12
|
|
|
* |
|
13
|
|
|
* @package silverstripe-advancedworkflow |
|
14
|
|
|
*/ |
|
15
|
|
|
class WorkflowFieldTransitionController extends RequestHandler |
|
16
|
|
|
{ |
|
17
|
|
|
private static $url_handlers = array( |
|
|
|
|
|
|
18
|
|
|
'new/$ParentID!' => 'handleAdd', |
|
19
|
|
|
'item/$ID!' => 'handleItem' |
|
20
|
|
|
); |
|
21
|
|
|
|
|
22
|
|
|
private static $allowed_actions = array( |
|
|
|
|
|
|
23
|
|
|
'handleAdd', |
|
24
|
|
|
'handleItem' |
|
25
|
|
|
); |
|
26
|
|
|
|
|
27
|
|
|
protected $parent; |
|
28
|
|
|
protected $name; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct($parent, $name) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->parent = $parent; |
|
33
|
|
|
$this->name = $name; |
|
34
|
|
|
|
|
35
|
|
|
parent::__construct(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function handleAdd() |
|
39
|
|
|
{ |
|
40
|
|
|
$parent = $this->request->param('ParentID'); |
|
41
|
|
|
$action = WorkflowAction::get()->byID($this->request->param('ParentID')); |
|
42
|
|
|
|
|
43
|
|
|
if (!$action || $action->WorkflowDefID != $this->RootField()->Definition()->ID) { |
|
44
|
|
|
$this->httpError(404); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if (!singleton(WorkflowTransition::class)->canCreate()) { |
|
48
|
|
|
$this->httpError(403); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$transition = new WorkflowTransition(); |
|
52
|
|
|
$transition->ActionID = $action->ID; |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
return new WorkflowFieldItemController($this, "new/$parent", $transition); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
View Code Duplication |
public function handleItem() |
|
|
|
|
|
|
58
|
|
|
{ |
|
59
|
|
|
$id = $this->request->param('ID'); |
|
60
|
|
|
$trans = WorkflowTransition::get()->byID($id); |
|
61
|
|
|
|
|
62
|
|
|
if (!$trans || $trans->Action()->WorkflowDefID != $this->RootField()->Definition()->ID) { |
|
|
|
|
|
|
63
|
|
|
$this->httpError(404); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
if (!$trans->canEdit()) { |
|
67
|
|
|
$this->httpError(403); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return new WorkflowFieldItemController($this, "item/$id", $trans); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function RootField() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->parent; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function Link($action = null) |
|
79
|
|
|
{ |
|
80
|
|
|
return Controller::join_links($this->parent->Link(), $this->name, $action); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|