1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bantenprov\VueWorkflow\Http\Traits; |
4
|
|
|
use Bantenprov\VueWorkflow\Models\WorkflowType; |
5
|
|
|
use Bantenprov\VueWorkflow\Models\History; |
6
|
|
|
use Bantenprov\VueWorkflow\Models\TransitionState; |
7
|
|
|
use Bantenprov\VueWorkflow\Models\Transition; |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Workflow trait |
12
|
|
|
*/ |
13
|
|
|
trait WorkflowTrait |
14
|
|
|
{ |
|
|
|
|
15
|
|
|
|
16
|
|
|
public function insertWithWorkflow($class, $datas) |
17
|
|
|
{ |
18
|
|
|
// if(in_array('label|asc',$request)){ |
|
|
|
|
19
|
|
|
// return 'work!!'; |
20
|
|
|
// } |
21
|
|
|
//dd($request); |
22
|
|
|
//$class->create($datas); |
|
|
|
|
23
|
|
|
$workflow = WorkflowType::where('content_type', class_basename($class)); |
24
|
|
|
|
25
|
|
|
if($workflow->count() > 0){ |
26
|
|
|
$get = $class->create($datas); |
27
|
|
|
//$class->find($get->id)->delete(); |
|
|
|
|
28
|
|
|
|
29
|
|
|
$transition = Transition::where('name','propose-to-propose')->where('workflow_id',$workflow->first()->workflow_id)->first(); |
30
|
|
|
|
31
|
|
|
$this->storeHistory( |
32
|
|
|
class_basename($class), |
33
|
|
|
$get->id, |
34
|
|
|
$workflow->first()->workflow_id, |
35
|
|
|
$transition->id, |
36
|
|
|
$transition->from, |
37
|
|
|
$transition->to, |
38
|
|
|
\Auth::user()->id |
39
|
|
|
); |
40
|
|
|
}else{ |
41
|
|
|
$class->create($datas); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function storeHistory($content_type, $content_id, $workflow_id, $workflow_transition_id, $from_state, $to_state, $user_id, $message = '') |
47
|
|
|
{ |
48
|
|
|
$save['content_type'] = $content_type; |
|
|
|
|
49
|
|
|
$save['content_id'] = $content_id; |
50
|
|
|
$save['workflow_id'] = $workflow_id; |
51
|
|
|
$save['workflow_transition_id'] = $workflow_transition_id; |
52
|
|
|
$save['from_state'] = $from_state; |
53
|
|
|
$save['to_state'] = $to_state; |
54
|
|
|
$save['user_id'] = $user_id; |
55
|
|
|
$save['message'] = $message; |
56
|
|
|
|
57
|
|
|
$history = History::create($save); |
58
|
|
|
|
59
|
|
|
$this->storeTransitionState($history->to_state ,$history->content_id, $history->id); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function storeTransitionState($current_state, $content_id, $history_id) |
63
|
|
|
{ |
64
|
|
|
$save['current_state'] = $current_state; |
|
|
|
|
65
|
|
|
$save['content_id'] = $content_id; |
66
|
|
|
$save['history_id'] = $history_id; |
67
|
|
|
|
68
|
|
|
TransitionState::create($save); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function updateWithWorkflow($class, $content_id, $request) |
72
|
|
|
{ |
73
|
|
|
$check = History::where('content_id', $content_id); |
74
|
|
|
|
75
|
|
|
$response = []; |
76
|
|
|
|
77
|
|
|
if($check->count() > 1){ |
78
|
|
|
$response['message'] = "Cant update, current state must be propose !"; |
79
|
|
|
}else{ |
80
|
|
|
$class->update($request); |
81
|
|
|
$response['message'] = "Update success"; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $response; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
// public function workflowExecute($op, $datas) |
|
|
|
|
88
|
|
|
// { |
89
|
|
|
|
90
|
|
|
// } |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
|