1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AppController |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Fr3nch13\Jira\Controller; |
8
|
|
|
|
9
|
|
|
use App\Controller\AppController as BaseController; |
10
|
|
|
use Fr3nch13\Jira\Form\AppForm as JiraForm; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* App Controller |
14
|
|
|
* |
15
|
|
|
* The base controller for the jira plugin. |
16
|
|
|
* |
17
|
|
|
* ----------------------------- |
18
|
|
|
* Inherited: |
19
|
|
|
* |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
* |
22
|
|
|
* @property \Cake\Controller\Component\AuthComponent $Auth |
23
|
|
|
*/ |
24
|
|
|
class AppController extends BaseController |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Human name of this object. |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
public $humanName = ''; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The form object. |
34
|
|
|
* @var object |
35
|
|
|
*/ |
36
|
|
|
public $JiraForm; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Initialize method |
40
|
|
|
* |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
2 |
|
public function initialize(): void |
44
|
|
|
{ |
45
|
2 |
|
parent::initialize(); |
46
|
|
|
|
47
|
2 |
|
$this->loadComponent('RequestHandler'); |
48
|
2 |
|
if (isset($this->Auth)) { |
49
|
|
|
$this->Auth->allow(['add', 'thankyou']); |
50
|
|
|
} |
51
|
|
|
|
52
|
2 |
|
$this->modelClass = false; |
53
|
|
|
|
54
|
2 |
|
$this->humanName = __('Task'); |
55
|
2 |
|
$this->JiraForm = new JiraForm(); |
56
|
2 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* The html form. |
60
|
|
|
* |
61
|
|
|
* @return \Cake\Http\Response|null Redirects on success. |
62
|
|
|
*/ |
63
|
1 |
|
public function add(): ?\Cake\Http\Response |
64
|
|
|
{ |
65
|
1 |
|
$errors = []; |
66
|
1 |
|
if ($this->getRequest()->is('post')) { |
67
|
|
|
$data = $this->getRequest()->getData(); |
68
|
|
|
if ($this->getRequest()->getQuery()) { |
69
|
|
|
$query = $this->getRequest()->getQuery(); |
70
|
|
|
if (isset($query['referer'])) { |
71
|
|
|
$data['referer'] = $query['referer']; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
if ($this->JiraForm->execute($data)) { |
75
|
|
|
$this->Flash->success(__('The {0} has been saved.', [$this->humanName])); |
76
|
|
|
|
77
|
|
|
return $this->redirect(['action' => 'thankyou', '?' => ['type' => $this->humanName]]); |
78
|
|
|
} else { |
79
|
|
|
$errors = $this->JiraForm->getErrors(); |
80
|
|
|
$this->Flash->error(__('There was a problem saving the {0}.', [$this->humanName])); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
1 |
|
if ($this->getRequest()->is('get')) { |
85
|
1 |
|
$this->JiraForm->setData($this->JiraForm->getFormData()); |
86
|
|
|
} |
87
|
|
|
|
88
|
1 |
|
$this->set([ |
89
|
1 |
|
'form' => $this->JiraForm, |
90
|
1 |
|
'errors' => $errors, |
91
|
|
|
]); |
92
|
|
|
|
93
|
1 |
|
return null; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* The thank you page after they've submitted their report. |
98
|
|
|
* |
99
|
|
|
* @return void |
100
|
|
|
*/ |
101
|
1 |
|
public function thankyou(): void |
102
|
|
|
{ |
103
|
|
|
// |
104
|
1 |
|
} |
105
|
|
|
} |
106
|
|
|
|