ProjetsController.php
5.61 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
namespace App\Controller;
use App\Controller\AppController;
/**
* Projets Controller
*
* @property \App\Model\Table\ProjetsTable $Projets
*
* @method \App\Model\Entity\Projet[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = [])
*/
class ProjetsController extends AppController
{
/**
* Index method
*
* @return \Cake\Http\Response|null
*/
public function index()
{
$this->paginate = [
//'contain' => ['GroupesThematiques', 'Users']
'contain' => ['GroupesThematiques', 'Pis', 'Pms']
];
$projets = $this->paginate($this->Projets);
$this->set(compact('projets'));
}
/**
* View method
*
* @param string|null $id Projet id.
* @return \Cake\Http\Response|null
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function view($id = null)
{
$projet = $this->Projets->get($id, [
//'contain' => ['GroupesThematiques', 'Users', 'Materiels']
'contain' => ['GroupesThematiques', 'Pis', 'Pms', 'Materiels']
]);
$this->set('projet', $projet);
}
/**
* Add method
*
* @return \Cake\Http\Response|null Redirects on successful add, renders view otherwise.
*/
public function add() {
$this->add_or_edit(TRUE, null);
/*
* ORIGINAL GÉNÉRÉ PAR CAKE BAKE controller Projets :
$projet = $this->Projets->newEntity();
if ($this->request->is('post')) {
$projet = $this->Projets->patchEntity($projet, $this->request->getData());
if ($this->Projets->save($projet)) {
$this->Flash->success(__('The projet has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The projet could not be saved. Please, try again.'));
}
$groupesThematiques = $this->Projets->GroupesThematiques->find('list', ['limit' => 200]);
$users = $this->Projets->Users->find('list', ['limit' => 200]);
$this->set(compact('projet', 'groupesThematiques', 'users'));
*/
}
/**
* Edit method
*
* @param string|null $id Projet id.
* @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function edit($id = null) {
$this->add_or_edit(FALSE, $id);
/*
* ORIGINAL GÉNÉRÉ PAR CAKE BAKE controller Projets :
$projet = $this->Projets->get($id, [
'contain' => []
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$projet = $this->Projets->patchEntity($projet, $this->request->getData());
if ($this->Projets->save($projet)) {
$this->Flash->success(__('The projet has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The projet could not be saved. Please, try again.'));
}
$groupesThematiques = $this->Projets->GroupesThematiques->find('list', ['limit' => 200]);
$users = $this->Projets->Users->find('list', ['limit' => 200]);
$this->set(compact('projet', 'groupesThematiques', 'users'));
*/
}
protected function add_or_edit($IS_ADD, $id=null,
$errors=null, $entity_name=null,
array $associated_entities=[],
$with_parent=false)
{
$IS_EDIT = !$IS_ADD;
$controller = $this->request->getParam('controller'); // 'Projets'
$this->myDebug("step 3: $controller .add_or_edit()");
// ORIGINAL GÉNÉRÉ PAR CAKE BAKE controller Projets :
//$projet = $IS_ADD ? $this->Projets->newEntity() : $this->Projets->get($id, ['contain' => []]);
$entity = $IS_ADD ? $this->$controller->newEntity() : $this->$controller->get($id, ['contain' => $associated_entities]);
$allowed_request_types = $IS_ADD ? 'post' : ['patch', 'post', 'put'];
if ($this->request->is($allowed_request_types)) {
$entity = $this->$controller->patchEntity($entity, $this->request->getData());
if ($this->$controller->save($entity)) {
$this->Flash->success(__('Le projet a bien été sauvegardé'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__("Le projet n'a pas pu être sauvegardé ! Essayez à nouveau"));
}
$groupes_thematiques = $this->$controller->GroupesThematiques->find('list', ['limit' => 200]);
//$pis = $this->$controller->Users->find('list', ['limit' => 200]);
//$pis = $this->$controller->Pis->find('list', ['limit' => 200]);
$pis = $this->$controller->Pis->find('list', ['limit' => 2000]);
$pms = $pis;
$this->set(compact('IS_ADD', 'entity', 'groupes_thematiques', 'pis', 'pms'));
}
/**
* Delete method
*
* @param string|null $id Projet id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$projet = $this->Projets->get($id);
if ($this->Projets->delete($projet)) {
$this->Flash->success(__('The projet has been deleted.'));
} else {
$this->Flash->error(__('The projet could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
}