1 |
<?php |
<?php |
2 |
//$Id$ |
//$Id$ |
3 |
//gen openMairie le 14/04/2020 14:11 |
//gen openMairie le 14/04/2020 14:11 |
4 |
|
|
5 |
require_once "../gen/obj/task.class.php"; |
require_once "../gen/obj/task.class.php"; |
6 |
|
|
7 |
class task extends task_gen { |
class task extends task_gen { |
8 |
|
|
9 |
|
const STATUS_DRAFT = 'draft'; |
10 |
|
const STATUS_NEW = 'new'; |
11 |
|
const STATUS_PENDING = 'pending'; |
12 |
|
const STATUS_DONE = 'done'; |
13 |
|
const STATUS_ERROR = 'error'; |
14 |
|
const STATUS_DEBUG = 'debug'; |
15 |
|
const STATUS_ARCHIVED = 'archived'; |
16 |
|
|
17 |
|
/** |
18 |
|
* Liste des types de tâche concernant les services instructeurs |
19 |
|
*/ |
20 |
|
const TASK_TYPE_SI = array( |
21 |
|
'creation_DA', |
22 |
|
'creation_DI', |
23 |
|
'depot_DI', |
24 |
|
'modification_DI', |
25 |
|
'qualification_DI', |
26 |
|
'decision_DI', |
27 |
|
'incompletude_DI', |
28 |
|
'completude_DI', |
29 |
|
'ajout_piece', |
30 |
|
'add_piece', |
31 |
|
'creation_consultation', |
32 |
|
'modification_DA', |
33 |
|
'create_DI', |
34 |
|
); |
35 |
|
|
36 |
|
/** |
37 |
|
* Liste des types de tâche concernant les services consultés |
38 |
|
*/ |
39 |
|
const TASK_TYPE_SC = array( |
40 |
|
'create_DI_for_consultation', |
41 |
|
'avis_consultation', |
42 |
|
'pec_metier_consultation', |
43 |
|
); |
44 |
|
|
45 |
/** |
/** |
46 |
* Définition des actions disponibles sur la classe. |
* Définition des actions disponibles sur la classe. |
47 |
* |
* |
55 |
"view" => "view_json_data", |
"view" => "view_json_data", |
56 |
"permission_suffix" => "consulter", |
"permission_suffix" => "consulter", |
57 |
); |
); |
58 |
|
$this->class_actions[997] = array( |
59 |
|
"identifier" => "json_data", |
60 |
|
"view" => "post_update_task", |
61 |
|
"permission_suffix" => "modifier", |
62 |
|
); |
63 |
|
$this->class_actions[996] = array( |
64 |
|
"identifier" => "json_data", |
65 |
|
"view" => "post_add_task", |
66 |
|
"permission_suffix" => "ajouter", |
67 |
|
); |
68 |
} |
} |
69 |
|
|
70 |
public function setvalF($val = array()) { |
public function setvalF($val = array()) { |
71 |
|
|
72 |
|
// // les guillets doubles sont remplacés automatiquement par des simples |
73 |
|
// // dans core/om_formulaire.clasS.php::recupererPostvar() |
74 |
|
// // voir le ticket https://dev.atreal.fr/projets/openmairie/tracker/209 |
75 |
|
// // ceci est un hack sale temporaire en attendant résolution du ticket |
76 |
|
// foreach(array('json_payload', 'timestamp_log') as $key) { |
77 |
|
// if (isset($val[$key]) && ! empty($val[$key]) && |
78 |
|
// isset($_POST[$key]) && ! empty($_POST[$key])) { |
79 |
|
// $submited_payload = $_POST[$key]; |
80 |
|
// if (! empty($submited_payload)) { |
81 |
|
// $new_payload = str_replace("'", '"', $val[$key]); |
82 |
|
// if ($new_payload == $submited_payload || |
83 |
|
// strpos($submited_payload, '"') === false) { |
84 |
|
// $val[$key] = $new_payload; |
85 |
|
// } |
86 |
|
// else { |
87 |
|
// $error_msg = sprintf( |
88 |
|
// __("La convertion des guillemets de la payload JSON '%s' ". |
89 |
|
// "n'est pas idempotente (courante: %s, postée: %s, convertie: %s)"), |
90 |
|
// $key, var_export($val[$key], true), var_export($submited_payload, true), |
91 |
|
// var_export($new_payload, true)); |
92 |
|
// $this->correct = false; |
93 |
|
// $this->addToMessage($error_msg); |
94 |
|
// $this->addToLog(__METHOD__."() erreur : $error_msg", DEBUG_MODE); |
95 |
|
// return false; |
96 |
|
// } |
97 |
|
// } |
98 |
|
// } |
99 |
|
// } |
100 |
|
|
101 |
parent::setvalF($val); |
parent::setvalF($val); |
102 |
// |
|
103 |
|
// XXX Ancien code : permet de ne pas avoir d'erreru lors de la modification d'une task |
104 |
if (array_key_exists('timestamp_log', $val) === true) { |
if (array_key_exists('timestamp_log', $val) === true) { |
105 |
$this->valF['timestamp_log'] = str_replace("'", '"', $val['timestamp_log']); |
$this->valF['timestamp_log'] = str_replace("'", '"', $val['timestamp_log']); |
106 |
} |
} |
107 |
|
|
108 |
|
// récupération de l'ID de l'objet existant |
109 |
|
$id = property_exists($this, 'id') ? $this->id : null; |
110 |
|
if(isset($val[$this->clePrimaire])) { |
111 |
|
$id = $val[$this->clePrimaire]; |
112 |
|
} elseif(isset($this->valF[$this->clePrimaire])) { |
113 |
|
$id = $this->valF[$this->clePrimaire]; |
114 |
|
} |
115 |
|
|
116 |
|
// MODE MODIFIER |
117 |
|
if (! empty($id)) { |
118 |
|
|
119 |
|
// si aucune payload n'est fourni (devrait toujours être le cas) |
120 |
|
if (! isset($val['json_payload']) || empty($val['json_payload'])) { |
121 |
|
|
122 |
|
// récupère l'objet existant |
123 |
|
$existing = $this->f->findObjectById(get_class($this), $id); |
124 |
|
if (! empty($existing)) { |
125 |
|
|
126 |
|
// récupère la payload de l'objet |
127 |
|
$val['json_payload'] = $existing->getVal('json_payload'); |
128 |
|
$this->valF['json_payload'] = $existing->getVal('json_payload'); |
129 |
|
$this->f->addToLog(__METHOD__."() récupère la payload de la tâche existante ". |
130 |
|
"'$id': ".$existing->getVal('json_payload'), EXTRA_VERBOSE_MODE); |
131 |
|
} |
132 |
|
} |
133 |
|
} |
134 |
} |
} |
135 |
|
|
136 |
/** |
/** |
144 |
"state", |
"state", |
145 |
"object_id", |
"object_id", |
146 |
"dossier", |
"dossier", |
147 |
|
"stream", |
148 |
"json_payload", |
"json_payload", |
149 |
"timestamp_log", |
"timestamp_log", |
150 |
); |
); |
152 |
|
|
153 |
function setType(&$form, $maj) { |
function setType(&$form, $maj) { |
154 |
parent::setType($form, $maj); |
parent::setType($form, $maj); |
155 |
|
|
156 |
// Récupération du mode de l'action |
// Récupération du mode de l'action |
157 |
$crud = $this->get_action_crud($maj); |
$crud = $this->get_action_crud($maj); |
158 |
|
|
159 |
if ($maj < 2) { |
// MODE CREER |
160 |
|
if ($maj == 0 || $crud == 'create') { |
161 |
$form->setType("state", "select"); |
$form->setType("state", "select"); |
162 |
|
$form->setType("stream", "select"); |
163 |
$form->setType("json_payload", "textarea"); |
$form->setType("json_payload", "textarea"); |
164 |
} |
} |
165 |
if ($maj == 3){ |
// MDOE MODIFIER |
166 |
|
if ($maj == 1 || $crud == 'update') { |
167 |
|
$form->setType("state", "select"); |
168 |
|
$form->setType("stream", "select"); |
169 |
|
$form->setType("json_payload", "jsonprettyprint"); |
170 |
|
} |
171 |
|
// MODE CONSULTER |
172 |
|
if ($maj == 3 || $crud == 'read') { |
173 |
$form->setType('dossier', 'link'); |
$form->setType('dossier', 'link'); |
174 |
$form->setType('json_payload', 'jsonprettyprint'); |
$form->setType('json_payload', 'jsonprettyprint'); |
175 |
} |
} |
181 |
*/ |
*/ |
182 |
function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) { |
function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) { |
183 |
if($maj < 2) { |
if($maj < 2) { |
|
$contenu=array(); |
|
184 |
|
|
185 |
$contenu[0][0]="draft"; |
$contenu = array(); |
186 |
$contenu[1][0]=_('draft'); |
foreach(array('DRAFT', 'NEW', 'PENDING', 'DONE', 'ERROR', 'DEBUG') as $key) { |
187 |
$contenu[0][1]="new"; |
$const_name = 'STATUS_'.$key; |
188 |
$contenu[1][1]=_('new'); |
$const_value = constant("self::$const_name"); |
189 |
$contenu[0][2]="pending"; |
$contenu[0][] = $const_value; |
190 |
$contenu[1][2]=_('pending'); |
$contenu[1][] = __($const_value); |
191 |
$contenu[0][3]="done"; |
} |
|
$contenu[1][3]=_('done'); |
|
|
$contenu[0][4]="archived"; |
|
|
$contenu[1][4]=_('archived'); |
|
|
$contenu[0][5]="error"; |
|
|
$contenu[1][5]=_('error'); |
|
|
$contenu[0][6]="debug"; |
|
|
$contenu[1][6]=_('debug'); |
|
192 |
|
|
193 |
$form->setSelect("state", $contenu); |
$form->setSelect("state", $contenu); |
194 |
|
|
195 |
|
$contenu_stream =array(); |
196 |
|
$contenu_stream[0][0]="input"; |
197 |
|
$contenu_stream[1][0]=_('input'); |
198 |
|
$contenu_stream[0][1]="output"; |
199 |
|
$contenu_stream[1][1]=_('output'); |
200 |
|
$form->setSelect("stream", $contenu_stream); |
201 |
|
|
202 |
} |
} |
203 |
|
|
204 |
if ($maj == 3) { |
if ($maj == 3) { |
205 |
$inst_dossier = $this->f->get_inst__om_dbform(array( |
if ($this->getVal('stream') == 'output') { |
206 |
"obj" => "dossier", |
$inst_dossier = $this->f->get_inst__om_dbform(array( |
207 |
"idx" => $form->val['dossier'], |
"obj" => "dossier", |
208 |
)); |
"idx" => $form->val['dossier'], |
209 |
|
)); |
|
if($form->val['type'] == "creation_DA"){ |
|
|
$obj_link = 'dossier_autorisation'; |
|
|
} else { |
|
|
$obj_link = 'dossier_instruction'; |
|
|
} |
|
210 |
|
|
211 |
$params = array(); |
if($form->val['type'] == "creation_DA" |
212 |
$params['obj'] = $obj_link; |
|| $form->val['type'] == "modification_DA"){ |
213 |
$params['libelle'] = $inst_dossier->getVal('dossier'); |
// |
214 |
$params['title'] = "Consulter le dossier"; |
$obj_link = 'dossier_autorisation'; |
215 |
$params['idx'] = $form->val['dossier']; |
} else { |
216 |
$form->setSelect("dossier", $params); |
$obj_link = 'dossier_instruction'; |
217 |
|
} |
218 |
|
|
219 |
|
$params = array(); |
220 |
|
$params['obj'] = $obj_link; |
221 |
|
$params['libelle'] = $inst_dossier->getVal('dossier'); |
222 |
|
$params['title'] = "Consulter le dossier"; |
223 |
|
$params['idx'] = $form->val['dossier']; |
224 |
|
$form->setSelect("dossier", $params); |
225 |
|
} |
226 |
} |
} |
227 |
} |
} |
228 |
|
|
234 |
function setVal(&$form, $maj, $validation, &$dnu1 = null, $dnu2 = null) { |
function setVal(&$form, $maj, $validation, &$dnu1 = null, $dnu2 = null) { |
235 |
// parent::setVal($form, $maj, $validation); |
// parent::setVal($form, $maj, $validation); |
236 |
// |
// |
237 |
$form->setVal('json_payload', $this->view_form_json(true)); |
if ($this->getVal('stream') == "output") { |
238 |
|
$form->setVal('json_payload', $this->view_form_json(true)); |
239 |
|
} else { |
240 |
|
$form->setVal('json_payload', htmlentities($this->getVal('json_payload'))); |
241 |
|
} |
242 |
|
} |
243 |
|
|
244 |
|
function setLib(&$form, $maj) { |
245 |
|
parent::setLib($form, $maj); |
246 |
|
|
247 |
|
// Récupération du mode de l'action |
248 |
|
$crud = $this->get_action_crud($maj); |
249 |
|
|
250 |
|
// MODE different de CREER |
251 |
|
if ($maj != 0 || $crud != 'create') { |
252 |
|
$form->setLib('json_payload', ''); |
253 |
|
} |
254 |
} |
} |
255 |
|
|
256 |
public function verifier($val = array(), &$dnu1 = null, $dnu2 = null) { |
public function verifier($val = array(), &$dnu1 = null, $dnu2 = null) { |
257 |
parent::verifier($val, $dnu1, $dnu2); |
$ret = parent::verifier($val, $dnu1, $dnu2); |
258 |
// |
|
259 |
if (array_key_exists('timestamp_log', $this->valF) === true |
// une tâche entrante doit avoir un type et une payload non-vide |
260 |
&& is_array(json_decode($this->valF['timestamp_log'], true)) === false) { |
if (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') { |
261 |
// |
if (isset($this->valF['type']) === false) { |
262 |
$this->correct = false; |
$this->correct = false; |
263 |
$this->addToMessage(sprintf( |
$this->addToMessage(sprintf( |
264 |
__("Le champ %s doit être dans un format JSON valide."), |
__("Le champ %s est obligatoire pour une tâche entrante."), |
265 |
sprintf('<span class="bold">%s</span>', $this->getLibFromField('timestamp_log')) |
sprintf('<span class="bold">%s</span>', $this->getLibFromField('type')) |
266 |
)); |
)); |
267 |
|
$this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE); |
268 |
|
} |
269 |
|
if (isset($this->valF['json_payload']) === false) { |
270 |
|
$this->correct = false; |
271 |
|
$this->addToMessage(sprintf( |
272 |
|
__("Le champ %s est obligatoire pour une tâche entrante."), |
273 |
|
sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload')) |
274 |
|
)); |
275 |
|
$this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE); |
276 |
|
} |
277 |
} |
} |
278 |
|
|
279 |
|
// les JSONs doivent être décodables |
280 |
|
foreach(array('json_payload', 'timestamp_log') as $key) { |
281 |
|
if (isset($this->valF[$key]) && ! empty($this->valF[$key]) && ( |
282 |
|
is_array(json_decode($this->valF[$key], true)) === false |
283 |
|
|| json_last_error() !== JSON_ERROR_NONE)) { |
284 |
|
$this->correct = false; |
285 |
|
$champ_text = sprintf('<span class="bold">%s</span>', $this->getLibFromField($key)); |
286 |
|
$this->addToMessage(sprintf( |
287 |
|
__("Le champ %s doit être dans un format JSON valide (erreur: %s).". |
288 |
|
"<p>%s valF:</br><pre>%s</pre></p>". |
289 |
|
"<p>%s val:</br><pre>%s</pre></p>". |
290 |
|
"<p>%s POST:</br><pre>%s</pre></p>". |
291 |
|
"<p>%s submitted POST value:</br><pre>%s</pre></p>"), |
292 |
|
$champ_text, |
293 |
|
json_last_error() !== JSON_ERROR_NONE ? json_last_error_msg() : __('invalide'), |
294 |
|
$champ_text, |
295 |
|
$this->valF[$key], |
296 |
|
$champ_text, |
297 |
|
$val[$key], |
298 |
|
$champ_text, |
299 |
|
isset($_POST[$key]) ? $_POST[$key] : '', |
300 |
|
$champ_text, |
301 |
|
$this->f->get_submitted_post_value($key) |
302 |
|
)); |
303 |
|
$this->addToLog(__METHOD__.'(): erreur JSON: '.$this->msg, DEBUG_MODE); |
304 |
|
} |
305 |
|
} |
306 |
|
|
307 |
|
// une tâche entrante doit avoir une payload avec les clés requises |
308 |
|
if ($this->correct && (isset($this->valF['stream']) === false || |
309 |
|
$this->valF['stream'] == 'input')) { |
310 |
|
|
311 |
|
// décode la payload JSON |
312 |
|
$json_payload = json_decode($this->valF['json_payload'], true); |
313 |
|
|
314 |
|
// défini une liste de chemin de clés requises |
315 |
|
$paths = array( |
316 |
|
'external_uids/dossier' |
317 |
|
); |
318 |
|
|
319 |
|
// tâche de type création de DI/DA |
320 |
|
if (isset($this->valF['type']) !== false && $this->valF['type'] == 'create_DI_for_consultation') { |
321 |
|
|
322 |
|
$paths = array_merge($paths, array( |
323 |
|
'dossier/dossier', |
324 |
|
'dossier/dossier_autorisation_type_detaille_code', |
325 |
|
'dossier/date_demande', |
326 |
|
'dossier/depot_electronique', |
327 |
|
)); |
328 |
|
|
329 |
|
// si l'option commune est activée (mode MC) |
330 |
|
if ($this->f->is_option_dossier_commune_enabled()) { |
331 |
|
$paths[] = 'dossier/insee'; |
332 |
|
} |
333 |
|
|
334 |
|
// présence d'un moyen d'identifier la collectivité/le service |
335 |
|
if (! isset($json_payload['external_uids']['acteur']) && |
336 |
|
! isset($json_payload['dossier']['om_collectivite'])) { |
337 |
|
$this->correct = false; |
338 |
|
$this->addToMessage(sprintf( |
339 |
|
__("L'une des clés %s ou %s est obligatoire dans le contenu du champ %s pour une tâche entrante."), |
340 |
|
sprintf('<span class="bold">%s</span>', 'external_uids/acteur'), |
341 |
|
sprintf('<span class="bold">%s</span>', 'dossier/om_collectivite'), |
342 |
|
sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload')) |
343 |
|
)); |
344 |
|
$this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE); |
345 |
|
} |
346 |
|
} |
347 |
|
|
348 |
|
// pas d'erreur déjà trouvée |
349 |
|
if($this->correct) { |
350 |
|
|
351 |
|
// pour chaque chemin |
352 |
|
foreach($paths as $path) { |
353 |
|
|
354 |
|
// décompose le chemin |
355 |
|
$tokens = explode('/', $path); |
356 |
|
$cur_depth = $json_payload; |
357 |
|
|
358 |
|
// descend au et à mesure dans l'arborescence du chemin |
359 |
|
foreach($tokens as $token) { |
360 |
|
|
361 |
|
// en vérifiant que chaque élément du chemin est défini et non-nul |
362 |
|
if (isset($cur_depth[$token]) === false) { |
363 |
|
|
364 |
|
// sinon on produit une erreur |
365 |
|
$this->correct = false; |
366 |
|
$this->addToMessage(sprintf( |
367 |
|
__("La clé %s est obligatoire dans le contenu du champ %s pour une tâche entrante."), |
368 |
|
sprintf('<span class="bold">%s</span>', $path), |
369 |
|
sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload')) |
370 |
|
)); |
371 |
|
$this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE); |
372 |
|
break 2; |
373 |
|
} |
374 |
|
$cur_depth = $cur_depth[$token]; |
375 |
|
} |
376 |
|
} |
377 |
|
} |
378 |
|
} |
379 |
|
|
380 |
|
return $ret && $this->correct; |
381 |
} |
} |
382 |
|
|
383 |
protected function task_exists(string $type, string $object_id) { |
/** |
384 |
|
* [task_exists description] |
385 |
|
* @param string $type [description] |
386 |
|
* @param string $object_id [description] |
387 |
|
* @return [type] [description] |
388 |
|
*/ |
389 |
|
public function task_exists(string $type, string $object_id) { |
390 |
$query = sprintf(' |
$query = sprintf(' |
391 |
SELECT task |
SELECT task |
392 |
FROM %1$stask |
FROM %1$stask |
395 |
AND object_id = \'%4$s\' |
AND object_id = \'%4$s\' |
396 |
', |
', |
397 |
DB_PREFIXE, |
DB_PREFIXE, |
398 |
'done', |
self::STATUS_DONE, |
399 |
$type, |
$type, |
400 |
$object_id |
$object_id |
401 |
); |
); |
407 |
} |
} |
408 |
|
|
409 |
/** |
/** |
410 |
|
* TRIGGER - triggerajouter. |
411 |
|
* |
412 |
|
* @param string $id |
413 |
|
* @param null &$dnu1 @deprecated Ne pas utiliser. |
414 |
|
* @param array $val Tableau des valeurs brutes. |
415 |
|
* @param null $dnu2 @deprecated Ne pas utiliser. |
416 |
|
* |
417 |
|
* @return boolean |
418 |
|
*/ |
419 |
|
function triggerajouter($id, &$dnu1 = null, $val = array(), $dnu2 = null) { |
420 |
|
|
421 |
|
// tâche entrante |
422 |
|
if (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') { |
423 |
|
|
424 |
|
// décode la paylod JSON pour extraire les données métiers à ajouter |
425 |
|
// en tant que métadonnées de la tâche |
426 |
|
$json_payload = json_decode($this->valF['json_payload'], true); |
427 |
|
|
428 |
|
// si la tâche possède déjà une clé dossier |
429 |
|
if (isset($json_payload['dossier']['dossier']) && |
430 |
|
! empty($json_payload['dossier']['dossier'])) { |
431 |
|
$this->valF["dossier"] = $json_payload['dossier']['dossier']; |
432 |
|
} |
433 |
|
} |
434 |
|
} |
435 |
|
|
436 |
|
/** |
437 |
* TREATMENT - add_task |
* TREATMENT - add_task |
438 |
* Ajoute un enregistrement. |
* Ajoute un enregistrement. |
439 |
* |
* |
442 |
*/ |
*/ |
443 |
public function add_task($params = array()) { |
public function add_task($params = array()) { |
444 |
$this->begin_treatment(__METHOD__); |
$this->begin_treatment(__METHOD__); |
445 |
|
|
446 |
|
// Vérifie si la task doit être ajoutée en fonction du mode de l'application, |
447 |
|
// seulement pour les tasks output |
448 |
|
$task_types_si = self::TASK_TYPE_SI; |
449 |
|
$task_types_sc = self::TASK_TYPE_SC; |
450 |
|
$stream = isset($params['val']['stream']) === true ? $params['val']['stream'] : 'output'; |
451 |
|
if ($stream === 'output' |
452 |
|
&& isset($params['val']['type']) === true |
453 |
|
&& $this->f->is_option_mode_service_consulte_enabled() === true |
454 |
|
&& in_array($params['val']['type'], $task_types_sc) === false) { |
455 |
|
// |
456 |
|
return $this->end_treatment(__METHOD__, true); |
457 |
|
} |
458 |
|
if ($stream === 'output' |
459 |
|
&& isset($params['val']['type']) === true |
460 |
|
&& $this->f->is_option_mode_service_consulte_enabled() === false |
461 |
|
&& in_array($params['val']['type'], $task_types_si) === false) { |
462 |
|
// |
463 |
|
return $this->end_treatment(__METHOD__, true); |
464 |
|
} |
465 |
|
|
466 |
$timestamp_log = json_encode(array( |
$timestamp_log = json_encode(array( |
467 |
'creation_date' => date('Y-m-d H:i:s'), |
'creation_date' => date('Y-m-d H:i:s'), |
468 |
)); |
)); |
469 |
|
|
470 |
|
// Si la tâche est de type ajout_piece et de stream input alors on ajoute le fichier |
471 |
|
// et on ajoute l'uid dans le champ json_payload avant l'ajout de la tâche |
472 |
|
if (isset($params['val']['type']) |
473 |
|
&& ($params['val']['type'] == "add_piece" || $params['val']['type'] == "avis_consultation") |
474 |
|
&& isset($params['val']['stream']) |
475 |
|
&& $params['val']['stream'] == "input" ) { |
476 |
|
// |
477 |
|
$json_payload = json_decode($params['val']['json_payload'], true); |
478 |
|
if (json_last_error() !== JSON_ERROR_NONE) { |
479 |
|
$this->addToMessage(__("Le contenu JSON de la tâche n'est pas valide.")); |
480 |
|
return $this->end_treatment(__METHOD__, false); |
481 |
|
} |
482 |
|
if (isset($json_payload['document_numerise']) === true |
483 |
|
&& empty($json_payload['document_numerise']) === false) { |
484 |
|
// |
485 |
|
$document_numerise = $json_payload['document_numerise']; |
486 |
|
$file_content = base64_decode($document_numerise["file_content"]); |
487 |
|
if ($file_content === false){ |
488 |
|
$this->addToMessage(__("Le contenu du fichier lié à la tâche n'a pas pu etre recupere.")); |
489 |
|
return $this->end_treatment(__METHOD__, false); |
490 |
|
} |
491 |
|
$metadata = array( |
492 |
|
"filename" => $document_numerise['nom_fichier'], |
493 |
|
"size" => strlen($file_content), |
494 |
|
"mimetype" => $document_numerise['file_content_type'], |
495 |
|
"date_creation" => isset($document_numerise['date_creation']) === true ? $document_numerise['date_creation'] : date("Y-m-d"), |
496 |
|
); |
497 |
|
$uid_fichier = $this->f->storage->create($file_content, $metadata, "from_content", "task.uid_fichier"); |
498 |
|
if ($uid_fichier === OP_FAILURE) { |
499 |
|
$this->addToMessage(__("Erreur lors de la creation du fichier lié à la tâche.")); |
500 |
|
return $this->end_treatment(__METHOD__, false); |
501 |
|
} |
502 |
|
$json_payload["document_numerise"]["uid"] = $uid_fichier; |
503 |
|
// Le fichier a été ajouté nous n'avons plus besoin du champ file_content dans la payload |
504 |
|
unset($json_payload["document_numerise"]["file_content"]); |
505 |
|
$params['val']['json_payload'] = json_encode($json_payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
506 |
|
} |
507 |
|
} |
508 |
|
|
509 |
// Mise à jour du DI |
// Mise à jour du DI |
510 |
$valF = array( |
$valF = array( |
511 |
'task' => '', |
'task' => '', |
512 |
'type' => $params['val']['type'], |
'type' => $params['val']['type'], |
513 |
'timestamp_log' => $timestamp_log, |
'timestamp_log' => $timestamp_log, |
514 |
'state' => isset($params['val']['state']) === true ? $params['val']['state'] : 'new', |
'state' => isset($params['val']['state']) === true ? $params['val']['state'] : self::STATUS_NEW, |
515 |
'object_id' => $params['val']['object_id'], |
'object_id' => isset($params['val']['object_id']) ? $params['val']['object_id'] : '', |
516 |
'dossier' => $params['val']['dossier'], |
'dossier' => isset($params['val']['dossier']) ? $params['val']['dossier'] : '', |
517 |
'json_payload' => '{}', |
'stream' => $stream, |
518 |
); |
'json_payload' => isset($params['val']['json_payload']) === true ? $params['val']['json_payload'] : '{}', |
519 |
$task_exists = $this->task_exists($valF['type'], $valF['object_id']); |
); |
520 |
if ($valF['type'] === 'modification_DI' && $task_exists === false) { |
|
521 |
$task_exists = $this->task_exists('creation_DI', $valF['object_id']); |
// tâche sortante |
522 |
} |
if($valF["stream"] == "output"){ |
523 |
if ($task_exists !== false) { |
|
524 |
$inst_task = $this->f->get_inst__om_dbform(array( |
// TODO expliquer ce code |
525 |
"obj" => "task", |
$task_exists = $this->task_exists($valF['type'], $valF['object_id']); |
526 |
"idx" => $task_exists, |
if ($valF['type'] === 'modification_DI' && $task_exists === false) { |
527 |
)); |
$task_exists = $this->task_exists('creation_DI', $valF['object_id']); |
528 |
$update_state = $inst_task->getVal('state'); |
} |
529 |
if (isset($params['update_val']['state']) === true) { |
if ($valF['type'] === 'modification_DA' && $task_exists === false) { |
530 |
$update_state = $params['update_val']['state']; |
$task_exists = $this->task_exists('creation_DA', $valF['object_id']); |
531 |
|
} |
532 |
|
if ($task_exists !== false) { |
533 |
|
$inst_task = $this->f->get_inst__om_dbform(array( |
534 |
|
"obj" => "task", |
535 |
|
"idx" => $task_exists, |
536 |
|
)); |
537 |
|
$update_state = $inst_task->getVal('state'); |
538 |
|
if (isset($params['update_val']['state']) === true) { |
539 |
|
$update_state = $params['update_val']['state']; |
540 |
|
} |
541 |
|
$update_params = array( |
542 |
|
'val' => array( |
543 |
|
'state' => $update_state, |
544 |
|
), |
545 |
|
); |
546 |
|
return $inst_task->update_task($update_params); |
547 |
} |
} |
|
$update_params = array( |
|
|
'val' => array( |
|
|
'state' => $update_state, |
|
|
), |
|
|
); |
|
|
return $inst_task->update_task($update_params); |
|
548 |
} |
} |
549 |
|
|
550 |
$add = $this->ajouter($valF); |
$add = $this->ajouter($valF); |
551 |
|
$this->addToLog(__METHOD__."(): retour de l'ajout de tâche: ".var_export($add, true), VERBOSE_MODE); |
552 |
if ($add === false) { |
if ($add === false) { |
553 |
$this->addToLog($this->msg, DEBUG_MODE); |
$this->addToLog(__METHOD__."(): ".$this->msg, DEBUG_MODE); |
554 |
return $this->end_treatment(__METHOD__, false); |
return $this->end_treatment(__METHOD__, false); |
555 |
} |
} |
556 |
return $this->end_treatment(__METHOD__, true); |
return $this->end_treatment(__METHOD__, true); |
567 |
$this->begin_treatment(__METHOD__); |
$this->begin_treatment(__METHOD__); |
568 |
$timestamp_log = $this->get_timestamp_log(); |
$timestamp_log = $this->get_timestamp_log(); |
569 |
if ($timestamp_log === false) { |
if ($timestamp_log === false) { |
570 |
$this->addToLog(__('XXX'), DEBUG_MODE); |
$this->addToLog(__METHOD__."(): erreur timestamp log", DEBUG_MODE); |
571 |
return $this->end_treatment(__METHOD__, false); |
return $this->end_treatment(__METHOD__, false); |
572 |
} |
} |
573 |
array_push($timestamp_log, array( |
array_push($timestamp_log, array( |
582 |
'timestamp_log' => $timestamp_log, |
'timestamp_log' => $timestamp_log, |
583 |
'state' => $params['val']['state'], |
'state' => $params['val']['state'], |
584 |
'object_id' => $this->getVal('object_id'), |
'object_id' => $this->getVal('object_id'), |
585 |
|
'stream' => $this->getVal('stream'), |
586 |
'dossier' => $this->getVal('dossier'), |
'dossier' => $this->getVal('dossier'), |
587 |
'json_payload' => $this->getVal('json_payload'), |
'json_payload' => $this->getVal('json_payload'), |
588 |
); |
); |
597 |
/** |
/** |
598 |
* Récupère le journal d'horodatage dans le champ timestamp_log de |
* Récupère le journal d'horodatage dans le champ timestamp_log de |
599 |
* l'enregistrement instancié. |
* l'enregistrement instancié. |
600 |
* |
* |
601 |
* @param array $params Tableau des paramètres |
* @param array $params Tableau des paramètres |
602 |
* @return array sinon false en cas d'erreur |
* @return array sinon false en cas d'erreur |
603 |
*/ |
*/ |
655 |
$list_tasks = array(); |
$list_tasks = array(); |
656 |
foreach ($res['result'] as $task) { |
foreach ($res['result'] as $task) { |
657 |
$task['timestamp_log'] = json_decode($task['timestamp_log'], true); |
$task['timestamp_log'] = json_decode($task['timestamp_log'], true); |
658 |
$task['dossier'] = $task['object_id']; |
$task['dossier'] = $task['dossier']; |
659 |
if ($this->get_lien_objet_by_type($task['type']) === 'document_numerise') { |
if ($task['type'] === 'ajout_piece') { |
660 |
$val_dn = $this->get_document_numerise_data($task['object_id']); |
$val_dn = $this->get_document_numerise_data($task['object_id']); |
661 |
$task['dossier'] = $val_dn['dossier']; |
} |
662 |
|
if ($task['stream'] === 'output') { |
663 |
|
$task['external_uids'] = $this->get_all_external_uids($task['dossier']); |
664 |
} |
} |
665 |
$list_tasks[$task['task']] = $task; |
$list_tasks[$task['task']] = $task; |
666 |
} |
} |
803 |
return $val_dt; |
return $val_dt; |
804 |
} |
} |
805 |
|
|
806 |
|
/** |
807 |
|
* Récupère la liste des objets distincts existants dans la table des liens |
808 |
|
* entre identifiants internes et identifiants externes. |
809 |
|
* |
810 |
|
* @return array |
811 |
|
*/ |
812 |
|
protected function get_list_distinct_objects_external_link() { |
813 |
|
$query = sprintf(' |
814 |
|
SELECT |
815 |
|
DISTINCT(object) |
816 |
|
FROM %1$slien_id_interne_uid_externe |
817 |
|
ORDER BY object ASC |
818 |
|
', |
819 |
|
DB_PREFIXE |
820 |
|
); |
821 |
|
$res = $this->f->get_all_results_from_db_query($query, true); |
822 |
|
if ($res['code'] === 'KO') { |
823 |
|
return array(); |
824 |
|
} |
825 |
|
$result = array(); |
826 |
|
foreach ($res['result'] as $object) { |
827 |
|
$result[] = $object['object']; |
828 |
|
} |
829 |
|
return $result; |
830 |
|
} |
831 |
|
|
832 |
protected function get_external_uid($fk_idx, string $fk_idx_2) { |
protected function get_external_uid($fk_idx, string $fk_idx_2) { |
833 |
$inst_external_uid = $this->f->get_inst__by_other_idx(array( |
$inst_external_uid = $this->f->get_inst__by_other_idx(array( |
834 |
"obj" => "lien_id_interne_uid_externe", |
"obj" => "lien_id_interne_uid_externe", |
840 |
return $inst_external_uid->getVal('external_uid'); |
return $inst_external_uid->getVal('external_uid'); |
841 |
} |
} |
842 |
|
|
843 |
|
protected function get_all_external_uids($fk_idx, $link_objects = array()) { |
844 |
|
if (count($link_objects) == 0) { |
845 |
|
$link_objects = $this->get_list_distinct_objects_external_link(); |
846 |
|
} |
847 |
|
$val_external_uid = array(); |
848 |
|
foreach ($link_objects as $link_object) { |
849 |
|
$external_uid = $this->get_external_uid($fk_idx, $link_object); |
850 |
|
if ($external_uid !== '' && $external_uid !== null) { |
851 |
|
$val_external_uid[$link_object] = $external_uid; |
852 |
|
} |
853 |
|
} |
854 |
|
return $val_external_uid; |
855 |
|
} |
856 |
|
|
857 |
protected function get_demandeurs_data(string $dossier) { |
protected function get_demandeurs_data(string $dossier) { |
858 |
$val_demandeur = array(); |
$val_demandeur = array(); |
859 |
$inst_di = $this->f->get_inst__om_dbform(array( |
$inst_di = $this->f->get_inst__om_dbform(array( |
886 |
return $val_architecte; |
return $val_architecte; |
887 |
} |
} |
888 |
|
|
889 |
protected function get_instruction_data(string $dossier, $type = 'decision') { |
protected function get_instruction_data(string $dossier, $type = 'decision', $extra_params = array()) { |
890 |
$val_instruction = null; |
$val_instruction = null; |
891 |
$instruction_with_doc = null; |
$instruction_with_doc = null; |
892 |
$inst_di = $this->f->get_inst__om_dbform(array( |
$inst_di = $this->f->get_inst__om_dbform(array( |
900 |
if ($type === 'incompletude') { |
if ($type === 'incompletude') { |
901 |
$idx = $inst_di->get_last_instruction_incompletude(); |
$idx = $inst_di->get_last_instruction_incompletude(); |
902 |
} |
} |
903 |
|
// XXX Permet de récupérer l'instruction par son identifiant |
904 |
|
if ($type === 'with-id') { |
905 |
|
$idx = $extra_params['with-id']; |
906 |
|
} |
907 |
$inst_instruction = $this->f->get_inst__om_dbform(array( |
$inst_instruction = $this->f->get_inst__om_dbform(array( |
908 |
"obj" => "instruction", |
"obj" => "instruction", |
909 |
"idx" => $idx, |
"idx" => $idx, |
949 |
|
|
950 |
protected function sort_instruction_data(array $values, array $res) { |
protected function sort_instruction_data(array $values, array $res) { |
951 |
$fields = array( |
$fields = array( |
952 |
|
"date_evenement", |
953 |
"date_envoi_signature", |
"date_envoi_signature", |
954 |
"date_retour_signature", |
"date_retour_signature", |
955 |
"date_envoi_rar", |
"date_envoi_rar", |
1010 |
return $val_dp; |
return $val_dp; |
1011 |
} |
} |
1012 |
|
|
1013 |
protected function view_form_json($in_field = false) { |
protected function get_avis_decision_data(string $dossier) { |
1014 |
// Mise à jour des valeurs |
$inst_di = $this->f->get_inst__om_dbform(array( |
1015 |
if ($this->f->get_submitted_post_value('valid') === 'true' |
"obj" => "dossier", |
1016 |
&& $this->f->get_submitted_post_value('state') !== null) { |
"idx" => $dossier, |
1017 |
// |
)); |
1018 |
$params = array( |
$ad = $inst_di->getVal('avis_decision'); |
1019 |
'val' => array( |
$val_ad = array(); |
1020 |
'state' => $this->f->get_submitted_post_value('state') |
if ($ad !== null) { |
1021 |
), |
$inst_ad = $this->f->get_inst__om_dbform(array( |
1022 |
); |
"obj" => "avis_decision", |
1023 |
$update = $this->update_task($params); |
"idx" => $ad, |
1024 |
$message_class = "valid"; |
)); |
1025 |
$message = $this->msg; |
$val_ad = $inst_ad->get_json_data(); |
1026 |
if ($update === false) { |
$val_ad['txAvis'] = "Voir document joint"; |
1027 |
$this->addToLog($this->msg, DEBUG_MODE); |
if (isset($val_ad['tacite']) === true |
1028 |
$message_class = "error"; |
&& $val_ad['tacite'] === 't') { |
1029 |
$message = sprintf( |
// |
1030 |
'%s %s', |
$val_ad['txAvis'] = "Sans objet"; |
|
__('Impossible de mettre à jour la tâche.'), |
|
|
__('Veuillez contacter votre administrateur.') |
|
|
); |
|
1031 |
} |
} |
|
$this->f->displayMessage($message_class, $message); |
|
1032 |
} |
} |
1033 |
// |
return $val_ad; |
1034 |
if ($this->f->get_submitted_post_value('valid') === 'true' |
} |
1035 |
&& $this->f->get_submitted_post_value('external_uid') !== null) { |
|
1036 |
|
protected function get_signataire_arrete_data(string $sa) { |
1037 |
|
$inst_sa = $this->f->get_inst__om_dbform(array( |
1038 |
|
"obj" => "signataire_arrete", |
1039 |
|
"idx" => $sa, |
1040 |
|
)); |
1041 |
|
$val_sa = array_combine($inst_sa->champs, $inst_sa->val); |
1042 |
|
foreach ($val_sa as $key => $value) { |
1043 |
|
$val_sa[$key] = strip_tags($value); |
1044 |
|
} |
1045 |
|
return $val_sa; |
1046 |
|
} |
1047 |
|
|
1048 |
|
// XXX WIP |
1049 |
|
protected function get_consultation_data(string $consultation) { |
1050 |
|
$val_consultation = array(); |
1051 |
|
$inst_consultation = $this->f->get_inst__om_dbform(array( |
1052 |
|
"obj" => "consultation", |
1053 |
|
"idx" => $consultation, |
1054 |
|
)); |
1055 |
|
$val_consultation = $inst_consultation->get_json_data(); |
1056 |
|
if (isset($val_consultation['fichier']) === true |
1057 |
|
&& $val_consultation['fichier'] !== '') { |
1058 |
// |
// |
1059 |
$inst_lien = $this->f->get_inst__om_dbform(array( |
$val_consultation['path_fichier'] = sprintf('%s&snippet=%s&obj=%s&champ=%s&id=%s', 'app/index.php?module=form', 'file', 'consultation', 'fichier', $this->getVal('object_id')); |
1060 |
"obj" => "lien_id_interne_uid_externe", |
} |
1061 |
"idx" => ']', |
if (isset($val_consultation['om_fichier_consultation']) === true |
1062 |
)); |
&& $val_consultation['om_fichier_consultation'] !== '') { |
1063 |
$valF = array( |
// |
1064 |
'lien_id_interne_uid_externe' => '', |
$val_consultation['path_om_fichier_consultation'] = sprintf('%s&snippet=%s&obj=%s&champ=%s&id=%s', 'app/index.php?module=form', 'file', 'consultation', 'om_fichier_consultation', $this->getVal('object_id')); |
|
'object' => $this->get_lien_objet_by_type($this->getVal('type')), |
|
|
'object_id' => $this->getVal('object_id'), |
|
|
'external_uid' => $this->f->get_submitted_post_value('external_uid'), |
|
|
); |
|
|
$add = $inst_lien->ajouter($valF); |
|
|
$message_class = "valid"; |
|
|
$message = $inst_lien->msg; |
|
|
if ($add === false) { |
|
|
$this->addToLog($inst_lien->msg, DEBUG_MODE); |
|
|
$message_class = "error"; |
|
|
$message = sprintf( |
|
|
'%s %s', |
|
|
__("Impossible de mettre à jour le lien entre l'identifiant interne et l'identifiant de l'application externe."), |
|
|
__('Veuillez contacter votre administrateur.') |
|
|
); |
|
|
} |
|
|
$this->f->displayMessage($message_class, $message); |
|
1065 |
} |
} |
1066 |
|
return $val_consultation; |
1067 |
|
} |
1068 |
|
|
1069 |
|
// XXX WIP |
1070 |
|
protected function get_service_data(string $service) { |
1071 |
|
$val_service = array(); |
1072 |
|
$inst_service = $this->f->get_inst__om_dbform(array( |
1073 |
|
"obj" => "service", |
1074 |
|
"idx" => $service, |
1075 |
|
)); |
1076 |
|
$val_service = $inst_service->get_json_data(); |
1077 |
|
return $val_service; |
1078 |
|
} |
1079 |
|
|
1080 |
|
protected function view_form_json($in_field = false) { |
1081 |
// |
// |
1082 |
if ($this->f->get_submitted_post_value('valid') === null) { |
if ($this->f->get_submitted_post_value('valid') === null |
1083 |
|
&& $this->getVal('state') !== self::STATUS_DRAFT) { |
1084 |
// Liste des valeurs à afficher |
// Liste des valeurs à afficher |
1085 |
$val = array(); |
$val = array(); |
1086 |
// |
// |
1091 |
$val_task['timestamp_log'] = json_decode($val_task['timestamp_log'], true); |
$val_task['timestamp_log'] = json_decode($val_task['timestamp_log'], true); |
1092 |
$val['task'] = $val_task; |
$val['task'] = $val_task; |
1093 |
// |
// |
1094 |
if ($this->getVal('type') === 'creation_DA') { |
if ($this->getVal('type') === 'creation_DA' |
1095 |
|
|| $this->getVal('type') === 'modification_DA') { |
1096 |
|
// |
1097 |
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id')); |
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id')); |
1098 |
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation'); |
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation'); |
1099 |
$val['dossier_autorisation_parcelle'] = $this->get_parcelles_data('dossier_autorisation', $val['dossier_autorisation']['dossier_autorisation']); |
$val['dossier_autorisation_parcelle'] = $this->get_parcelles_data('dossier_autorisation', $val['dossier_autorisation']['dossier_autorisation']); |
1100 |
$val_external_uid = array(); |
$val_external_uid = array(); |
1101 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier_autorisation']['dossier_autorisation'], 'dossier_autorisation'); |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier_autorisation']['dossier_autorisation'], 'dossier_autorisation'); |
1102 |
$val['external_uid'] = $val_external_uid; |
$val['external_uids'] = $val_external_uid; |
1103 |
} |
} |
1104 |
// |
// |
1105 |
if ($this->getVal('type') === 'creation_DI' |
if ($this->getVal('type') === 'creation_DI' |
1115 |
$val_external_uid = array(); |
$val_external_uid = array(); |
1116 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1117 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1118 |
$val['external_uid'] = $val_external_uid; |
$val['external_uids'] = $val_external_uid; |
1119 |
} |
} |
1120 |
// |
// |
1121 |
if ($this->getVal('type') === 'qualification_DI') { |
if ($this->getVal('type') === 'qualification_DI') { |
1122 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1123 |
$val_external_uid = array(); |
$val_external_uid = array(); |
1124 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1125 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1126 |
$val['external_uid'] = $val_external_uid; |
$val['external_uids'] = $val_external_uid; |
1127 |
} |
} |
1128 |
// |
// |
1129 |
if ($this->getVal('type') === 'ajout_piece') { |
if ($this->getVal('type') === 'ajout_piece') { |
1133 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1134 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1135 |
$val_external_uid['document_numerise'] = $this->get_external_uid($val['document_numerise']['document_numerise'], 'document_numerise'); |
$val_external_uid['document_numerise'] = $this->get_external_uid($val['document_numerise']['document_numerise'], 'document_numerise'); |
1136 |
$val['external_uid'] = $val_external_uid; |
$val['external_uids'] = $val_external_uid; |
1137 |
} |
} |
1138 |
// |
// |
1139 |
if ($this->getVal('type') === 'decision_DI') { |
if ($this->getVal('type') === 'decision_DI') { |
1140 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1141 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier']); |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1142 |
$val_external_uid = array(); |
$val_external_uid = array(); |
1143 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1144 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1145 |
$val['external_uid'] = $val_external_uid; |
$val['external_uids'] = $val_external_uid; |
1146 |
} |
} |
1147 |
// |
// |
1148 |
if ($this->getVal('type') === 'incompletude_DI') { |
if ($this->getVal('type') === 'incompletude_DI') { |
1149 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1150 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'incompletude'); |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1151 |
$val_external_uid = array(); |
$val_external_uid = array(); |
1152 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1153 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1154 |
$val['external_uid'] = $val_external_uid; |
$val['external_uids'] = $val_external_uid; |
1155 |
} |
} |
1156 |
// |
// |
1157 |
if ($this->getVal('type') === 'completude_DI') { |
if ($this->getVal('type') === 'completude_DI') { |
1158 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1159 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'completude'); |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1160 |
|
$val_external_uid = array(); |
1161 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1162 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1163 |
|
$val['external_uids'] = $val_external_uid; |
1164 |
|
} |
1165 |
|
// |
1166 |
|
if ($this->getVal('type') === 'pec_metier_consultation') { |
1167 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1168 |
|
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
1169 |
$val_external_uid = array(); |
$val_external_uid = array(); |
1170 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1171 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1172 |
$val['external_uid'] = $val_external_uid; |
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
1173 |
|
$val['external_uids'] = $val_external_uid; |
1174 |
|
} |
1175 |
|
// |
1176 |
|
if ($this->getVal('type') === 'avis_consultation') { |
1177 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1178 |
|
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
1179 |
|
$val['avis_decision'] = $this->get_avis_decision_data($this->getVal('dossier')); |
1180 |
|
if (isset($val['instruction']['signataire_arrete']) === true) { |
1181 |
|
$val['signataire_arrete'] = $this->get_signataire_arrete_data($val['instruction']['signataire_arrete']); |
1182 |
|
} |
1183 |
|
$val_external_uid = array(); |
1184 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1185 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1186 |
|
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
1187 |
|
$val['external_uids'] = $val_external_uid; |
1188 |
|
} |
1189 |
|
// XXX WIP |
1190 |
|
if ($this->getVal('type') === 'creation_consultation') { |
1191 |
|
// |
1192 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1193 |
|
$val['consultation'] = $this->get_consultation_data($this->getVal('object_id')); |
1194 |
|
$val['service'] = $this->get_service_data($val['consultation']['service']); |
1195 |
|
$val_external_uid = array(); |
1196 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1197 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1198 |
|
$val['external_uids'] = $val_external_uid; |
1199 |
} |
} |
1200 |
|
|
1201 |
if ($in_field === true) { |
if ($in_field === true) { |
1202 |
return json_encode($val, JSON_PRETTY_PRINT ,JSON_UNESCAPED_SLASHES); |
return json_encode($val, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
1203 |
} else { |
} else { |
1204 |
// Liste des valeurs affichée en JSON |
// Liste des valeurs affichée en JSON |
1205 |
printf(json_encode($val, JSON_UNESCAPED_SLASHES)); |
printf(json_encode($val, JSON_UNESCAPED_SLASHES)); |
1207 |
} |
} |
1208 |
} |
} |
1209 |
|
|
1210 |
protected function get_lien_objet_by_type($type) { |
function post_update_task() { |
1211 |
// |
// Mise à jour des valeurs |
1212 |
$objet = ''; |
|
1213 |
if ($type === 'creation_DA') { |
// Modification de l'état de la tâche |
1214 |
$objet = 'dossier_autorisation'; |
if ($this->f->get_submitted_post_value('state') !== null) { |
1215 |
} |
$params = array( |
1216 |
if ($type === 'creation_DI' |
'val' => array( |
1217 |
|| $type === 'depot_DI' |
'state' => $this->f->get_submitted_post_value('state') |
1218 |
|| $type === 'modification_DI' |
), |
1219 |
|| $type === 'qualification_DI' |
); |
1220 |
|| $type === 'decision_DI' |
$update = $this->update_task($params); |
1221 |
|| $type === 'incompletude_DI' |
$message_class = "valid"; |
1222 |
|| $type === 'completude_DI') { |
$message = $this->msg; |
1223 |
|
if ($update === false) { |
1224 |
|
$this->addToLog($this->msg, DEBUG_MODE); |
1225 |
|
$message_class = "error"; |
1226 |
|
$message = sprintf( |
1227 |
|
'%s %s', |
1228 |
|
__('Impossible de mettre à jour la tâche.'), |
1229 |
|
__('Veuillez contacter votre administrateur.') |
1230 |
|
); |
1231 |
|
} |
1232 |
|
$this->f->displayMessage($message_class, $message); |
1233 |
|
} |
1234 |
|
|
1235 |
|
// Sauvegarde de l'uid externe retourné |
1236 |
|
if ($this->f->get_submitted_post_value('external_uid') !== null) { |
1237 |
// |
// |
1238 |
$objet = 'dossier'; |
$objects = $this->get_objects_by_task_type($this->getVal('type'), $this->getVal('stream')); |
1239 |
|
foreach ($objects as $object) { |
1240 |
|
$inst_lien = $this->f->get_inst__om_dbform(array( |
1241 |
|
"obj" => "lien_id_interne_uid_externe", |
1242 |
|
"idx" => ']', |
1243 |
|
)); |
1244 |
|
if ($inst_lien->is_exists($object, $this->getVal('object_id'), $this->f->get_submitted_post_value('external_uid'), $this->getVal('dossier')) === false) { |
1245 |
|
$valF = array( |
1246 |
|
'lien_id_interne_uid_externe' => '', |
1247 |
|
'object' => $object, |
1248 |
|
'object_id' => $this->getVal('object_id'), |
1249 |
|
'external_uid' => $this->f->get_submitted_post_value('external_uid'), |
1250 |
|
'dossier' => $this->getVal('dossier'), |
1251 |
|
); |
1252 |
|
$add = $inst_lien->ajouter($valF); |
1253 |
|
$message_class = "valid"; |
1254 |
|
$message = $inst_lien->msg; |
1255 |
|
if ($add === false) { |
1256 |
|
$this->addToLog($inst_lien->msg, DEBUG_MODE); |
1257 |
|
$message_class = "error"; |
1258 |
|
$message = sprintf( |
1259 |
|
'%s %s', |
1260 |
|
__("Impossible de mettre à jour le lien entre l'identifiant interne et l'identifiant de l'application externe."), |
1261 |
|
__('Veuillez contacter votre administrateur.') |
1262 |
|
); |
1263 |
|
} |
1264 |
|
$this->f->displayMessage($message_class, $message); |
1265 |
|
} |
1266 |
|
} |
1267 |
} |
} |
1268 |
if ($type === 'ajout_piece') { |
} |
1269 |
$objet = 'document_numerise'; |
|
1270 |
|
function post_add_task() { |
1271 |
|
// TODO Tester de remplacer la ligne de json_payload par un $_POST |
1272 |
|
$result = $this->add_task(array( |
1273 |
|
'val' => array( |
1274 |
|
'stream' => 'input', |
1275 |
|
'json_payload' => html_entity_decode($this->f->get_submitted_post_value('json_payload')), |
1276 |
|
'type' => $this->f->get_submitted_post_value('type'), |
1277 |
|
) |
1278 |
|
)); |
1279 |
|
$message = sprintf( |
1280 |
|
__("Tâche %s ajoutée avec succès"), |
1281 |
|
$this->getVal($this->clePrimaire)). |
1282 |
|
'<br/><br/>'. |
1283 |
|
$this->msg; |
1284 |
|
$message_class = "valid"; |
1285 |
|
if ($result === false){ |
1286 |
|
$this->addToLog($this->msg, DEBUG_MODE); |
1287 |
|
$message_class = "error"; |
1288 |
|
$message = sprintf( |
1289 |
|
'%s %s', |
1290 |
|
__('Impossible d\'ajouter la tâche.'), |
1291 |
|
__('Veuillez contacter votre administrateur.') |
1292 |
|
); |
1293 |
} |
} |
1294 |
return $objet; |
$this->f->displayMessage($message_class, $message); |
1295 |
} |
} |
1296 |
|
|
1297 |
function setLayout(&$form, $maj) { |
function setLayout(&$form, $maj) { |
1298 |
$form->setBloc('json_payload', 'D', '', 'col_6'); |
|
1299 |
$form->setFieldset('json_payload', 'DF', _("json_payload"), "collapsible, startClosed"); |
// Récupération du mode de l'action |
1300 |
$form->setBloc('json_payload', 'F'); |
$crud = $this->get_action_crud($maj); |
1301 |
|
|
1302 |
|
// MODE different de CREER |
1303 |
|
if ($maj != 0 || $crud != 'create') { |
1304 |
|
$form->setBloc('json_payload', 'D', '', 'col_6'); |
1305 |
|
$form->setFieldset('json_payload', 'DF', __("json_payload"), "collapsible, startClosed"); |
1306 |
|
$form->setBloc('json_payload', 'F'); |
1307 |
|
} |
1308 |
$form->setBloc('timestamp_log', 'DF', '', 'col_9'); |
$form->setBloc('timestamp_log', 'DF', '', 'col_9'); |
1309 |
} |
} |
1310 |
|
|
1311 |
|
/** |
1312 |
|
* [get_objects_by_task_type description] |
1313 |
|
* @param [type] $type [description] |
1314 |
|
* @return [type] [description] |
1315 |
|
*/ |
1316 |
|
function get_objects_by_task_type($type, $stream = 'all') { |
1317 |
|
$objects = array(); |
1318 |
|
if (in_array($type, array('creation_DA', 'modification_DA', )) === true) { |
1319 |
|
$objects = array('dossier_autorisation', ); |
1320 |
|
} |
1321 |
|
if (in_array($type, array('creation_DI', 'depot_DI', 'notification_DI', 'qualification_DI', )) === true) { |
1322 |
|
$objects = array('dossier', ); |
1323 |
|
} |
1324 |
|
if (in_array($type, array('create_DI_for_consultation', )) === true) { |
1325 |
|
$objects = array('dossier', 'dossier_consultation', ); |
1326 |
|
} |
1327 |
|
if (in_array($type, array('create_DI', )) === true |
1328 |
|
&& $stream === 'input') { |
1329 |
|
$objects = array('dossier', 'dossier_autorisation', ); |
1330 |
|
} |
1331 |
|
if (in_array($type, array('decision_DI', 'incompletude_DI', 'completude_DI', )) === true) { |
1332 |
|
$objects = array('instruction', ); |
1333 |
|
} |
1334 |
|
if (in_array($type, array('pec_metier_consultation', )) === true |
1335 |
|
&& $stream === 'output') { |
1336 |
|
$objects = array('pec_dossier_consultation', ); |
1337 |
|
} |
1338 |
|
if (in_array($type, array('avis_consultation', )) === true |
1339 |
|
&& $stream === 'output') { |
1340 |
|
$objects = array('avis_dossier_consultation', ); |
1341 |
|
} |
1342 |
|
if (in_array($type, array('ajout_piece', 'add_piece', )) === true) { |
1343 |
|
$objects = array('piece', ); |
1344 |
|
} |
1345 |
|
if (in_array($type, array('creation_consultation', )) === true) { |
1346 |
|
$objects = array('consultation', ); |
1347 |
|
} |
1348 |
|
if (in_array($type, array('pec_metier_consultation', )) === true |
1349 |
|
&& $stream === 'input') { |
1350 |
|
$objects = array('pec_metier_consultation', ); |
1351 |
|
} |
1352 |
|
if (in_array($type, array('avis_consultation', )) === true |
1353 |
|
&& $stream === 'input') { |
1354 |
|
$objects = array('avis_consultation', ); |
1355 |
|
} |
1356 |
|
return $objects; |
1357 |
|
} |
1358 |
|
|
1359 |
} |
} |