forked from AppStateESS/InternshipInventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorkflowTransitionView.php
54 lines (40 loc) · 1.66 KB
/
WorkflowTransitionView.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Intern;
class WorkflowTransitionView {
private $state;
private $form;
private $internship;
public function __construct(Internship $i, \PHPWS_Form &$form){
$this->internship = $i;
$this->form = $form;
$this->state = $this->internship->getWorkflowState();
$this->form->useRowRepeat();
}
public function show()
{
$this->form->addTplTag('WORKFLOW_STATE', $this->state->getFriendlyName());
$transitions = $this->state->getTransitions($this->internship);
// Generate the array of radio buttons to add (one for each possible transition)
$radioButtons = array();
foreach($transitions as $t){
$radioButtons[$t->getName()] = $t->getActionName();
}
// Add the radio buttons to the form
$this->form->addRadioAssoc('workflow_action', $radioButtons);
// Find and disable any transitions that aren't allowed (but still show them in the list)
$radio = $this->form->grab('workflow_action');
foreach($transitions as $t){
if(!$t->allowed($this->internship)){
// Set disabled
$radio[$t->getName()]->setDisabled(true);
}
}
if($this->state instanceof \Intern\WorkflowState\CreationState){
// New Internship, only option is 'create' transitions
$this->form->setMatch('workflow_action', 'Intern\WorkflowTransition\CreationTransition');
}else{
// Existing internship, default is to leave in current state
$this->form->setMatch('workflow_action', 'Intern\WorkflowTransition\LeaveTransition');
}
}
}