|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Symbiote\AdvancedWorkflow\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Control\Controller; |
|
6
|
|
|
use SilverStripe\Control\Director; |
|
7
|
|
|
use SilverStripe\Core\Convert; |
|
8
|
|
|
use SilverStripe\ORM\DataObject; |
|
9
|
|
|
use SilverStripe\Security\Security; |
|
10
|
|
|
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowInstance; |
|
11
|
|
|
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowTransition; |
|
12
|
|
|
use Symbiote\AdvancedWorkflow\Services\WorkflowService; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Handles actions triggered from external sources, eg emails or web frontend |
|
16
|
|
|
* |
|
17
|
|
|
* @author [email protected] |
|
18
|
|
|
* @license BSD License http://silverstripe.org/bsd-license/ |
|
19
|
|
|
*/ |
|
20
|
|
|
class AdvancedWorkflowActionController extends Controller |
|
21
|
|
|
{ |
|
22
|
|
|
public function transition($request) |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
if (!Security::getCurrentUser()) { |
|
25
|
|
|
return Security::permissionFailure( |
|
26
|
|
|
$this, |
|
27
|
|
|
_t( |
|
28
|
|
|
'AdvancedWorkflowActionController.ACTION_ERROR', |
|
29
|
|
|
"You must be logged in" |
|
30
|
|
|
) |
|
31
|
|
|
); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
$id = $this->request->requestVar('id'); |
|
35
|
|
|
$transition = $this->request->requestVar('transition'); |
|
36
|
|
|
|
|
37
|
|
|
$instance = DataObject::get_by_id(WorkflowInstance::class, (int) $id); |
|
38
|
|
|
if ($instance && $instance->canEdit()) { |
|
39
|
|
|
$transition = DataObject::get_by_id(WorkflowTransition::class, (int) $transition); |
|
40
|
|
|
if ($transition) { |
|
41
|
|
|
if ($this->request->requestVar('comments')) { |
|
42
|
|
|
$action = $instance->CurrentAction(); |
|
43
|
|
|
$action->Comment = $this->request->requestVar('comments'); |
|
44
|
|
|
$action->write(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
singleton(WorkflowService::class)->executeTransition($instance->getTarget(), $transition->ID); |
|
48
|
|
|
$result = array( |
|
49
|
|
|
'success' => true, |
|
50
|
|
|
'link' => $instance->getTarget()->AbsoluteLink() |
|
51
|
|
|
); |
|
52
|
|
|
if (Director::is_ajax()) { |
|
53
|
|
|
return json_encode($result); |
|
54
|
|
|
} |
|
55
|
|
|
return $this->redirect($instance->getTarget()->Link()); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
if (Director::is_ajax()) { |
|
60
|
|
|
$result = array( |
|
61
|
|
|
'success' => false, |
|
62
|
|
|
); |
|
63
|
|
|
return json_encode($result); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $this->redirect($instance->getTarget()->Link()); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.