ProjetsController.php
8.04 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?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 {
// Jolis labels pour chaque champ de l'entité
//@Override
protected $nice_field_labels = [
'groupes_thematique_id' => 'Groupe thématique',
'chef_science_id' => 'Responsable scientifique',
'chef_projet_id' => 'Chef de projet',
'date_start' => 'Date début',
'date_stop' => 'Date fin',
];
/*
protected function getControllerNameForFK($fk_name) {
if ($fk_name=='chef_science_id') return 'PIs';
if ($fk_name=='chef_projet_id') return 'PMs';
return parent::getControllerNameForFK($fk_name);
}
*/
protected function getRealControllerNameForAlias($alias_name) {
if ($alias_name == 'ChefSciences') return 'Users';
if ($alias_name == 'ChefProjets') return 'Users';
return $alias_name;
}
/**
* Index method
*
* @return \Cake\Http\Response|null
*/
public function index()
{
// https://book.cakephp.org/3/fr/controllers/components/pagination.html
$this->paginate = [
//'contain' => ['GroupesThematiques', 'Users']
//'contain' => ['GroupesThematiques', 'Pis', 'Pms']
'contain' => ['GroupesThematiques', 'ChefSciences', 'ChefProjets']
];
$projets = $this->paginate();
// ce qui équivaut à :
//s$projets = $this->paginate($this->Projets);
// Si on est sur l'instance de l'IRAP (InventIrap)
// on affiche l'url vers la page des Groupes métiers sur le site web de l'IRAP
$lab_website_urls = ($this->confLabinvent->labNameShort != 'IRAP') ?
[]
:
[
'Projets Instrumentaux' => 'https://www.irap.omp.eu/sedoo-project-tag/projets_instrumentaux',
'Projets Scientifiques' => 'https://www.irap.omp.eu/sedoo-project-tag/projets-scientifiques',
'Projets R&T' => 'https://www.irap.omp.eu/sedoo-project-tag/rt',
'Projets financés (ANR, Europe...)' => 'https://www.irap.omp.eu/observation-instrumentation/projets/projets-finances',
];
$this->set(compact('projets', 'lab_website_urls'));
}
/**
* 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']
]);
debug($projet); exit;
*/
$child_entity_types = [
'Materiels',
];
//return parent::view($id, $associated_entity_types);
return $this->view_generic($id, $child_entity_types);
/*
$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->ChefSciences->find('list', ['limit' => 2000]);
//$pms = $pis;
$pms = $this->$controller->ChefProjets->find('list', ['limit' => 2000]);
//$pis = $this->$controller->Users->find('list', ['limit' => 200]);
//$pis = $this->$controller->Pis->find('list', ['limit' => 200]);
//$pis = $this->$controller->Pis->find('list', ['limit' => 2000]);
$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']);
}
}