1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace App\Controller; |
4
|
|
|
|
5
|
|
|
use App\Controller\AppController; |
|
|
|
|
6
|
|
|
use Cake\I18n\Time; |
7
|
|
|
use Cake\I18n\I18n; |
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Tickets Controller |
11
|
|
|
* |
12
|
|
|
* @property \App\Model\Table\TicketsTable $Tickets |
13
|
|
|
*/ |
|
|
|
|
14
|
|
|
class TicketsController extends AppController { |
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Index method |
18
|
|
|
* |
19
|
|
|
* @return \Cake\Network\Response|null |
|
|
|
|
20
|
|
|
*/ |
21
|
1 |
|
public function index() { |
|
|
|
|
22
|
|
|
|
23
|
1 |
|
$tickets = $this->paginate($this->Tickets->find('all', ['contain' => ['Tickettypes', 'Ticketstatuses']])); |
24
|
|
|
|
25
|
1 |
|
$this->set(compact('tickets')); |
26
|
1 |
|
$this->set('_serialize', ['tickets']); |
27
|
1 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* View method |
31
|
|
|
* |
32
|
|
|
* @param string|null $id Ticket id. |
|
|
|
|
33
|
|
|
* @return \Cake\Network\Response|null |
|
|
|
|
34
|
|
|
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. |
|
|
|
|
35
|
|
|
*/ |
36
|
1 |
|
public function view($id = null) { |
|
|
|
|
37
|
1 |
|
$ticket = $this->Tickets->get($id, [ |
38
|
1 |
|
'contain' => ['Operations', 'Tickettypes'] |
|
|
|
|
39
|
|
|
]); |
40
|
|
|
|
41
|
1 |
|
$this->set('ticket', $ticket); |
42
|
1 |
|
$this->set('_serialize', ['ticket']); |
43
|
1 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Add method |
47
|
|
|
* |
48
|
|
|
* @return \Cake\Network\Response|null Redirects on successful add, renders view otherwise. |
49
|
|
|
*/ |
50
|
2 |
|
public function add() { |
|
|
|
|
51
|
2 |
|
$ticket = $this->Tickets->newEmptyEntity(); |
52
|
2 |
|
if ($this->request->is('post')) { |
53
|
2 |
|
$ticket = $this->Tickets->patchEntity($ticket, $this->getRequest()->getData()); |
54
|
2 |
|
if ($this->Tickets->save($ticket)) { |
55
|
2 |
|
$this->Flash->success(__('The ticket has been saved.')); |
56
|
|
|
|
57
|
2 |
|
return $this->redirect(['prefix' => false, 'controller' => 'Tickets', 'action' => 'index']); |
58
|
|
|
} |
|
|
|
|
59
|
|
|
$this->Flash->error(__('The ticket could not be saved. Please, try again.')); |
60
|
|
|
} |
|
|
|
|
61
|
2 |
|
$types = $this->Tickets->Tickettypes->find('list'); |
|
|
|
|
62
|
2 |
|
$statuses = $this->Tickets->Ticketstatuses->find('list'); |
63
|
2 |
|
$this->set(compact('ticket', 'types', 'statuses')); |
64
|
2 |
|
$this->set('_serialize', ['ticket']); |
65
|
2 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Edit method |
69
|
|
|
* |
70
|
|
|
* @param string|null $id Ticket id. |
|
|
|
|
71
|
|
|
* @return \Cake\Network\Response|null Redirects on successful edit, renders view otherwise. |
|
|
|
|
72
|
|
|
* @throws \Cake\Network\Exception\NotFoundException When record not found. |
|
|
|
|
73
|
|
|
*/ |
74
|
1 |
|
public function edit($id = null) { |
|
|
|
|
75
|
1 |
|
$ticket = $this->Tickets->get($id, [ |
76
|
1 |
|
'contain' => ['Tickettypes'] |
|
|
|
|
77
|
|
|
]); |
78
|
1 |
|
if ($this->request->is(['patch', 'post', 'put'])) { |
79
|
1 |
|
$ticket = $this->Tickets->patchEntity($ticket, $this->getRequest()->getData()); |
80
|
1 |
|
if ($this->Tickets->save($ticket)) { |
81
|
1 |
|
$this->Flash->success(__('The ticket has been saved.')); |
82
|
|
|
|
83
|
1 |
|
return $this->redirect(['prefix' => false, 'controller' => 'Tickets', 'action' => 'index']); |
84
|
|
|
} |
|
|
|
|
85
|
|
|
$this->Flash->error(__('The ticket could not be saved. Please, try again.')); |
86
|
|
|
} |
|
|
|
|
87
|
1 |
|
$tickettypes = $this->Tickets->Tickettypes->find('list'); |
|
|
|
|
88
|
1 |
|
$ticketstatuses = $this->Tickets->Ticketstatuses->find('list'); |
89
|
1 |
|
$this->set(compact('ticket', 'tickettypes', 'ticketstatuses')); |
90
|
1 |
|
$this->set('_serialize', ['ticket']); |
91
|
1 |
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Delete method |
95
|
|
|
* |
96
|
|
|
* @param string|null $id Ticket id. |
|
|
|
|
97
|
|
|
* @return \Cake\Network\Response|null Redirects to index. |
|
|
|
|
98
|
|
|
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. |
|
|
|
|
99
|
|
|
*/ |
100
|
1 |
|
public function delete($id = null) { |
|
|
|
|
101
|
1 |
|
$this->request->allowMethod(['post', 'delete']); |
102
|
1 |
|
$ticket = $this->Tickets->get($id); |
103
|
1 |
|
if ($this->Tickets->delete($ticket)) { |
104
|
1 |
|
$this->Flash->success(__('The ticket has been deleted.')); |
105
|
|
|
} else { |
|
|
|
|
106
|
|
|
$this->Flash->error(__('The ticket could not be deleted. Please, try again.')); |
107
|
|
|
} |
108
|
|
|
|
109
|
1 |
|
return $this->redirect(['prefix' => false, 'controller' => 'Tickets', 'action' => 'index']); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function addOperation($id = null) { |
|
|
|
|
113
|
|
|
$ticket = $this->Tickets->get($id, [ |
114
|
|
|
'contain' => [] |
|
|
|
|
115
|
|
|
]); |
116
|
|
|
|
117
|
|
|
$this->loadModel('Operations'); |
118
|
|
|
$newOperation = $this->Operations->newEntity(); |
119
|
|
|
if ($this->request->is('post')) { |
120
|
|
|
$datetimeStart = Time::parseDateTime($this->request->data['start']); |
|
|
|
|
121
|
|
|
$datetimeEnd = Time::parseDateTime($this->request->data['end']); |
|
|
|
|
122
|
|
|
$newOperation->ticket_id = $this->request->data['ticket_id']; |
|
|
|
|
123
|
|
|
$newOperation->description = $this->request->data['description']; |
124
|
|
|
$newOperation->start = $datetimeStart; |
|
|
|
|
125
|
|
|
$newOperation->end = $datetimeEnd; |
|
|
|
|
126
|
|
|
if ($this->Operations->save($newOperation)) { |
127
|
|
|
$this->Flash->success(__('The new operation has been saved.')); |
128
|
|
|
return $this->redirect(['prefix' => false, 'controller' => 'Tickets', 'action' => 'view', $this->request->data['ticket_id']]); |
129
|
|
|
} |
|
|
|
|
130
|
|
|
$this->Flash->error(__('The new operation could not be saved. Please, try again.')); |
131
|
|
|
} |
|
|
|
|
132
|
|
|
$newOperation->ticket_id = $id; |
133
|
|
|
$this->set('newOperation', $newOperation); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
|
|
|
|
137
|
|
|
* @param null $operation_id |
|
|
|
|
138
|
|
|
* @return \Cake\Network\Response|null |
139
|
|
|
*/ |
140
|
|
|
public function editOperation($operation_id = null) { |
|
|
|
|
141
|
|
|
|
142
|
|
|
$this->loadModel('Operations'); |
143
|
|
|
$operation = $this->Operations->get($operation_id, [ |
144
|
|
|
'contain' => ['Tickets'] |
|
|
|
|
145
|
|
|
]); |
146
|
|
|
if ($this->request->is(['patch', 'post', 'put'])) { |
147
|
|
|
$this->request->data['start'] = Time::parseDateTime($this->request->data['start']); |
148
|
|
|
$this->request->data['end'] = Time::parseDateTime($this->request->data['end']); |
|
|
|
|
149
|
|
|
$operation = $this->Operations->patchEntity($operation, $this->request->data); |
|
|
|
|
150
|
|
|
|
151
|
|
|
if ($this->Operations->save($operation)) { |
152
|
|
|
$this->Flash->success(__('The operation has been saved.')); |
153
|
|
|
|
154
|
|
|
return $this->redirect(['prefix' => false, 'controller' => 'Tickets', 'action' => 'view', $this->request->data['ticket_id']]); |
155
|
|
|
} |
|
|
|
|
156
|
|
|
$this->Flash->error(__('The operation could not be saved. Please, try again.')); |
157
|
|
|
} |
|
|
|
|
158
|
|
|
$this->set(compact('operation')); |
159
|
|
|
$this->set('_serialize', ['operation']); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function viewOperation($id = null) { |
|
|
|
|
163
|
|
|
|
164
|
|
|
$this->loadModel('Operations'); |
165
|
|
|
$operation = $this->Operations->get($id, [ |
166
|
|
|
'contain' => ['Tickets'] |
|
|
|
|
167
|
|
|
]); |
168
|
|
|
|
169
|
|
|
$this->set('operation', $operation); |
170
|
|
|
$this->set('_serialize', ['operation']); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function deleteOperation($id = null) { |
|
|
|
|
174
|
|
|
|
175
|
|
|
$this->loadModel('Operations'); |
176
|
|
|
$this->request->allowMethod(['post', 'delete']); |
177
|
|
|
$operation = $this->Operations->get($id, [ |
178
|
|
|
'contain' => ['Tickets'] |
|
|
|
|
179
|
|
|
] |
|
|
|
|
180
|
|
|
); |
181
|
|
|
if ($this->Operations->delete($operation)) { |
182
|
|
|
$this->Flash->success(__('The operation has been deleted.')); |
183
|
|
|
} else { |
|
|
|
|
184
|
|
|
$this->Flash->error(__('The operation could not be deleted. Please, try again.')); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
return $this->redirect(['prefix' => false, 'controller' => 'Tickets', 'action' => 'view', $operation->ticket_id]); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
} |
191
|
|
|
|