13 |
const STATUS_ERROR = 'error'; |
const STATUS_ERROR = 'error'; |
14 |
const STATUS_DEBUG = 'debug'; |
const STATUS_DEBUG = 'debug'; |
15 |
const STATUS_ARCHIVED = 'archived'; |
const STATUS_ARCHIVED = 'archived'; |
16 |
|
const STATUS_CANCELED = 'canceled'; |
17 |
|
|
18 |
/** |
/** |
19 |
* Liste des types de tâche concernant les services instructeurs |
* Liste des types de tâche concernant les services instructeurs |
32 |
'creation_consultation', |
'creation_consultation', |
33 |
'modification_DA', |
'modification_DA', |
34 |
'create_DI', |
'create_DI', |
35 |
|
'envoi_CL', |
36 |
|
'notification_recepisse', |
37 |
|
'notification_instruction', |
38 |
|
'notification_decision', |
39 |
|
'notification_service_consulte', |
40 |
|
'notification_tiers_consulte', |
41 |
|
'notification_depot_demat', |
42 |
|
'notification_commune', |
43 |
|
'notification_signataire', |
44 |
|
'lettre_incompletude', |
45 |
|
'lettre_majoration' |
46 |
); |
); |
47 |
|
|
48 |
/** |
/** |
52 |
'create_DI_for_consultation', |
'create_DI_for_consultation', |
53 |
'avis_consultation', |
'avis_consultation', |
54 |
'pec_metier_consultation', |
'pec_metier_consultation', |
55 |
|
'create_message', |
56 |
|
'notification_recepisse', |
57 |
|
'notification_instruction', |
58 |
|
'notification_decision', |
59 |
|
'notification_service_consulte', |
60 |
|
'notification_tiers_consulte', |
61 |
|
'notification_depot_demat', |
62 |
|
'prescription', |
63 |
); |
); |
64 |
|
|
65 |
/** |
/** |
66 |
|
* Liste des types de tâche pouvant avoir des documents associés |
67 |
|
*/ |
68 |
|
const TASK_WITH_DOCUMENT = array( |
69 |
|
'add_piece', |
70 |
|
'avis_consultation', |
71 |
|
'pec_metier_consultation' |
72 |
|
); |
73 |
|
|
74 |
|
/** |
75 |
|
* Préfixe pour identifier les codes de suivi |
76 |
|
* @var string |
77 |
|
*/ |
78 |
|
const CS_PREFIX = 'code-suivi://'; |
79 |
|
|
80 |
|
/** |
81 |
|
* Catégorie de la tâche |
82 |
|
*/ |
83 |
|
var $category = PLATAU; |
84 |
|
|
85 |
|
/** |
86 |
* Définition des actions disponibles sur la classe. |
* Définition des actions disponibles sur la classe. |
87 |
* |
* |
88 |
* @return void |
* @return void |
160 |
if (! isset($val['json_payload']) || empty($val['json_payload'])) { |
if (! isset($val['json_payload']) || empty($val['json_payload'])) { |
161 |
|
|
162 |
// récupère l'objet existant |
// récupère l'objet existant |
163 |
$existing = $this->f->findObjectById(get_class($this), $id); |
$existing = $this->f->findObjectById('task', $id); |
164 |
if (! empty($existing)) { |
if (! empty($existing)) { |
165 |
|
|
166 |
// récupère la payload de l'objet |
// récupère la payload de l'objet |
171 |
} |
} |
172 |
} |
} |
173 |
} |
} |
174 |
|
|
175 |
|
if (array_key_exists('category', $val) === false |
176 |
|
|| $this->valF['category'] === '' |
177 |
|
|| $this->valF['category'] === null) { |
178 |
|
// |
179 |
|
$this->valF['category'] = $this->category; |
180 |
|
} |
181 |
|
|
182 |
|
// Si last_modification_time est vide, la valeur est remplacée par NULL |
183 |
|
// pour eviter d'avoir une erreur de base de données car le champ est au format time. |
184 |
|
if ($val['last_modification_time'] == "") { |
185 |
|
$this->valF['last_modification_time'] = NULL; |
186 |
|
} else { |
187 |
|
$this->valF['last_modification_time'] = $val['last_modification_time']; |
188 |
|
} |
189 |
|
|
190 |
|
// Si creation_time est vide, la valeur est remplacée par NULL |
191 |
|
// pour eviter d'avoir une erreur de base de données car le champ est au format time. |
192 |
|
if ($val['creation_time'] == "") { |
193 |
|
$this->valF['creation_time'] = NULL; |
194 |
|
} else { |
195 |
|
$this->valF['creation_time'] = $val['creation_time']; |
196 |
|
} |
197 |
} |
} |
198 |
|
|
199 |
/** |
/** |
208 |
"object_id", |
"object_id", |
209 |
"dossier", |
"dossier", |
210 |
"stream", |
"stream", |
211 |
|
"creation_date", |
212 |
|
"creation_time", |
213 |
|
"CONCAT_WS(' ', to_char(task.creation_date, 'DD/MM/YYYY'), task.creation_time) AS date_creation", |
214 |
|
'last_modification_date', |
215 |
|
'last_modification_time', |
216 |
|
"CONCAT_WS(' ', to_char(task.last_modification_date, 'DD/MM/YYYY'), task.last_modification_time) AS date_modification", |
217 |
|
"comment", |
218 |
"json_payload", |
"json_payload", |
219 |
"timestamp_log", |
"timestamp_log", |
220 |
|
"timestamp_log AS timestamp_log_hidden", |
221 |
|
"category", |
222 |
); |
); |
223 |
} |
} |
224 |
|
|
228 |
// Récupération du mode de l'action |
// Récupération du mode de l'action |
229 |
$crud = $this->get_action_crud($maj); |
$crud = $this->get_action_crud($maj); |
230 |
|
|
231 |
|
// ALL |
232 |
|
$form->setType("category", "hidden"); |
233 |
|
$form->setType("timestamp_log_hidden", "hidden"); |
234 |
|
|
235 |
// MODE CREER |
// MODE CREER |
236 |
if ($maj == 0 || $crud == 'create') { |
if ($maj == 0 || $crud == 'create') { |
237 |
|
$form->setType("type", "select"); |
238 |
$form->setType("state", "select"); |
$form->setType("state", "select"); |
239 |
$form->setType("stream", "select"); |
$form->setType("stream", "select"); |
240 |
$form->setType("json_payload", "textarea"); |
$form->setType("json_payload", "textarea"); |
241 |
} |
} |
242 |
// MDOE MODIFIER |
// MODE MODIFIER |
243 |
if ($maj == 1 || $crud == 'update') { |
if ($maj == 1 || $crud == 'update') { |
244 |
|
$form->setType("task", "hiddenstatic"); |
245 |
$form->setType("state", "select"); |
$form->setType("state", "select"); |
246 |
$form->setType("stream", "select"); |
$form->setType("stream", "hiddenstatic"); |
247 |
$form->setType("json_payload", "jsonprettyprint"); |
$form->setType("json_payload", "jsonprettyprint"); |
248 |
|
$form->setType("timestamp_log", "jsontotab"); |
249 |
|
$form->setType("type", "hiddenstatic"); |
250 |
|
$form->setType("creation_date", "hidden"); |
251 |
|
$form->setType("creation_time", "hidden"); |
252 |
|
$form->setType("object_id", "hiddenstatic"); |
253 |
|
$form->setType("dossier", "hiddenstatic"); |
254 |
|
$form->setType("date_creation", "hiddenstatic"); |
255 |
|
$form->setType("last_modification_date", "hidden"); |
256 |
|
$form->setType("last_modification_time", "hidden"); |
257 |
|
$form->setType("date_modification", "static"); |
258 |
} |
} |
259 |
// MODE CONSULTER |
// MODE CONSULTER |
260 |
if ($maj == 3 || $crud == 'read') { |
if ($maj == 3 || $crud == 'read') { |
261 |
|
$form->setType("state", "selecthiddenstatic"); |
262 |
|
$form->setType("stream", "selecthiddenstatic"); |
263 |
$form->setType('dossier', 'link'); |
$form->setType('dossier', 'link'); |
264 |
$form->setType('json_payload', 'jsonprettyprint'); |
$form->setType('json_payload', 'jsonprettyprint'); |
265 |
|
$form->setType("type", "selecthiddenstatic"); |
266 |
|
$form->setType("creation_date", "hidden"); |
267 |
|
$form->setType("creation_time", "hidden"); |
268 |
|
$form->setType("date_creation", "static"); |
269 |
|
$form->setType("last_modification_date", "hidden"); |
270 |
|
$form->setType("last_modification_time", "hidden"); |
271 |
|
$form->setType("date_modification", "static"); |
272 |
|
$form->setType("timestamp_log", "jsontotab"); |
273 |
} |
} |
|
|
|
274 |
} |
} |
275 |
|
|
276 |
|
function stateTranslation ($currentState) { |
277 |
|
switch ($currentState){ |
278 |
|
case "draft": |
279 |
|
return __('brouillon'); |
280 |
|
break; |
281 |
|
case "new": |
282 |
|
return __('à traiter'); |
283 |
|
break; |
284 |
|
case "pending": |
285 |
|
return __('en cours'); |
286 |
|
break; |
287 |
|
case "done": |
288 |
|
return __('terminé'); |
289 |
|
break; |
290 |
|
case "archived": |
291 |
|
return __('archivé'); |
292 |
|
break; |
293 |
|
case "error": |
294 |
|
return __('erreur'); |
295 |
|
break; |
296 |
|
case "debug": |
297 |
|
return __('debug'); |
298 |
|
break; |
299 |
|
case "canceled": |
300 |
|
return __('annulé'); |
301 |
|
break; |
302 |
|
} |
303 |
|
} |
304 |
/** |
/** |
305 |
* |
* |
306 |
*/ |
*/ |
307 |
function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) { |
function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) { |
308 |
if($maj < 2) { |
if($maj <= 3) { |
|
|
|
309 |
$contenu = array(); |
$contenu = array(); |
310 |
foreach(array('DRAFT', 'NEW', 'PENDING', 'DONE', 'ERROR', 'DEBUG') as $key) { |
foreach(array('DRAFT', 'NEW', 'PENDING', 'DONE', 'ERROR', 'DEBUG', 'ARCHIVED', 'CANCELED') as $key) { |
311 |
$const_name = 'STATUS_'.$key; |
$const_name = 'STATUS_'.$key; |
312 |
$const_value = constant("self::$const_name"); |
$const_value = constant("self::$const_name"); |
313 |
$contenu[0][] = $const_value; |
$contenu[0][] = $const_value; |
314 |
$contenu[1][] = __($const_value); |
|
315 |
|
|
316 |
|
$contenu[1][] = $this->stateTranslation($const_value); |
317 |
|
|
318 |
} |
} |
319 |
|
|
320 |
$form->setSelect("state", $contenu); |
$form->setSelect("state", $contenu); |
321 |
|
|
322 |
$contenu_stream =array(); |
$contenu_stream =array(); |
323 |
$contenu_stream[0][0]="input"; |
$contenu_stream[0][0]="input"; |
324 |
$contenu_stream[1][0]=_('input'); |
$contenu_stream[1][0]=__('input'); |
325 |
$contenu_stream[0][1]="output"; |
$contenu_stream[0][1]="output"; |
326 |
$contenu_stream[1][1]=_('output'); |
$contenu_stream[1][1]=__('output'); |
327 |
$form->setSelect("stream", $contenu_stream); |
$form->setSelect("stream", $contenu_stream); |
328 |
|
|
329 |
|
$tab_type = array_unique(array_merge(self::TASK_TYPE_SI, self::TASK_TYPE_SC)); |
330 |
|
|
331 |
|
foreach ($tab_type as $type) { |
332 |
|
|
333 |
|
$contenu_type[0][] = $type; |
334 |
|
|
335 |
|
switch ($type) { |
336 |
|
case "creation_DA": |
337 |
|
$value_type = __('Création DA'); |
338 |
|
break; |
339 |
|
case "create_DI": |
340 |
|
$value_type = __('Création demande'); |
341 |
|
break; |
342 |
|
case "creation_DI": |
343 |
|
$value_type = __('Création DI'); |
344 |
|
break; |
345 |
|
case "modification_DA": |
346 |
|
$value_type = __('Modification DA'); |
347 |
|
break; |
348 |
|
case "modification_DI": |
349 |
|
$value_type = __('Modification DI'); |
350 |
|
break; |
351 |
|
case "ajout_piece": |
352 |
|
$value_type = __('Ajout pièce (sortant)'); |
353 |
|
break; |
354 |
|
case "add_piece": |
355 |
|
$value_type = __('Ajout pièce (entrant)'); |
356 |
|
break; |
357 |
|
case "depot_DI": |
358 |
|
$value_type = __('Dépôt DI'); |
359 |
|
break; |
360 |
|
case "qualification_DI": |
361 |
|
$value_type = __('Qualification DI'); |
362 |
|
break; |
363 |
|
case "creation_consultation": |
364 |
|
$value_type = __('Création consultation'); |
365 |
|
break; |
366 |
|
case "decision_DI": |
367 |
|
$value_type = __('Décision DI'); |
368 |
|
break; |
369 |
|
case "envoi_CL": |
370 |
|
$value_type = __('Envoi contrôle de légalité'); |
371 |
|
break; |
372 |
|
case "pec_metier_consultation": |
373 |
|
$value_type = __('PeC consultation'); |
374 |
|
break; |
375 |
|
case "avis_consultation": |
376 |
|
$value_type = __('Avis'); |
377 |
|
break; |
378 |
|
case "prescription": |
379 |
|
$value_type = __('Prescription'); |
380 |
|
break; |
381 |
|
case "create_DI_for_consultation": |
382 |
|
$value_type = __('Création DI pour consultation'); |
383 |
|
break; |
384 |
|
case "create_message": |
385 |
|
$value_type = __('Message'); |
386 |
|
break; |
387 |
|
case "notification_recepisse": |
388 |
|
$value_type = __('Notification récépissé'); |
389 |
|
break; |
390 |
|
case "notification_instruction": |
391 |
|
$value_type = __('Notification instruction'); |
392 |
|
break; |
393 |
|
case "notification_decision": |
394 |
|
$value_type = __('Notification décision'); |
395 |
|
break; |
396 |
|
case "notification_service_consulte": |
397 |
|
$value_type = __('Notification service consulté'); |
398 |
|
break; |
399 |
|
case "notification_tiers_consulte": |
400 |
|
$value_type = __('Notification tiers consulté'); |
401 |
|
break; |
402 |
|
case "notification_signataire": |
403 |
|
$value_type = __('Notification signataire'); |
404 |
|
break; |
405 |
|
case "completude_DI": |
406 |
|
$value_type = __('complétude DI'); |
407 |
|
break; |
408 |
|
case "incompletude_DI": |
409 |
|
$value_type = __('incomplétude DI'); |
410 |
|
break; |
411 |
|
case "lettre_incompletude": |
412 |
|
$value_type = __('Lettre au pétitionnaire d\'incompletude'); |
413 |
|
break; |
414 |
|
case "lettre_majoration": |
415 |
|
$value_type = __('Lettre au pétitionnaire de majoration'); |
416 |
|
break; |
417 |
|
} |
418 |
|
|
419 |
|
$contenu_type[1][] = $value_type; |
420 |
|
} |
421 |
|
|
422 |
|
$form->setselect('type', $contenu_type); |
423 |
} |
} |
424 |
|
|
425 |
if ($maj == 3) { |
if ($maj == 3) { |
426 |
if ($this->getVal('stream') == 'output') { |
// Récupération du numéro du dossier si il n'est pas renseigné dans la tâche |
427 |
$inst_dossier = $this->f->get_inst__om_dbform(array( |
if ($form->val['dossier'] == '' || $form->val['dossier'] == null) { |
428 |
"obj" => "dossier", |
// Récupération de la payload de la taĉhe. |
429 |
"idx" => $form->val['dossier'], |
// Si la tâche est une tâche input la payload est associée à la tâche. |
430 |
)); |
// Si la tâche est une tâche en output la payload est "calculé" à l'ouverture |
431 |
|
// du formulaire. |
432 |
|
if ($this->getVal('stream') == 'input') { |
433 |
|
$json_payload = json_decode($this->getVal('json_payload'), true); |
434 |
|
} else { |
435 |
|
$json_payload = json_decode($form->val['json_payload'], true); |
436 |
|
} |
437 |
|
// A partir de la payload de la tâche ont récupère les externals uid |
438 |
|
// Si un external uid de DI (dossier) existe ont le récupère et on stocke le numéro |
439 |
|
// pour l'afficher sur le formulaire. |
440 |
|
// Si l'external UID du DI n'existe pas on récupère celui du DA |
441 |
|
$external_uid = ''; |
442 |
|
if (array_key_exists('external_uids', $json_payload) |
443 |
|
&& array_key_exists('dossier', $json_payload['external_uids']) |
444 |
|
) { |
445 |
|
$external_uid = $json_payload['external_uids']['dossier']; |
446 |
|
} elseif (array_key_exists('external_uids', $json_payload) |
447 |
|
&& array_key_exists('demande', $json_payload['external_uids'])) { |
448 |
|
$external_uid = $json_payload['external_uids']['demande']; |
449 |
|
} |
450 |
|
// Recherche l'external uid dans la base de données pour récupèrer le numéro de |
451 |
|
// DI / DA correspondant. On stocke le numéro de dossier dans la propriété val |
452 |
|
// du formulaire pour pouvoir l'afficher |
453 |
|
if ($external_uid != '') { |
454 |
|
$qres = $this->f->get_one_result_from_db_query( |
455 |
|
sprintf( |
456 |
|
'SELECT |
457 |
|
lien_id_interne_uid_externe.dossier |
458 |
|
FROM |
459 |
|
%1$slien_id_interne_uid_externe |
460 |
|
WHERE |
461 |
|
lien_id_interne_uid_externe.external_uid = \'%2$s\'', |
462 |
|
DB_PREFIXE, |
463 |
|
$this->f->db->escapeSimple($external_uid) |
464 |
|
), |
465 |
|
array( |
466 |
|
"origin" => __METHOD__, |
467 |
|
) |
468 |
|
); |
469 |
|
if (! empty($qres["result"])) { |
470 |
|
$form->val['dossier'] = $qres["result"]; |
471 |
|
} |
472 |
|
} |
473 |
|
} |
474 |
|
|
475 |
if($form->val['type'] == "creation_DA" |
// Vérifie si le numéro de dossier associé à la tâche existe dans la base. |
476 |
|| $form->val['type'] == "modification_DA"){ |
// Si c'est le cas ce numéro sera lié au dossier (DI ou DA) correspondant |
477 |
// |
// TODO : vérifier la liste des tâches lié à des DA |
478 |
|
$obj_link = ''; |
479 |
|
if ($form->val['type'] == "creation_DA" || $form->val['type'] == "modification_DA") { |
480 |
|
// Vérification que le numéro de DA affiché dans le formulaire existe |
481 |
|
$qres = $this->f->get_one_result_from_db_query( |
482 |
|
sprintf( |
483 |
|
'SELECT |
484 |
|
dossier_autorisation.dossier_autorisation |
485 |
|
FROM |
486 |
|
%1$sdossier_autorisation |
487 |
|
WHERE |
488 |
|
dossier_autorisation.dossier_autorisation = \'%2$s\'', |
489 |
|
DB_PREFIXE, |
490 |
|
$this->f->db->escapeSimple($form->val['dossier']) |
491 |
|
), |
492 |
|
array( |
493 |
|
"origin" => __METHOD__, |
494 |
|
) |
495 |
|
); |
496 |
|
// Si on a un résultat c'est que le dossier existe, il faut afficher le lien |
497 |
|
if (! empty($qres["result"])) { |
498 |
$obj_link = 'dossier_autorisation'; |
$obj_link = 'dossier_autorisation'; |
499 |
} else { |
} |
500 |
|
} else { |
501 |
|
// Vérification que le numéro de DI affiché dans le formulaire existe |
502 |
|
$qres = $this->f->get_one_result_from_db_query( |
503 |
|
sprintf( |
504 |
|
'SELECT |
505 |
|
dossier.dossier |
506 |
|
FROM |
507 |
|
%1$sdossier |
508 |
|
WHERE |
509 |
|
dossier.dossier = \'%2$s\'', |
510 |
|
DB_PREFIXE, |
511 |
|
$this->f->db->escapeSimple($form->val['dossier']) |
512 |
|
), |
513 |
|
array( |
514 |
|
"origin" => __METHOD__, |
515 |
|
) |
516 |
|
); |
517 |
|
// Si on a un résultat c'est que le dossier existe, il faut afficher le lien |
518 |
|
if (! empty($qres["result"])) { |
519 |
$obj_link = 'dossier_instruction'; |
$obj_link = 'dossier_instruction'; |
520 |
} |
} |
|
|
|
|
$params = array(); |
|
|
$params['obj'] = $obj_link; |
|
|
$params['libelle'] = $inst_dossier->getVal('dossier'); |
|
|
$params['title'] = "Consulter le dossier"; |
|
|
$params['idx'] = $form->val['dossier']; |
|
|
$form->setSelect("dossier", $params); |
|
521 |
} |
} |
522 |
|
// Pour afficher le lien vers un dossier ont utilise un champ de type "link". |
523 |
|
// Pour paramétrer ce champs on a besoin de savoir : |
524 |
|
// - quel objet est visé par le lien |
525 |
|
// - le label (libellé) du lien |
526 |
|
// - l'identifiant de l'objet qui sera utilisé dans le lien |
527 |
|
// - le titre associé au lien |
528 |
|
// Pour cela on remplit le champs comme un select et les valeurs du select |
529 |
|
// contiennent les informations nécessaire à l'affichage du champs. |
530 |
|
$params = array( |
531 |
|
'obj' => $obj_link, |
532 |
|
'libelle' => $form->val['dossier'], |
533 |
|
'title' => "Consulter le dossier", |
534 |
|
'idx' => $form->val['dossier'] |
535 |
|
); |
536 |
|
$form->setSelect("dossier", $params); |
537 |
} |
} |
538 |
} |
} |
539 |
|
|
545 |
function setVal(&$form, $maj, $validation, &$dnu1 = null, $dnu2 = null) { |
function setVal(&$form, $maj, $validation, &$dnu1 = null, $dnu2 = null) { |
546 |
// parent::setVal($form, $maj, $validation); |
// parent::setVal($form, $maj, $validation); |
547 |
// |
// |
548 |
if ($this->getVal('stream') == "output") { |
if ($this->getVal('stream') == "output" |
549 |
|
&& ($this->getVal('state') !== self::STATUS_DONE |
550 |
|
|| $this->getVal('json_payload') === "{}")) { |
551 |
|
// |
552 |
$form->setVal('json_payload', $this->view_form_json(true)); |
$form->setVal('json_payload', $this->view_form_json(true)); |
553 |
} else { |
} else { |
554 |
$form->setVal('json_payload', htmlentities($this->getVal('json_payload'))); |
$form->setVal('json_payload', json_encode(json_decode($this->getVal('json_payload'), true), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); |
555 |
|
} |
556 |
|
// Gestion du contenu de l'historique |
557 |
|
if ($this->getVal('timestamp_log') !== '' |
558 |
|
&& $this->getVal('timestamp_log') !== null) { |
559 |
|
// |
560 |
|
$form->setVal('timestamp_log', $this->getVal('timestamp_log')); |
561 |
} |
} |
562 |
} |
} |
563 |
|
|
567 |
// Récupération du mode de l'action |
// Récupération du mode de l'action |
568 |
$crud = $this->get_action_crud($maj); |
$crud = $this->get_action_crud($maj); |
569 |
|
|
570 |
|
$form->setLib('date_creation', __("Date de création")); |
571 |
|
$form->setLib('date_modification', __("Date de dernière modification")); |
572 |
|
$form->setLib('comment', __("commentaire")); |
573 |
|
|
574 |
// MODE different de CREER |
// MODE different de CREER |
575 |
if ($maj != 0 || $crud != 'create') { |
if ($maj != 0 || $crud != 'create') { |
576 |
$form->setLib('json_payload', ''); |
$form->setLib('json_payload', ''); |
577 |
|
$form->setLib("task", __("identifiant")); |
578 |
|
$form->setLib("Task_portal", __("task_portal")); |
579 |
|
$form->setLib("type", __("type")); |
580 |
|
$form->setLib("object_id", __("Réf. interne")); |
581 |
|
$form->setLib("stream", __("flux")); |
582 |
|
$form->setLib("timestamp_log", __("Historique")); |
583 |
} |
} |
584 |
} |
} |
585 |
|
|
639 |
$this->valF['stream'] == 'input')) { |
$this->valF['stream'] == 'input')) { |
640 |
|
|
641 |
// décode la payload JSON |
// décode la payload JSON |
642 |
|
// TODO : COMMENTER |
643 |
$json_payload = json_decode($this->valF['json_payload'], true); |
$json_payload = json_decode($this->valF['json_payload'], true); |
644 |
|
|
645 |
// défini une liste de chemin de clés requises |
// défini une liste de chemin de clés requises |
646 |
$paths = array( |
$paths = array(); |
647 |
'external_uids/dossier' |
if ($this->valF['category'] === PLATAU) { |
648 |
); |
$paths = array( |
649 |
|
'external_uids/dossier' |
650 |
|
); |
651 |
|
} |
652 |
|
|
653 |
// tâche de type création de DI/DA |
// tâche de type création de DI/DA |
654 |
if (isset($this->valF['type']) !== false && $this->valF['type'] == 'create_DI_for_consultation') { |
if (isset($this->valF['type']) !== false && $this->valF['type'] == 'create_DI_for_consultation') { |
718 |
* [task_exists description] |
* [task_exists description] |
719 |
* @param string $type [description] |
* @param string $type [description] |
720 |
* @param string $object_id [description] |
* @param string $object_id [description] |
721 |
|
* @param bool $is_not_done [description] |
722 |
* @return [type] [description] |
* @return [type] [description] |
723 |
*/ |
*/ |
724 |
public function task_exists(string $type, string $object_id) { |
public function task_exists(string $type, string $object_id, string $dossier = null, bool $is_not_done = true) { |
725 |
|
$qres = $this->f->get_one_result_from_db_query( |
726 |
|
sprintf( |
727 |
|
'SELECT |
728 |
|
task |
729 |
|
FROM |
730 |
|
%1$stask |
731 |
|
WHERE |
732 |
|
%2$s |
733 |
|
type = \'%3$s\' |
734 |
|
AND ( |
735 |
|
object_id = \'%4$s\' |
736 |
|
%5$s |
737 |
|
) |
738 |
|
AND state != \'%6$s\'', |
739 |
|
DB_PREFIXE, |
740 |
|
$is_not_done == true ? 'state != \''.self::STATUS_DONE.'\' AND' : '', |
741 |
|
$type, |
742 |
|
$object_id, |
743 |
|
$dossier !== null ? sprintf('OR dossier = \'%s\'', $dossier) : '', |
744 |
|
self::STATUS_CANCELED |
745 |
|
), |
746 |
|
array( |
747 |
|
"origin" => __METHOD__, |
748 |
|
) |
749 |
|
); |
750 |
|
if ($qres["result"] !== null && $qres["result"] !== "") { |
751 |
|
return $qres["result"]; |
752 |
|
} |
753 |
|
return false; |
754 |
|
} |
755 |
|
|
756 |
|
/** |
757 |
|
* Permet la recherche multi-critères des tasks. |
758 |
|
* |
759 |
|
* @param array $search_values Chaque entrée du tableau est une ligne dans le WHERE |
760 |
|
* @return mixed Retourne le résultat de la requête ou false |
761 |
|
*/ |
762 |
|
public function task_exists_multi_search(array $search_values) { |
763 |
$query = sprintf(' |
$query = sprintf(' |
764 |
SELECT task |
SELECT * |
765 |
FROM %1$stask |
FROM %1$stask |
766 |
WHERE state != \'%2$s\' |
%2$s |
767 |
AND type = \'%3$s\' |
%3$s |
768 |
AND object_id = \'%4$s\' |
ORDER BY task ASC |
769 |
', |
', |
770 |
DB_PREFIXE, |
DB_PREFIXE, |
771 |
self::STATUS_DONE, |
empty($search_values) === false ? ' WHERE ' : '', |
772 |
$type, |
implode(' AND ', $search_values) |
773 |
$object_id |
); |
774 |
|
$res = $this->f->get_all_results_from_db_query( |
775 |
|
$query, |
776 |
|
array( |
777 |
|
"origin" => __METHOD__, |
778 |
|
) |
779 |
); |
); |
780 |
$res = $this->f->get_one_result_from_db_query($query); |
if (count($res['result']) > 0) { |
|
if ($res['result'] !== null && $res['result'] !== '') { |
|
781 |
return $res['result']; |
return $res['result']; |
782 |
} |
} |
783 |
return false; |
return false; |
808 |
$this->valF["dossier"] = $json_payload['dossier']['dossier']; |
$this->valF["dossier"] = $json_payload['dossier']['dossier']; |
809 |
} |
} |
810 |
} |
} |
811 |
|
|
812 |
|
// gestion d'une tache de type notification et de category mail |
813 |
|
if (isset($val['type']) |
814 |
|
&& (($val['type'] === 'notification_instruction' || $val['type'] === 'notification_decision') |
815 |
|
&& isset($val['category']) |
816 |
|
&& $val['category'] === 'mail') |
817 |
|
|| $val['type'] === 'notification_service_consulte' |
818 |
|
|| $val['type'] === 'notification_tiers_consulte' |
819 |
|
|| $val['type'] === 'notification_depot_demat' |
820 |
|
|| $val['type'] === 'notification_commune' |
821 |
|
|| $val['type'] === 'notification_signataire' |
822 |
|
) { |
823 |
|
// Récupère la payload de la tache |
824 |
|
$data = array(); |
825 |
|
$data['instruction_notification'] = $this->get_instruction_notification_data( |
826 |
|
$this->valF['category'], |
827 |
|
'with-id', |
828 |
|
array('with-id' => $this->valF['object_id']) |
829 |
|
); |
830 |
|
$data['dossier'] = $this->get_dossier_data($this->valF['dossier']); |
831 |
|
|
832 |
|
// Récupère l'instance de la notification |
833 |
|
$inst_notif = $this->f->get_inst__om_dbform(array( |
834 |
|
"obj" => "instruction_notification", |
835 |
|
"idx" => $val['object_id'], |
836 |
|
)); |
837 |
|
// Envoi le mail et met à jour le suivi |
838 |
|
$envoiMail = $inst_notif->send_mail_notification($data, $val['type']); |
839 |
|
// Passage de la tache à done si elle a réussi et à error |
840 |
|
// si l'envoi a échoué |
841 |
|
$this->valF['state'] = 'done'; |
842 |
|
if ($envoiMail === false) { |
843 |
|
$this->valF['state'] = 'error'; |
844 |
|
} |
845 |
|
} |
846 |
|
} |
847 |
|
|
848 |
|
/** |
849 |
|
* TRIGGER - triggermodifier. |
850 |
|
* |
851 |
|
* @param string $id |
852 |
|
* @param null &$dnu1 @deprecated Ne pas utiliser. |
853 |
|
* @param array $val Tableau des valeurs brutes. |
854 |
|
* @param null $dnu2 @deprecated Ne pas utiliser. |
855 |
|
* |
856 |
|
* @return boolean |
857 |
|
*/ |
858 |
|
function triggermodifier($id, &$dnu1 = null, $val = array(), $dnu2 = null) { |
859 |
|
parent::triggermodifier($id, $dnu1, $val, $dnu2); |
860 |
|
$this->addToLog(__METHOD__."(): start", EXTRA_VERBOSE_MODE); |
861 |
|
|
862 |
|
// Mise à jour des valeurs, notamment du timestamp_log en fonction de plusieurs critères |
863 |
|
$values = array( |
864 |
|
'state' => $this->valF['state'], |
865 |
|
'object_id' => $this->valF['object_id'], |
866 |
|
'comment' => $this->valF['comment'], |
867 |
|
); |
868 |
|
$new_values = $this->set_values_for_update($values); |
869 |
|
if ($new_values === false) { |
870 |
|
$this->addToLog(__METHOD__."(): erreur timestamp log", DEBUG_MODE); |
871 |
|
return false; |
872 |
|
} |
873 |
|
|
874 |
|
// Mise à jour des valeurs |
875 |
|
$this->valF['timestamp_log'] = $new_values['timestamp_log']; |
876 |
|
$this->valF['state'] = $new_values['state']; |
877 |
|
$this->valF['object_id'] = $new_values['object_id']; |
878 |
|
$this->valF['last_modification_date'] = date('Y-m-d'); |
879 |
|
$this->valF['last_modification_time'] = date('H:i:s'); |
880 |
|
if ($val['stream'] === 'output') { |
881 |
|
// Lorsque la task passe d'un état qui n'est pas "done" à l'état "done" |
882 |
|
if ($this->getVal("state") !== self::STATUS_DONE |
883 |
|
&& $this->valF['state'] === self::STATUS_DONE) { |
884 |
|
// |
885 |
|
$this->valF['json_payload'] = $this->view_form_json(true); |
886 |
|
} |
887 |
|
// Lorsque la task passe d'un état "done" à un état qui n'est pas "done" |
888 |
|
if ($this->getVal("state") === self::STATUS_DONE |
889 |
|
&& $this->valF['state'] !== self::STATUS_DONE) { |
890 |
|
// |
891 |
|
$this->valF['json_payload'] = "{}"; |
892 |
|
} |
893 |
|
} |
894 |
|
|
895 |
|
return true; |
896 |
|
} |
897 |
|
|
898 |
|
|
899 |
|
/** |
900 |
|
* Applique nouvelle valeur après traitement. |
901 |
|
* |
902 |
|
* @param array $params Tableau des valeurs en entrées |
903 |
|
* @return array Tableau des valeurs en sorties |
904 |
|
*/ |
905 |
|
public function set_values_for_update($params = array()) { |
906 |
|
|
907 |
|
// Récupération du timestamp_log existant |
908 |
|
$timestamp_log = $this->get_timestamp_log(); |
909 |
|
if ($timestamp_log === false) { |
910 |
|
return false; |
911 |
|
} |
912 |
|
|
913 |
|
// Vérification des object_id précédent en cas de tentative d'appliquer |
914 |
|
// l'état CANCELED sur la tâche |
915 |
|
if (isset($params['state']) === true |
916 |
|
&& $params['state'] === self::STATUS_CANCELED) { |
917 |
|
// Récupération du journal d'activité de la tâche sous forme de tableau |
918 |
|
// trié par ordre décroissant |
919 |
|
$log = $timestamp_log; |
920 |
|
krsort($log); |
921 |
|
// Pour chaque entrée dans le journal d'activité de la tâche : |
922 |
|
// - vérification de la présence de l'object_id précédent |
923 |
|
// - vérification que l'object_id précédent existe toujours dans la base de données |
924 |
|
// - l'object_id est mise à jour avec la valeur de l'object_id précédent |
925 |
|
// - le state n'est pas modifié |
926 |
|
// - sortie du traitement dès que le premier object_id précédent existant est trouvé |
927 |
|
// - si aucun object_id précédent existant n'est trouvé alors ni le state, ni l'object_id n'est modifiés |
928 |
|
foreach ($log as $key => $value) { |
929 |
|
// |
930 |
|
if (isset($value['prev_object_id']) === true |
931 |
|
&& $this->getVal('object_id') !== $value['prev_object_id']) { |
932 |
|
// Récupère la liste des tables potentielles pour un type de tâche |
933 |
|
$tables = $this->get_tables_by_task_type($this->getVal('type'), $this->getVal('stream')); |
934 |
|
foreach ($tables as $table) { |
935 |
|
// Vérifie s'il y a un ou aucun résultat |
936 |
|
$qres = $this->f->get_one_result_from_db_query( |
937 |
|
sprintf( |
938 |
|
'SELECT |
939 |
|
COUNT(%2$s) |
940 |
|
FROM |
941 |
|
%1$s%2$s |
942 |
|
WHERE |
943 |
|
%2$s::CHARACTER VARYING = \'%3$s\'', |
944 |
|
DB_PREFIXE, |
945 |
|
$table, |
946 |
|
$value['prev_object_id'] |
947 |
|
), |
948 |
|
array( |
949 |
|
"origin" => __METHOD__, |
950 |
|
"force_return" => true, |
951 |
|
) |
952 |
|
); |
953 |
|
if ($qres["code"] !== "OK") { |
954 |
|
return $this->end_treatment(__METHOD__, false); |
955 |
|
} |
956 |
|
// Affectation des valeurs et sortie de la boucle |
957 |
|
if ($qres["result"] == '1') { |
958 |
|
$params['object_id'] = $value['prev_object_id']; |
959 |
|
$params['state'] = $this->getVal('state'); |
960 |
|
break; |
961 |
|
} |
962 |
|
} |
963 |
|
// Sortie de la boucle si les valeurs sont affectées |
964 |
|
if ($params['object_id'] !== null |
965 |
|
&& $params['object_id'] === $value['prev_object_id']) { |
966 |
|
// |
967 |
|
break; |
968 |
|
} |
969 |
|
} |
970 |
|
} |
971 |
|
} |
972 |
|
|
973 |
|
// Mise à jour du journal d'activité de la tâche |
974 |
|
array_push($timestamp_log, array( |
975 |
|
'modification_date' => date('Y-m-d H:i:s'), |
976 |
|
'object_id' => $params['object_id'] !== null ? $params['object_id'] : $this->getVal('object_id'), |
977 |
|
'prev_object_id' => $this->getVal('object_id'), |
978 |
|
'state' => $params['state'], |
979 |
|
'prev_state' => $this->getVal('state'), |
980 |
|
'comment' => isset($params['comment']) ? $params['comment'] : $this->getVal('comment'), |
981 |
|
)); |
982 |
|
// |
983 |
|
$timestamp_log = json_encode($timestamp_log); |
984 |
|
|
985 |
|
|
986 |
|
// Les nouvelles valeurs après vérification des critères |
987 |
|
$result = array( |
988 |
|
'timestamp_log' => $timestamp_log, |
989 |
|
'object_id' => $params['object_id'], |
990 |
|
'state' => $params['state'], |
991 |
|
'comment' => $params['comment'], |
992 |
|
); |
993 |
|
return $result; |
994 |
|
} |
995 |
|
|
996 |
|
|
997 |
|
/** |
998 |
|
* TRIGGER - triggermodifierapres. |
999 |
|
* |
1000 |
|
* @param string $id |
1001 |
|
* @param null &$dnu1 @deprecated Ne pas utiliser. |
1002 |
|
* @param array $val Tableau des valeurs brutes. |
1003 |
|
* @param null $dnu2 @deprecated Ne pas utiliser. |
1004 |
|
* |
1005 |
|
* @return boolean |
1006 |
|
*/ |
1007 |
|
public function triggermodifierapres($id, &$dnu1 = null, $val = array(), $dnu2 = null) { |
1008 |
|
parent::triggermodifierapres($id, $dnu1, $val, $dnu2); |
1009 |
|
|
1010 |
|
// Suivi des notificiations |
1011 |
|
// En cas de changement de l'état de la tâche de notification, alors |
1012 |
|
// le suivi des dates de la notification et de l'instruction, est effectué |
1013 |
|
if (isset($val['category']) === true |
1014 |
|
&& $val['category'] === PORTAL |
1015 |
|
&& isset($val['type']) === true |
1016 |
|
&& ($val['type'] === 'notification_recepisse' |
1017 |
|
|| $val['type'] === 'notification_instruction' |
1018 |
|
|| $val['type'] === 'notification_decision' |
1019 |
|
|| $val['type'] === 'notification_service_consulte' |
1020 |
|
|| $val['type'] === 'notification_tiers_consulte')) { |
1021 |
|
// |
1022 |
|
if (isset($this->valF['state']) === true |
1023 |
|
&& $this->valF['state'] !== $this->getVal('state') |
1024 |
|
&& $this->valF['state'] !== self::STATUS_CANCELED) { |
1025 |
|
// |
1026 |
|
$inst_in = $this->f->get_inst__om_dbform(array( |
1027 |
|
"obj" => "instruction_notification", |
1028 |
|
"idx" => $val['object_id'], |
1029 |
|
)); |
1030 |
|
$valF_in = array(); |
1031 |
|
foreach ($inst_in->champs as $champ) { |
1032 |
|
$valF_in[$champ] = $inst_in->getVal($champ); |
1033 |
|
} |
1034 |
|
// Par défaut la date d'envoi et la date de premier accès sur |
1035 |
|
// la notification ne sont pas renseignées |
1036 |
|
$valF_in['date_envoi'] = null; |
1037 |
|
$valF_in['date_premier_acces'] = null; |
1038 |
|
// Lorsque la tâche est correctement traitée |
1039 |
|
if ($this->valF['state'] === self::STATUS_DONE) { |
1040 |
|
// |
1041 |
|
$valF_in['statut'] = __("envoyé"); |
1042 |
|
$valF_in['commentaire'] = __("Notification traitée"); |
1043 |
|
$valF_in['date_envoi'] = date('d/m/Y H:i:s'); |
1044 |
|
// Si l'instruction possède un document lié, alors ses dates |
1045 |
|
// de suivi sont mises à jour |
1046 |
|
$inst_instruction = $this->f->get_inst__om_dbform(array( |
1047 |
|
"obj" => "instruction", |
1048 |
|
"idx" => $inst_in->getVal('instruction'), |
1049 |
|
)); |
1050 |
|
if ($inst_instruction->has_an_edition() === true) { |
1051 |
|
$valF_instruction = array(); |
1052 |
|
foreach ($inst_instruction->champs as $champ) { |
1053 |
|
$valF_instruction[$champ] = $inst_instruction->getVal($champ); |
1054 |
|
} |
1055 |
|
$valF_instruction['date_envoi_rar'] = date('d/m/Y'); |
1056 |
|
$valF_instruction['date_retour_rar'] = date('d/m/Y', strtotime('now + 1 day')); |
1057 |
|
// Action spécifique pour identifier que la modification |
1058 |
|
// est une notification de demandeur |
1059 |
|
$inst_instruction->setParameter('maj', 175); |
1060 |
|
$update_instruction = $inst_instruction->modifier($valF_instruction); |
1061 |
|
if ($update_instruction === false) { |
1062 |
|
$this->addToLog(__METHOD__."(): ".$inst_instruction->msg, DEBUG_MODE); |
1063 |
|
return false; |
1064 |
|
} |
1065 |
|
} |
1066 |
|
} |
1067 |
|
// En cas d'erreur lors du traitement de la task |
1068 |
|
if ($this->valF['state'] === self::STATUS_ERROR) { |
1069 |
|
$valF_in['statut'] = __("échec"); |
1070 |
|
$valF_in['commentaire'] = __("Le traitement de la notification a échoué"); |
1071 |
|
} |
1072 |
|
// Met à jour la notification |
1073 |
|
$inst_in->setParameter('maj', 1); |
1074 |
|
$update_in = $inst_in->modifier($valF_in); |
1075 |
|
if ($update_in === false) { |
1076 |
|
$this->addToLog(__METHOD__."(): ".$inst_in->msg, DEBUG_MODE); |
1077 |
|
return false; |
1078 |
|
} |
1079 |
|
} |
1080 |
|
} |
1081 |
|
|
1082 |
|
// Envoi au contrôle de légalité |
1083 |
|
// En cas de changement de l'état de la tâche envoi_CL, alors le suivi |
1084 |
|
// des dates de l'instruction est effectué |
1085 |
|
if ($val['type'] === 'envoi_CL' |
1086 |
|
&& isset($this->valF['state']) === true |
1087 |
|
&& $this->valF['state'] === self::STATUS_DONE) { |
1088 |
|
// |
1089 |
|
$inst_instruction = $this->f->get_inst__om_dbform(array( |
1090 |
|
"obj" => "instruction", |
1091 |
|
"idx" => $this->getVal('object_id'), |
1092 |
|
)); |
1093 |
|
if ($inst_instruction->has_an_edition() === true) { |
1094 |
|
$valF_instruction = array(); |
1095 |
|
foreach ($inst_instruction->champs as $champ) { |
1096 |
|
$valF_instruction[$champ] = $inst_instruction->getVal($champ); |
1097 |
|
} |
1098 |
|
} |
1099 |
|
$valF_instruction['date_envoi_controle_legalite'] = date("Y-m-d"); |
1100 |
|
$inst_instruction->setParameter('maj', 1); |
1101 |
|
$update_instruction = $inst_instruction->modifier($valF_instruction); |
1102 |
|
if ($update_instruction === false) { |
1103 |
|
$this->addToLog(__METHOD__."(): ".$inst_instruction->msg, DEBUG_MODE); |
1104 |
|
return false; |
1105 |
|
} |
1106 |
|
} |
1107 |
|
|
1108 |
|
// |
1109 |
|
return true; |
1110 |
} |
} |
1111 |
|
|
1112 |
/** |
/** |
1139 |
return $this->end_treatment(__METHOD__, true); |
return $this->end_treatment(__METHOD__, true); |
1140 |
} |
} |
1141 |
|
|
1142 |
$timestamp_log = json_encode(array( |
// |
1143 |
'creation_date' => date('Y-m-d H:i:s'), |
$timestamp_log = json_encode(array()); |
1144 |
)); |
|
1145 |
|
// |
1146 |
|
$category = isset($params['val']['category']) === true ? $params['val']['category'] : $this->category; |
1147 |
|
|
1148 |
// Si la tâche est de type ajout_piece et de stream input alors on ajoute le fichier |
// Si la tâche est de type ajout_piece et de stream input alors on ajoute le fichier |
1149 |
// et on ajoute l'uid dans le champ json_payload avant l'ajout de la tâche |
// et on ajoute l'uid dans le champ json_payload avant l'ajout de la tâche |
1150 |
if (isset($params['val']['type']) |
if (isset($params['val']['type']) |
1151 |
&& ($params['val']['type'] == "add_piece" || $params['val']['type'] == "avis_consultation") |
&& in_array($params['val']['type'], self::TASK_WITH_DOCUMENT) |
1152 |
&& isset($params['val']['stream']) |
&& isset($params['val']['stream']) |
1153 |
&& $params['val']['stream'] == "input" ) { |
&& $params['val']['stream'] == "input" ) { |
1154 |
// |
// |
1157 |
$this->addToMessage(__("Le contenu JSON de la tâche n'est pas valide.")); |
$this->addToMessage(__("Le contenu JSON de la tâche n'est pas valide.")); |
1158 |
return $this->end_treatment(__METHOD__, false); |
return $this->end_treatment(__METHOD__, false); |
1159 |
} |
} |
1160 |
if (isset($json_payload['document_numerise']) === true |
if (isset($json_payload['document_numerise']["file_content"]) === true |
1161 |
&& empty($json_payload['document_numerise']) === false) { |
&& empty($json_payload['document_numerise']["file_content"]) === false) { |
1162 |
// |
// |
1163 |
$document_numerise = $json_payload['document_numerise']; |
$document_numerise = $json_payload['document_numerise']; |
1164 |
$file_content = base64_decode($document_numerise["file_content"]); |
$file_content = base64_decode($document_numerise["file_content"]); |
1184 |
} |
} |
1185 |
} |
} |
1186 |
|
|
1187 |
// Mise à jour du DI |
// Valeurs de la tâche |
1188 |
$valF = array( |
$valF = array( |
1189 |
'task' => '', |
'task' => '', |
1190 |
'type' => $params['val']['type'], |
'type' => $params['val']['type'], |
1194 |
'dossier' => isset($params['val']['dossier']) ? $params['val']['dossier'] : '', |
'dossier' => isset($params['val']['dossier']) ? $params['val']['dossier'] : '', |
1195 |
'stream' => $stream, |
'stream' => $stream, |
1196 |
'json_payload' => isset($params['val']['json_payload']) === true ? $params['val']['json_payload'] : '{}', |
'json_payload' => isset($params['val']['json_payload']) === true ? $params['val']['json_payload'] : '{}', |
1197 |
|
'category' => $category, |
1198 |
|
'creation_date' => date('Y-m-d'), |
1199 |
|
'creation_time' => date('H:i:s'), |
1200 |
|
'last_modification_date' => null, |
1201 |
|
'last_modification_time' => null, |
1202 |
|
'comment' => null, |
1203 |
|
); |
1204 |
|
|
1205 |
|
// Gestion de la mise à jour des tâches sortantes |
1206 |
|
$typeNonConcerne = array( |
1207 |
|
'notification_recepisse', |
1208 |
|
'notification_instruction', |
1209 |
|
'notification_decision', |
1210 |
|
'notification_service_consulte', |
1211 |
|
'notification_tiers_consulte', |
1212 |
|
'notification_depot_demat', |
1213 |
|
'notification_commune', |
1214 |
|
'notification_signataire', |
1215 |
); |
); |
1216 |
|
if ($valF["stream"] == "output" |
1217 |
|
&& ! in_array($valF['type'], $typeNonConcerne)) { |
1218 |
|
// Vérification de l'existance d'une tâche pour l'objet concerné |
1219 |
|
// La vérification diffère en fonction de certains types de tâche |
1220 |
|
$search_values_common = array( |
1221 |
|
sprintf('state != \'%s\'', self::STATUS_CANCELED), |
1222 |
|
sprintf('state != \'%s\'', self::STATUS_DONE), |
1223 |
|
); |
1224 |
|
$search_values_others = array( |
1225 |
|
sprintf('type = \'%s\'', $valF['type']), |
1226 |
|
sprintf('(object_id = \'%s\' OR dossier = \'%s\')', $valF['object_id'], $valF['dossier']), |
1227 |
|
); |
1228 |
|
$search_values_specifics = array( |
1229 |
|
sprintf('object_id = \'%s\'', $valF['object_id']), |
1230 |
|
); |
1231 |
|
|
1232 |
// tâche sortante |
// Recherche multi-critères sur les tâches |
1233 |
if($valF["stream"] == "output"){ |
// Si l'object id/dossier à des tâches de type $valF['type'] qui lui est associé |
1234 |
|
// Et que ces tâches ont des statut différents de canceled et done |
1235 |
|
// Alors on récupère ces tâches |
1236 |
|
// Sinon return false |
1237 |
|
$task_exists = $this->task_exists_multi_search(array_merge($search_values_common, $search_values_others)); |
1238 |
|
|
1239 |
// TODO expliquer ce code |
// S'il n'existe pas de tâche de type 'modification DI' pour l'object id/dossier |
|
$task_exists = $this->task_exists($valF['type'], $valF['object_id']); |
|
1240 |
if ($valF['type'] === 'modification_DI' && $task_exists === false) { |
if ($valF['type'] === 'modification_DI' && $task_exists === false) { |
1241 |
$task_exists = $this->task_exists('creation_DI', $valF['object_id']); |
// On se réfère à la tâche de type 'creation DI' de l'object id |
1242 |
|
$task_exists = $this->task_exists_multi_search(array_merge($search_values_common, $search_values_specifics, array("type = 'creation_DI'"))); |
1243 |
} |
} |
1244 |
|
// S'il n'existe pas de tâche de type 'modification DA' pour l'object id/dossier |
1245 |
if ($valF['type'] === 'modification_DA' && $task_exists === false) { |
if ($valF['type'] === 'modification_DA' && $task_exists === false) { |
1246 |
$task_exists = $this->task_exists('creation_DA', $valF['object_id']); |
// On se réfère à la tâche de type 'creation DA' de l'object id |
1247 |
|
$task_exists = $this->task_exists_multi_search(array_merge($search_values_common, $search_values_specifics, array("type = 'creation_DA'"))); |
1248 |
} |
} |
1249 |
|
if ($valF['type'] === 'ajout_piece') { |
1250 |
|
// On se réfère à la tâche de type 'ajout piece' de l'object id |
1251 |
|
$task_exists = $this->task_exists_multi_search(array_merge($search_values_common, $search_values_specifics, array("type = 'ajout_piece'"))); |
1252 |
|
} |
1253 |
|
if ($valF['type'] === 'creation_consultation') { |
1254 |
|
// On se réfère à la tâche de type 'creation consultation' de l'object id |
1255 |
|
$task_exists = $this->task_exists_multi_search(array_merge($search_values_common, $search_values_specifics, array("type = 'creation_consultation'"))); |
1256 |
|
} |
1257 |
|
// S'il existe une tâche pour l'objet concerné, pas d'ajout de nouvelle |
1258 |
|
// tâche mais mise à jour de l'existante |
1259 |
if ($task_exists !== false) { |
if ($task_exists !== false) { |
1260 |
$inst_task = $this->f->get_inst__om_dbform(array( |
// Plusieurs tâches pourraient exister, elles sont contôler par ordre croissant |
1261 |
"obj" => "task", |
foreach ($task_exists as $task) { |
1262 |
"idx" => $task_exists, |
$inst_task = $this->f->get_inst__om_dbform(array( |
1263 |
)); |
"obj" => "task", |
1264 |
$update_state = $inst_task->getVal('state'); |
"idx" => $task['task'], |
1265 |
if (isset($params['update_val']['state']) === true) { |
)); |
1266 |
$update_state = $params['update_val']['state']; |
$update_state = $inst_task->getVal('state'); |
1267 |
} |
if (isset($params['update_val']['state']) === true) { |
1268 |
$update_params = array( |
$update_state = $params['update_val']['state']; |
1269 |
'val' => array( |
} |
1270 |
'state' => $update_state, |
$object_id = $inst_task->getVal('object_id'); |
1271 |
), |
if (!empty($valF['object_id'])) { |
1272 |
); |
$object_id = $valF['object_id']; |
1273 |
return $inst_task->update_task($update_params); |
} |
1274 |
|
// Pour être mise à jour, la tâche existante ne doit pas être en cours de traitement |
1275 |
|
$task_pending = $inst_task->getVal('state') === self::STATUS_PENDING |
1276 |
|
&& $update_state === self::STATUS_PENDING |
1277 |
|
&& $inst_task->getVal('object_id') !== $object_id; |
1278 |
|
if ($task_pending === false) { |
1279 |
|
$update_params = array( |
1280 |
|
'val' => array( |
1281 |
|
'state' => $update_state, |
1282 |
|
), |
1283 |
|
'object_id' => $object_id, |
1284 |
|
); |
1285 |
|
return $inst_task->update_task($update_params); |
1286 |
|
} |
1287 |
|
} |
1288 |
} |
} |
1289 |
} |
} |
|
|
|
1290 |
$add = $this->ajouter($valF); |
$add = $this->ajouter($valF); |
1291 |
$this->addToLog(__METHOD__."(): retour de l'ajout de tâche: ".var_export($add, true), VERBOSE_MODE); |
$this->addToLog(__METHOD__."(): retour de l'ajout de tâche: ".var_export($add, true), VERBOSE_MODE); |
1292 |
if ($add === false) { |
if ($add === false) { |
1305 |
*/ |
*/ |
1306 |
public function update_task($params = array()) { |
public function update_task($params = array()) { |
1307 |
$this->begin_treatment(__METHOD__); |
$this->begin_treatment(__METHOD__); |
1308 |
$timestamp_log = $this->get_timestamp_log(); |
|
1309 |
if ($timestamp_log === false) { |
// Mise à jour de la tâche |
|
$this->addToLog(__METHOD__."(): erreur timestamp log", DEBUG_MODE); |
|
|
return $this->end_treatment(__METHOD__, false); |
|
|
} |
|
|
array_push($timestamp_log, array( |
|
|
'modification_date' => date('Y-m-d H:i:s'), |
|
|
'state' => $params['val']['state'], |
|
|
'prev_state' => $this->getVal('state'), |
|
|
)); |
|
|
$timestamp_log = json_encode($timestamp_log); |
|
1310 |
$valF = array( |
$valF = array( |
1311 |
'task' => $this->getVal($this->clePrimaire), |
'task' => $this->getVal($this->clePrimaire), |
1312 |
'type' => $this->getVal('type'), |
'type' => $this->getVal('type'), |
1313 |
'timestamp_log' => $timestamp_log, |
'timestamp_log' => '[]', |
1314 |
'state' => $params['val']['state'], |
'state' => $params['val']['state'], |
1315 |
'object_id' => $this->getVal('object_id'), |
'object_id' => isset($params['object_id']) == true ? $params['object_id'] : $this->getVal('object_id'), |
1316 |
'stream' => $this->getVal('stream'), |
'stream' => $this->getVal('stream'), |
1317 |
'dossier' => $this->getVal('dossier'), |
'dossier' => $this->getVal('dossier'), |
1318 |
'json_payload' => $this->getVal('json_payload'), |
'json_payload' => $this->getVal('json_payload'), |
1319 |
|
'category' => $this->getVal('category'), |
1320 |
|
'creation_date' => $this->getVal('creation_date'), |
1321 |
|
'creation_time' => $this->getVal('creation_time'), |
1322 |
|
'last_modification_date' => date('Y-m-d'), |
1323 |
|
'last_modification_time' => date('H:i:s'), |
1324 |
|
'comment' => isset($params['comment']) == true ? $params['comment'] : $this->getVal('comment'), |
1325 |
); |
); |
1326 |
$update = $this->modifier($valF); |
$update = $this->modifier($valF); |
1327 |
if ($update === false) { |
if ($update === false) { |
1370 |
|
|
1371 |
protected function view_tab_json() { |
protected function view_tab_json() { |
1372 |
$where = ''; |
$where = ''; |
1373 |
if ($this->f->get_submitted_get_value('state') !== null |
$category = null; |
1374 |
&& $this->f->get_submitted_get_value('state') !== '') { |
// Liste des paramètres possibles pour la recherche des tâches |
1375 |
// |
$params = array( |
1376 |
$where = sprintf(' WHERE state = \'%s\' ', $this->f->get_submitted_get_value('state')); |
'task', |
1377 |
|
'type', |
1378 |
|
'state', |
1379 |
|
'object_id', |
1380 |
|
'dossier', |
1381 |
|
'stream', |
1382 |
|
'category', |
1383 |
|
'lien_id_interne_uid_externe', |
1384 |
|
'object', |
1385 |
|
'external_uid', |
1386 |
|
); |
1387 |
|
// Pour chaque paramètre possible, vérification de son existance et de sa |
1388 |
|
// valeur pour compléter la requête de recherche |
1389 |
|
foreach ($params as $param) { |
1390 |
|
// |
1391 |
|
if ($this->f->get_submitted_get_value($param) !== null |
1392 |
|
&& $this->f->get_submitted_get_value($param) !== '') { |
1393 |
|
// Condition spécifique au champ 'category' |
1394 |
|
if ($param === 'category') { |
1395 |
|
$category = $this->f->get_submitted_get_value('category'); |
1396 |
|
} |
1397 |
|
// |
1398 |
|
$where_or_and = 'WHERE'; |
1399 |
|
if ($where !== '') { |
1400 |
|
$where_or_and = 'AND'; |
1401 |
|
} |
1402 |
|
$table = 'task'; |
1403 |
|
if ($param === 'lien_id_interne_uid_externe' |
1404 |
|
|| $param === 'object' |
1405 |
|
|| $param === 'external_uid') { |
1406 |
|
// |
1407 |
|
$table = 'lien_id_interne_uid_externe'; |
1408 |
|
} |
1409 |
|
$where .= sprintf(' %s %s.%s = \'%s\' ', $where_or_and, $table, $param, $this->f->get_submitted_get_value($param)); |
1410 |
|
} |
1411 |
} |
} |
1412 |
|
// |
1413 |
$query = sprintf(' |
$query = sprintf(' |
1414 |
SELECT |
SELECT |
1415 |
* |
DISTINCT (task.task), |
1416 |
|
task.object_id, |
1417 |
|
task.dossier, |
1418 |
|
task.stream, |
1419 |
|
task.category, |
1420 |
|
task.creation_date, |
1421 |
|
task.creation_time, |
1422 |
|
task.last_modification_date, |
1423 |
|
task.last_modification_time, |
1424 |
|
task.comment |
1425 |
FROM %1$stask |
FROM %1$stask |
1426 |
|
LEFT JOIN %1$slien_id_interne_uid_externe |
1427 |
|
ON task.object_id = lien_id_interne_uid_externe.object_id |
1428 |
|
AND task.category = lien_id_interne_uid_externe.category |
1429 |
%2$s |
%2$s |
1430 |
ORDER BY task ASC |
ORDER BY task ASC |
1431 |
', |
', |
1432 |
DB_PREFIXE, |
DB_PREFIXE, |
1433 |
$where |
$where |
1434 |
); |
); |
1435 |
$res = $this->f->get_all_results_from_db_query($query, true); |
$res = $this->f->get_all_results_from_db_query( |
1436 |
|
$query, |
1437 |
|
array( |
1438 |
|
"origin" => __METHOD__, |
1439 |
|
"force_return" => true, |
1440 |
|
) |
1441 |
|
); |
1442 |
if ($res['code'] === 'KO') { |
if ($res['code'] === 'KO') { |
1443 |
return false; |
return false; |
1444 |
} |
} |
1445 |
$list_tasks = array(); |
$list_tasks = array(); |
1446 |
foreach ($res['result'] as $task) { |
foreach ($res['result'] as $task) { |
|
$task['timestamp_log'] = json_decode($task['timestamp_log'], true); |
|
|
$task['dossier'] = $task['dossier']; |
|
1447 |
if ($task['type'] === 'ajout_piece') { |
if ($task['type'] === 'ajout_piece') { |
1448 |
$val_dn = $this->get_document_numerise_data($task['object_id']); |
$val_dn = $this->get_document_numerise_data($task['object_id']); |
1449 |
} |
} |
1450 |
if ($task['stream'] === 'output') { |
if ($task['stream'] === 'output') { |
1451 |
$task['external_uids'] = $this->get_all_external_uids($task['dossier']); |
$task['external_uids'] = array_merge( |
1452 |
|
$this->get_all_external_uids($task['dossier'], array(), $category !== null ? $category : $task['category']), |
1453 |
|
$this->get_all_external_uids($task['object_id'], array(), $category !== null ? $category : $task['category']) |
1454 |
|
); |
1455 |
} |
} |
1456 |
$list_tasks[$task['task']] = $task; |
$list_tasks[$task['task']] = $task; |
1457 |
} |
} |
1458 |
printf(json_encode($list_tasks)); |
echo(json_encode($list_tasks)); |
1459 |
} |
} |
1460 |
|
|
1461 |
protected function get_dossier_data(string $dossier) { |
protected function get_dossier_data(string $dossier) { |
1464 |
"obj" => "dossier", |
"obj" => "dossier", |
1465 |
"idx" => $dossier, |
"idx" => $dossier, |
1466 |
)); |
)); |
1467 |
|
if (empty($inst_di->val) === true) { |
1468 |
|
return $val_di; |
1469 |
|
} |
1470 |
$val_di = $inst_di->get_json_data(); |
$val_di = $inst_di->get_json_data(); |
1471 |
if ($val_di['dossier_instruction_type_code'] === 'T') { |
if ($val_di['dossier_instruction_type_code'] === 'T') { |
1472 |
$val_di['date_decision_transfert'] = $val_di['date_decision']; |
$val_di['date_decision_transfert'] = $val_di['date_decision']; |
1557 |
if (isset($val_dt['tax_ext_pret']) === true |
if (isset($val_dt['tax_ext_pret']) === true |
1558 |
&& $val_dt['tax_ext_pret'] === 'f') { |
&& $val_dt['tax_ext_pret'] === 'f') { |
1559 |
// |
// |
1560 |
$val_dt['tax_su_princ_surf1'] = $val_dt['tax_surf_tot_cstr']; |
$val_dt['tax_su_princ_surf1'] = isset($val_dt['tax_surf_tot_cstr']) === true ? $val_dt['tax_surf_tot_cstr'] : ''; |
1561 |
$val_dt['tax_su_princ_surf_stat1'] = $val_dt['tax_surf_loc_stat']; |
$val_dt['tax_su_princ_surf_stat1'] = isset($val_dt['tax_surf_loc_stat']) === true ? $val_dt['tax_surf_loc_stat'] : ''; |
1562 |
} |
} |
1563 |
if (isset($val_dt['tax_ext_pret']) === true |
if (isset($val_dt['tax_ext_pret']) === true |
1564 |
&& $val_dt['tax_ext_pret'] === 't') { |
&& $val_dt['tax_ext_pret'] === 't') { |
1567 |
if (preg_match('/[pP].*[lL].*[aA].*[iI]/', $val_dt['tax_ext_desc']) === 1 |
if (preg_match('/[pP].*[lL].*[aA].*[iI]/', $val_dt['tax_ext_desc']) === 1 |
1568 |
|| preg_match('/[lL].*[lL].*[tT].*[sS]/', $val_dt['tax_ext_desc']) === 1) { |
|| preg_match('/[lL].*[lL].*[tT].*[sS]/', $val_dt['tax_ext_desc']) === 1) { |
1569 |
// |
// |
1570 |
$val_dt['tax_su_princ_surf2'] = $val_dt['tax_surf_tot_cstr']; |
$val_dt['tax_su_princ_surf2'] = isset($val_dt['tax_surf_tot_cstr']) === true ? $val_dt['tax_surf_tot_cstr'] : ''; |
1571 |
$val_dt['tax_su_princ_surf_stat2'] = $val_dt['tax_surf_loc_stat']; |
$val_dt['tax_su_princ_surf_stat2'] = isset($val_dt['tax_surf_loc_stat']) === true ? $val_dt['tax_surf_loc_stat'] : ''; |
1572 |
} |
} |
1573 |
// if (preg_match('/[pP].*[tT].*[zZ]/', $val_dt['tax_ext_desc']) === 1) { |
// if (preg_match('/[pP].*[tT].*[zZ]/', $val_dt['tax_ext_desc']) === 1) { |
1574 |
// $val_dt['tax_su_princ_surf4'] = $val_dt['tax_surf_tot_cstr']; |
// $val_dt['tax_su_princ_surf4'] = $val_dt['tax_surf_tot_cstr']; |
1612 |
', |
', |
1613 |
DB_PREFIXE |
DB_PREFIXE |
1614 |
); |
); |
1615 |
$res = $this->f->get_all_results_from_db_query($query, true); |
$res = $this->f->get_all_results_from_db_query( |
1616 |
|
$query, |
1617 |
|
array( |
1618 |
|
"origin" => __METHOD__, |
1619 |
|
"force_return" => true, |
1620 |
|
) |
1621 |
|
); |
1622 |
if ($res['code'] === 'KO') { |
if ($res['code'] === 'KO') { |
1623 |
return array(); |
return array(); |
1624 |
} |
} |
1629 |
return $result; |
return $result; |
1630 |
} |
} |
1631 |
|
|
1632 |
protected function get_external_uid($fk_idx, string $fk_idx_2) { |
protected function get_external_uid($fk_idx, string $fk_idx_2, $fk_idx_3 = PLATAU, $order_asc_desc = 'DESC') { |
1633 |
$inst_external_uid = $this->f->get_inst__by_other_idx(array( |
$inst_external_uid = $this->f->get_inst__by_other_idx(array( |
1634 |
"obj" => "lien_id_interne_uid_externe", |
"obj" => "lien_id_interne_uid_externe", |
1635 |
"fk_field" => 'object_id', |
"fk_field" => 'object_id', |
1636 |
"fk_idx" => $fk_idx, |
"fk_idx" => $fk_idx, |
1637 |
"fk_field_2" => 'object', |
"fk_field_2" => 'object', |
1638 |
"fk_idx_2" => $fk_idx_2, |
"fk_idx_2" => $fk_idx_2, |
1639 |
|
"fk_field_3" => 'category', |
1640 |
|
"fk_idx_3" => $fk_idx_3, |
1641 |
|
"order_field" => 'lien_id_interne_uid_externe', |
1642 |
|
"order_asc_desc" => $order_asc_desc, |
1643 |
)); |
)); |
1644 |
return $inst_external_uid->getVal('external_uid'); |
return $inst_external_uid->getVal('external_uid'); |
1645 |
} |
} |
1646 |
|
|
1647 |
protected function get_all_external_uids($fk_idx, $link_objects = array()) { |
protected function get_all_external_uids($fk_idx, $link_objects = array(), $category=PLATAU) { |
1648 |
if (count($link_objects) == 0) { |
if (count($link_objects) == 0) { |
1649 |
$link_objects = $this->get_list_distinct_objects_external_link(); |
$link_objects = $this->get_list_distinct_objects_external_link(); |
1650 |
} |
} |
1651 |
$val_external_uid = array(); |
$val_external_uid = array(); |
1652 |
foreach ($link_objects as $link_object) { |
foreach ($link_objects as $link_object) { |
1653 |
$external_uid = $this->get_external_uid($fk_idx, $link_object); |
$external_uid = $this->get_external_uid($fk_idx, $link_object, $category); |
1654 |
if ($external_uid !== '' && $external_uid !== null) { |
if ($external_uid !== '' && $external_uid !== null) { |
1655 |
$val_external_uid[$link_object] = $external_uid; |
$val_external_uid[$link_object] = $external_uid; |
1656 |
} |
} |
1658 |
return $val_external_uid; |
return $val_external_uid; |
1659 |
} |
} |
1660 |
|
|
1661 |
protected function get_demandeurs_data(string $dossier) { |
protected function get_demandeurs_data($dossier) { |
1662 |
$val_demandeur = array(); |
$val_demandeur = array(); |
1663 |
|
if ($dossier === null) { |
1664 |
|
return $val_demandeur; |
1665 |
|
} |
1666 |
$inst_di = $this->f->get_inst__om_dbform(array( |
$inst_di = $this->f->get_inst__om_dbform(array( |
1667 |
"obj" => "dossier", |
"obj" => "dossier", |
1668 |
"idx" => $dossier, |
"idx" => $dossier, |
1693 |
return $val_architecte; |
return $val_architecte; |
1694 |
} |
} |
1695 |
|
|
1696 |
protected function get_instruction_data(string $dossier, $type = 'decision', $extra_params = array()) { |
protected function get_instruction_data($dossier, $type = 'decision', $extra_params = array()) { |
1697 |
$val_instruction = null; |
$val_instruction = null; |
1698 |
|
if ($dossier === null) { |
1699 |
|
return $val_instruction; |
1700 |
|
} |
1701 |
$instruction_with_doc = null; |
$instruction_with_doc = null; |
1702 |
$inst_di = $this->f->get_inst__om_dbform(array( |
$inst_di = $this->f->get_inst__om_dbform(array( |
1703 |
"obj" => "dossier", |
"obj" => "dossier", |
1757 |
return $val_instruction; |
return $val_instruction; |
1758 |
} |
} |
1759 |
|
|
1760 |
|
|
1761 |
|
/** |
1762 |
|
* Récupère les informations pour les notifications ayant plusieurs annexe |
1763 |
|
*/ |
1764 |
|
protected function get_instruction_notification_data($category, $type = '', $extra_params = array()) { |
1765 |
|
$val_in = null; |
1766 |
|
|
1767 |
|
$idx = null; |
1768 |
|
if ($type === 'with-id') { |
1769 |
|
$idx = $extra_params['with-id']; |
1770 |
|
} |
1771 |
|
|
1772 |
|
// Récupération du type de notification. Le type est nécessaire pour récupérer |
1773 |
|
// le message et le titre de notification. |
1774 |
|
$typeNotification = $this->getVal('type'); |
1775 |
|
if (isset($this->valF['type'])) { |
1776 |
|
$typeNotification = $this->valF['type']; |
1777 |
|
} |
1778 |
|
|
1779 |
|
// récupére les données à intégrer à la payload |
1780 |
|
$inst_in = $this->f->get_inst__om_dbform(array( |
1781 |
|
"obj" => "instruction_notification", |
1782 |
|
"idx" => $idx, |
1783 |
|
)); |
1784 |
|
if (count($inst_in->val) > 0) { |
1785 |
|
$val_in = $inst_in->get_json_data(); |
1786 |
|
|
1787 |
|
$val_in['parametre_courriel_type_titre'] = ''; |
1788 |
|
$val_in['parametre_courriel_type_message'] = ''; |
1789 |
|
// Récupération du message et du titre |
1790 |
|
if ($category === 'mail') { |
1791 |
|
$inst_instruction = $this->f->get_inst__om_dbform(array( |
1792 |
|
"obj" => "instruction", |
1793 |
|
"idx" => $inst_in->getVal('instruction'), |
1794 |
|
)); |
1795 |
|
$collectivite_id = $inst_instruction->get_dossier_instruction_om_collectivite($inst_instruction->getVal('dossier')); |
1796 |
|
$phrase_type_notification = $this->f->get_notification_parametre_courriel_type($collectivite_id, $typeNotification); |
1797 |
|
$val_in['parametre_courriel_type_titre'] = $phrase_type_notification['parametre_courriel_type_titre']; |
1798 |
|
$val_in['parametre_courriel_type_message'] = $phrase_type_notification['parametre_courriel_type_message']; |
1799 |
|
} |
1800 |
|
|
1801 |
|
if ($typeNotification == 'notification_signataire') { |
1802 |
|
$val_in['lien_page_signature'] = $inst_in->getLienPageSignature($inst_instruction); |
1803 |
|
} |
1804 |
|
else { |
1805 |
|
// Récupération des liens vers les documents et des id et type des annexes |
1806 |
|
$infoDocNotif = $inst_in->getInfosDocumentsNotif($inst_in->getVal($inst_in->clePrimaire), $category); |
1807 |
|
$cle = $category == PORTAL ? 'path' : 'lien_telechargement_document'; |
1808 |
|
$val_in[$cle] = $infoDocNotif['document']['path']; |
1809 |
|
$val_in['annexes'] = $infoDocNotif['annexes']; |
1810 |
|
} |
1811 |
|
} |
1812 |
|
return $val_in; |
1813 |
|
} |
1814 |
|
|
1815 |
|
/** |
1816 |
|
* Récupère les informations concernant la lettre au pétitionnaire. |
1817 |
|
* |
1818 |
|
* @param string identifiant du dossier |
1819 |
|
* @param string type de tâche |
1820 |
|
* @param array paramètre supplémentaire permettant de récupérer les informations |
1821 |
|
* |
1822 |
|
* @return array information concernant la lettre au pétitionnaire |
1823 |
|
*/ |
1824 |
|
protected function get_lettre_petitionnaire_data($dossier, $type, $extra_params = array()) { |
1825 |
|
// Si la date limite de notification n'a pas été dépassé le type de lettre est 1 |
1826 |
|
// Si la date a été dépassé et qu'il s'agit d'une demande de pièce le type est 3 |
1827 |
|
// Si la date a été dépassé et qu'il s'agit d'une prolongation le type est 4 |
1828 |
|
// Le type de document dépend du type de pièce |
1829 |
|
$nomTypeLettre = ''; |
1830 |
|
$nomTypeDocument = ''; |
1831 |
|
if ($type === 'lettre_incompletude') { |
1832 |
|
$nomTypeLettre = '3'; |
1833 |
|
$nomTypeDocument = '4'; |
1834 |
|
} elseif ($type === 'lettre_majoration') { |
1835 |
|
$nomTypeLettre = '4'; |
1836 |
|
$nomTypeDocument = '6'; |
1837 |
|
} |
1838 |
|
|
1839 |
|
$inst_di = $this->f->get_inst__om_dbform(array( |
1840 |
|
"obj" => "dossier", |
1841 |
|
"idx" => $dossier, |
1842 |
|
)); |
1843 |
|
$date_limite_notification = DateTime::createFromFormat('Y-m-d', $inst_di->getVal('date_notification_delai')); |
1844 |
|
$aujourdhui = new DateTime(); |
1845 |
|
if (! $date_limite_notification instanceof DateTime) { |
1846 |
|
$nomTypeLettre = ''; |
1847 |
|
$nomTypeDocument = ''; |
1848 |
|
} elseif ($aujourdhui < $date_limite_notification) { |
1849 |
|
$nomTypeLettre = '1'; |
1850 |
|
$nomTypeDocument = '3'; |
1851 |
|
} |
1852 |
|
|
1853 |
|
return array( |
1854 |
|
'nomEtatLettre' => '3', |
1855 |
|
'nomModaliteNotifMetier' => '4', |
1856 |
|
'nomTypeLettre' => $nomTypeLettre, |
1857 |
|
'nomTypeDocument' => $nomTypeDocument |
1858 |
|
); |
1859 |
|
} |
1860 |
|
|
1861 |
protected function sort_instruction_data(array $values, array $res) { |
protected function sort_instruction_data(array $values, array $res) { |
1862 |
$fields = array( |
$fields = array( |
1863 |
"date_evenement", |
"date_evenement", |
1871 |
"om_fichier_instruction", |
"om_fichier_instruction", |
1872 |
"tacite", |
"tacite", |
1873 |
"lettretype", |
"lettretype", |
1874 |
|
"commentaire", |
1875 |
|
"complement_om_html", |
1876 |
); |
); |
1877 |
foreach ($values as $key => $value) { |
foreach ($values as $key => $value) { |
1878 |
if (in_array($key, $fields) === true) { |
if (in_array($key, $fields) === true) { |
1891 |
return $res; |
return $res; |
1892 |
} |
} |
1893 |
|
|
1894 |
|
/** |
1895 |
|
* Permet de définir si l'instruction passée en paramètre est une instruction |
1896 |
|
* récépissé d'une demande et si la demande en question a générée un dossier d'instruction. |
1897 |
|
* |
1898 |
|
* @param integer $instruction Identifiant de l'instruction |
1899 |
|
* @return boolean |
1900 |
|
*/ |
1901 |
|
protected function is_demande_instruction_recepisse_without_dossier($instruction) { |
1902 |
|
if ($instruction === null) { |
1903 |
|
return false; |
1904 |
|
} |
1905 |
|
$qres = $this->f->get_one_result_from_db_query( |
1906 |
|
sprintf( |
1907 |
|
'SELECT |
1908 |
|
demande_type.dossier_instruction_type |
1909 |
|
FROM |
1910 |
|
%1$sdemande |
1911 |
|
INNER JOIN %1$sdemande_type |
1912 |
|
ON demande.demande_type = demande_type.demande_type |
1913 |
|
WHERE |
1914 |
|
demande.instruction_recepisse = %2$s', |
1915 |
|
DB_PREFIXE, |
1916 |
|
intval($instruction) |
1917 |
|
), |
1918 |
|
array( |
1919 |
|
"origin" => __METHOD__, |
1920 |
|
"force_return" => true, |
1921 |
|
) |
1922 |
|
); |
1923 |
|
if ($qres["code"] !== "OK") { |
1924 |
|
return null; |
1925 |
|
} |
1926 |
|
if ($qres["result"] === "") { |
1927 |
|
return true; |
1928 |
|
} |
1929 |
|
return false; |
1930 |
|
} |
1931 |
|
|
1932 |
protected function get_document_numerise_data(string $dn) { |
protected function get_document_numerise_data(string $dn) { |
1933 |
$val_dn = array(); |
$val_dn = array(); |
1934 |
$inst_dn = $this->f->get_inst__om_dbform(array( |
$inst_dn = $this->f->get_inst__om_dbform(array( |
1968 |
)); |
)); |
1969 |
$ad = $inst_di->getVal('avis_decision'); |
$ad = $inst_di->getVal('avis_decision'); |
1970 |
$val_ad = array(); |
$val_ad = array(); |
1971 |
if ($ad !== null) { |
if ($ad !== null && trim($ad) !== '') { |
1972 |
$inst_ad = $this->f->get_inst__om_dbform(array( |
$inst_ad = $this->f->get_inst__om_dbform(array( |
1973 |
"obj" => "avis_decision", |
"obj" => "avis_decision", |
1974 |
"idx" => $ad, |
"idx" => $ad, |
2030 |
|
|
2031 |
protected function view_form_json($in_field = false) { |
protected function view_form_json($in_field = false) { |
2032 |
// |
// |
2033 |
if ($this->f->get_submitted_post_value('valid') === null |
$check_state = isset($this->valF['state']) === true ? $this->valF['state'] : $this->getVal('state'); |
2034 |
&& $this->getVal('state') !== self::STATUS_DRAFT) { |
if ($check_state !== self::STATUS_CANCELED) { |
2035 |
// Liste des valeurs à afficher |
// Liste des valeurs à afficher |
2036 |
$val = array(); |
$val = array(); |
2037 |
// |
// |
2039 |
foreach ($val_task as $key => $value) { |
foreach ($val_task as $key => $value) { |
2040 |
$val_task[$key] = strip_tags($value); |
$val_task[$key] = strip_tags($value); |
2041 |
} |
} |
2042 |
$val_task['timestamp_log'] = json_decode($val_task['timestamp_log'], true); |
|
2043 |
$val['task'] = $val_task; |
// Vérifie pour les tâches dont l'affichage de la payload est calculée si l'objet |
2044 |
// |
// de référence de la tâche existe. |
2045 |
if ($this->getVal('type') === 'creation_DA' |
$objectRefExist = true; |
2046 |
|| $this->getVal('type') === 'modification_DA') { |
if ($val_task['stream'] === 'output' |
2047 |
// |
&& (empty($val_task['json_payload']) || $val_task['json_payload'] === '{}')) { |
2048 |
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id')); |
$objectRefExist = $this->does_referenced_object_exist( |
2049 |
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation'); |
$val_task['object_id'], |
2050 |
$val['dossier_autorisation_parcelle'] = $this->get_parcelles_data('dossier_autorisation', $val['dossier_autorisation']['dossier_autorisation']); |
$val_task['type'] |
2051 |
$val_external_uid = array(); |
); |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier_autorisation']['dossier_autorisation'], 'dossier_autorisation'); |
|
|
$val['external_uids'] = $val_external_uid; |
|
|
} |
|
|
// |
|
|
if ($this->getVal('type') === 'creation_DI' |
|
|
|| $this->getVal('type') === 'modification_DI' |
|
|
|| $this->getVal('type') === 'depot_DI') { |
|
|
// |
|
|
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
|
|
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_instruction'); |
|
|
$val['demandeur'] = $this->get_demandeurs_data($val['dossier']['dossier']); |
|
|
$architecte = isset($val['donnees_techniques']['architecte']) === true ? $val['donnees_techniques']['architecte'] : null; |
|
|
$val['architecte'] = $this->get_architecte_data($architecte); |
|
|
$val['dossier_parcelle'] = $this->get_parcelles_data('dossier', $val['dossier']['dossier']); |
|
|
$val_external_uid = array(); |
|
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
|
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
|
|
$val['external_uids'] = $val_external_uid; |
|
|
} |
|
|
// |
|
|
if ($this->getVal('type') === 'qualification_DI') { |
|
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
|
|
$val_external_uid = array(); |
|
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
|
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
|
|
$val['external_uids'] = $val_external_uid; |
|
|
} |
|
|
// |
|
|
if ($this->getVal('type') === 'ajout_piece') { |
|
|
$val['document_numerise'] = $this->get_document_numerise_data($this->getVal('object_id')); |
|
|
$val['dossier'] = $this->get_dossier_data($val['document_numerise']['dossier']); |
|
|
$val_external_uid = array(); |
|
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
|
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
|
|
$val_external_uid['document_numerise'] = $this->get_external_uid($val['document_numerise']['document_numerise'], 'document_numerise'); |
|
|
$val['external_uids'] = $val_external_uid; |
|
|
} |
|
|
// |
|
|
if ($this->getVal('type') === 'decision_DI') { |
|
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
|
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
|
|
$val_external_uid = array(); |
|
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
|
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
|
|
$val['external_uids'] = $val_external_uid; |
|
|
} |
|
|
// |
|
|
if ($this->getVal('type') === 'incompletude_DI') { |
|
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
|
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
|
|
$val_external_uid = array(); |
|
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
|
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
|
|
$val['external_uids'] = $val_external_uid; |
|
|
} |
|
|
// |
|
|
if ($this->getVal('type') === 'completude_DI') { |
|
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
|
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
|
|
$val_external_uid = array(); |
|
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
|
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
|
|
$val['external_uids'] = $val_external_uid; |
|
|
} |
|
|
// |
|
|
if ($this->getVal('type') === 'pec_metier_consultation') { |
|
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
|
|
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
|
|
$val_external_uid = array(); |
|
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
|
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
|
|
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
|
|
$val['external_uids'] = $val_external_uid; |
|
2052 |
} |
} |
2053 |
// |
|
2054 |
if ($this->getVal('type') === 'avis_consultation') { |
// Si l'objet de référence n'existe pas log le numéro de la tâche concerné et |
2055 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
// renvoie une payload contenant le message d'erreur. |
2056 |
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
// Sinon constitue la payload du json. |
2057 |
$val['avis_decision'] = $this->get_avis_decision_data($this->getVal('dossier')); |
if (! $objectRefExist) { |
2058 |
if (isset($val['instruction']['signataire_arrete']) === true) { |
$this->f->addToLog( |
2059 |
$val['signataire_arrete'] = $this->get_signataire_arrete_data($val['instruction']['signataire_arrete']); |
sprintf( |
2060 |
} |
__('Impossible de récupérer la payload car l\'objet de réference n\'existe pas pour la tâche : %s'), |
2061 |
$val_external_uid = array(); |
$val_task['task'] |
2062 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
), |
2063 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
DEBUG_MODE |
2064 |
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
); |
2065 |
$val['external_uids'] = $val_external_uid; |
$val = __('Impossible de recuperer la payload car l\'objet de reference n\'existe pas.'); |
2066 |
} |
} else { |
2067 |
// XXX WIP |
|
2068 |
if ($this->getVal('type') === 'creation_consultation') { |
// L'historique n'est pas nécessaire dans l'affichage en JSON |
2069 |
// |
if ($in_field === true) { |
2070 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
$val_task['timestamp_log'] = json_decode($val_task['timestamp_log'], true); |
2071 |
$val['consultation'] = $this->get_consultation_data($this->getVal('object_id')); |
} else { |
2072 |
$val['service'] = $this->get_service_data($val['consultation']['service']); |
unset($val_task['timestamp_log']); |
2073 |
$val_external_uid = array(); |
} |
2074 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
unset($val_task['timestamp_log_hidden']); |
2075 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
$val['task'] = $val_task; |
2076 |
$val['external_uids'] = $val_external_uid; |
// |
2077 |
|
if ($this->getVal('type') === 'creation_DA' |
2078 |
|
|| $this->getVal('type') === 'modification_DA') { |
2079 |
|
// |
2080 |
|
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id')); |
2081 |
|
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation'); |
2082 |
|
$val['dossier_autorisation_parcelle'] = $this->get_parcelles_data('dossier_autorisation', $val['dossier_autorisation']['dossier_autorisation']); |
2083 |
|
$val_external_uid = array(); |
2084 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier_autorisation']['dossier_autorisation'], 'dossier_autorisation'); |
2085 |
|
$val['external_uids'] = $val_external_uid; |
2086 |
|
} |
2087 |
|
// |
2088 |
|
if ($this->getVal('type') === 'creation_DI' |
2089 |
|
|| $this->getVal('type') === 'modification_DI' |
2090 |
|
|| $this->getVal('type') === 'depot_DI') { |
2091 |
|
// |
2092 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
2093 |
|
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_instruction'); |
2094 |
|
$val['demandeur'] = $this->get_demandeurs_data($val['dossier']['dossier']); |
2095 |
|
$architecte = isset($val['donnees_techniques']['architecte']) === true ? $val['donnees_techniques']['architecte'] : null; |
2096 |
|
$val['architecte'] = $this->get_architecte_data($architecte); |
2097 |
|
$val['dossier_parcelle'] = $this->get_parcelles_data('dossier', $val['dossier']['dossier']); |
2098 |
|
$val_external_uid = array(); |
2099 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2100 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2101 |
|
$val['external_uids'] = $val_external_uid; |
2102 |
|
} |
2103 |
|
// |
2104 |
|
if ($this->getVal('type') === 'qualification_DI') { |
2105 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2106 |
|
$val_external_uid = array(); |
2107 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2108 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2109 |
|
$val['external_uids'] = $val_external_uid; |
2110 |
|
} |
2111 |
|
// |
2112 |
|
if ($this->getVal('type') === 'ajout_piece') { |
2113 |
|
$val['document_numerise'] = $this->get_document_numerise_data($this->getVal('object_id')); |
2114 |
|
$val['dossier'] = $this->get_dossier_data($val['document_numerise']['dossier']); |
2115 |
|
$val_external_uid = array(); |
2116 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2117 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2118 |
|
$val_external_uid['piece'] = $this->get_external_uid($val['document_numerise']['document_numerise'], 'piece'); |
2119 |
|
$val['external_uids'] = $val_external_uid; |
2120 |
|
} |
2121 |
|
// |
2122 |
|
if ($this->getVal('type') === 'decision_DI') { |
2123 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2124 |
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
2125 |
|
$val['instruction']['final'] = 't'; |
2126 |
|
if (isset($val['instruction']['signataire_arrete']) === true) { |
2127 |
|
$val['signataire_arrete'] = $this->get_signataire_arrete_data($val['instruction']['signataire_arrete']); |
2128 |
|
} |
2129 |
|
$val_external_uid = array(); |
2130 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2131 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2132 |
|
$val['external_uids'] = $val_external_uid; |
2133 |
|
} |
2134 |
|
// |
2135 |
|
if ($this->getVal('type') === 'incompletude_DI') { |
2136 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2137 |
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
2138 |
|
$val_external_uid = array(); |
2139 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2140 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2141 |
|
$val['external_uids'] = $val_external_uid; |
2142 |
|
} |
2143 |
|
// |
2144 |
|
if ($this->getVal('type') === 'completude_DI') { |
2145 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2146 |
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
2147 |
|
$val_external_uid = array(); |
2148 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2149 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2150 |
|
$val['external_uids'] = $val_external_uid; |
2151 |
|
} |
2152 |
|
// |
2153 |
|
if ($this->getVal('type') === 'lettre_incompletude' |
2154 |
|
|| $this->getVal('type') === 'lettre_majoration') { |
2155 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2156 |
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
2157 |
|
$val['lettre_petitionnaire'] = $this->get_lettre_petitionnaire_data($val['dossier']['dossier'], $this->getVal('type')); |
2158 |
|
$val_external_uid = array(); |
2159 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2160 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2161 |
|
$val['external_uids'] = $val_external_uid; |
2162 |
|
} |
2163 |
|
// |
2164 |
|
if ($this->getVal('type') === 'pec_metier_consultation') { |
2165 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2166 |
|
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
2167 |
|
$val_external_uid = array(); |
2168 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2169 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2170 |
|
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
2171 |
|
$val['external_uids'] = $val_external_uid; |
2172 |
|
} |
2173 |
|
// |
2174 |
|
if ($this->getVal('type') === 'avis_consultation') { |
2175 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2176 |
|
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
2177 |
|
$val['avis_decision'] = $this->get_avis_decision_data($this->getVal('dossier')); |
2178 |
|
if (isset($val['instruction']['signataire_arrete']) === true) { |
2179 |
|
$val['signataire_arrete'] = $this->get_signataire_arrete_data($val['instruction']['signataire_arrete']); |
2180 |
|
} |
2181 |
|
$val_external_uid = array(); |
2182 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2183 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2184 |
|
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
2185 |
|
$val_external_uid['avis_dossier_consultation'] = $this->get_external_uid($this->getVal('object_id'), 'avis_dossier_consultation'); |
2186 |
|
$val['external_uids'] = $val_external_uid; |
2187 |
|
} |
2188 |
|
// XXX WIP |
2189 |
|
if ($this->getVal('type') === 'creation_consultation') { |
2190 |
|
// |
2191 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2192 |
|
$val['consultation'] = $this->get_consultation_data($this->getVal('object_id')); |
2193 |
|
$val['service'] = $this->get_service_data($val['consultation']['service']); |
2194 |
|
$val_external_uid = array(); |
2195 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2196 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2197 |
|
$val['external_uids'] = $val_external_uid; |
2198 |
|
} |
2199 |
|
// |
2200 |
|
if ($this->getVal('type') === 'envoi_CL') { |
2201 |
|
// |
2202 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2203 |
|
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
2204 |
|
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($val['dossier']['dossier_autorisation']); |
2205 |
|
$val_external_uid = array(); |
2206 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2207 |
|
$val_external_uid['dossier'] = $this->get_external_uid($this->getVal('dossier'), 'dossier'); |
2208 |
|
$val_external_uid['decision'] = $this->get_external_uid($this->getVal('object_id'), 'instruction'); |
2209 |
|
if ($val_external_uid['decision'] === '') { |
2210 |
|
$inst_instruction = $this->f->get_inst__om_dbform(array( |
2211 |
|
"obj" => "instruction", |
2212 |
|
"idx" => $this->getVal('object_id'), |
2213 |
|
)); |
2214 |
|
$val_external_uid['decision'] = $this->get_external_uid($inst_instruction->get_related_instructions_next('retour_signature'), 'instruction'); |
2215 |
|
} |
2216 |
|
$val['external_uids'] = $val_external_uid; |
2217 |
|
} |
2218 |
|
if ($this->getVal('type') === 'notification_instruction' |
2219 |
|
|| $this->getVal('type') === 'notification_recepisse' |
2220 |
|
|| $this->getVal('type') === 'notification_decision' |
2221 |
|
|| $this->getVal('type') === 'notification_service_consulte' |
2222 |
|
|| $this->getVal('type') === 'notification_tiers_consulte' |
2223 |
|
|| $this->getVal('type') === 'notification_signataire') { |
2224 |
|
// |
2225 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2226 |
|
$dossier_id = isset($val['dossier']['dossier']) === true ? $val['dossier']['dossier'] : null; |
2227 |
|
$val['demandeur'] = $this->get_demandeurs_data($dossier_id); |
2228 |
|
$val['instruction_notification'] = $this->get_instruction_notification_data($this->getVal('category'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
2229 |
|
$instruction_id = isset($val['instruction_notification']['instruction']) === true ? $val['instruction_notification']['instruction'] : null; |
2230 |
|
$instruction_annexes = isset($val['instruction_notification']['annexes']) === true ? $val['instruction_notification']['annexes'] : null; |
2231 |
|
$val['instruction'] = $this->get_instruction_data($dossier_id, 'with-id', array('with-id' => $instruction_id)); |
2232 |
|
// Précise qu'il s'agit d'une instruction final si l'instruction est liée à une |
2233 |
|
// demande dont le type ne génère pas de dossier |
2234 |
|
if ($this->is_demande_instruction_recepisse_without_dossier($instruction_id) === true) { |
2235 |
|
$val['instruction']['final'] = 't'; |
2236 |
|
} |
2237 |
|
$val_external_uid = array(); |
2238 |
|
// Affiche l'identifiant externe lié à l'instruction si cette combinaison existe, sinon celui lié au dossier |
2239 |
|
$val_external_uid['demande'] = $this->get_external_uid($instruction_id, 'demande') !== '' ? $this->get_external_uid($instruction_id, 'demande') : $this->get_external_uid($dossier_id, 'demande'); |
2240 |
|
$val_external_uid['demande (instruction)'] = $this->get_external_uid($instruction_id, 'demande', PORTAL, 'ASC'); |
2241 |
|
$val_external_uid['instruction_notification'] = $this->get_external_uid($this->getVal('object_id'), 'instruction_notification', PORTAL); |
2242 |
|
$val['external_uids'] = $val_external_uid; |
2243 |
|
} |
2244 |
|
// |
2245 |
|
if ($this->getVal('type') === 'prescription') { |
2246 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2247 |
|
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
2248 |
|
$val['avis_decision'] = $this->get_avis_decision_data($this->getVal('dossier')); |
2249 |
|
if (isset($val['instruction']['signataire_arrete']) === true) { |
2250 |
|
$val['signataire_arrete'] = $this->get_signataire_arrete_data($val['instruction']['signataire_arrete']); |
2251 |
|
} |
2252 |
|
$val_external_uid = array(); |
2253 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2254 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2255 |
|
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
2256 |
|
$val_external_uid['prescription'] = $this->get_external_uid($this->getVal('object_id'), 'prescription'); |
2257 |
|
$val['external_uids'] = $val_external_uid; |
2258 |
|
} |
2259 |
} |
} |
2260 |
|
|
2261 |
if ($in_field === true) { |
if ($in_field === true) { |
2262 |
return json_encode($val, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
return json_encode($val, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
2263 |
} else { |
} else { |
2264 |
// Liste des valeurs affichée en JSON |
// Liste des valeurs affichée en JSON |
2265 |
printf(json_encode($val, JSON_UNESCAPED_SLASHES)); |
echo(json_encode($val, JSON_UNESCAPED_SLASHES)); |
2266 |
} |
} |
2267 |
} |
} |
2268 |
} |
} |
2277 |
'state' => $this->f->get_submitted_post_value('state') |
'state' => $this->f->get_submitted_post_value('state') |
2278 |
), |
), |
2279 |
); |
); |
2280 |
|
if ($this->f->get_submitted_post_value('comment') !== null) { |
2281 |
|
$params['comment'] = $this->f->get_submitted_post_value('comment'); |
2282 |
|
} |
2283 |
$update = $this->update_task($params); |
$update = $this->update_task($params); |
2284 |
$message_class = "valid"; |
$message_class = "valid"; |
2285 |
$message = $this->msg; |
$message = $this->msg; |
2296 |
} |
} |
2297 |
|
|
2298 |
// Sauvegarde de l'uid externe retourné |
// Sauvegarde de l'uid externe retourné |
2299 |
if ($this->f->get_submitted_post_value('external_uid') !== null) { |
$external_uid = $this->f->get_submitted_post_value('external_uid'); |
2300 |
|
if ($external_uid !== null) { |
2301 |
// |
// |
2302 |
$objects = $this->get_objects_by_task_type($this->getVal('type'), $this->getVal('stream')); |
$objects = $this->get_objects_by_task_type($this->getVal('type'), $this->getVal('stream')); |
2303 |
|
// Si l'identifiant externe contient le préfixe pour identifier les codes de suivi, |
2304 |
|
// le seul objet concerné sera celui du code de suivi |
2305 |
|
if (strpos($external_uid, self::CS_PREFIX) !== false) { |
2306 |
|
$objects = array('code-suivi', ); |
2307 |
|
$external_uid = str_replace(self::CS_PREFIX, '', $external_uid); |
2308 |
|
} |
2309 |
foreach ($objects as $object) { |
foreach ($objects as $object) { |
2310 |
$inst_lien = $this->f->get_inst__om_dbform(array( |
$inst_lien = $this->f->get_inst__om_dbform(array( |
2311 |
"obj" => "lien_id_interne_uid_externe", |
"obj" => "lien_id_interne_uid_externe", |
2312 |
"idx" => ']', |
"idx" => ']', |
2313 |
)); |
)); |
2314 |
if ($inst_lien->is_exists($object, $this->getVal('object_id'), $this->f->get_submitted_post_value('external_uid'), $this->getVal('dossier')) === false) { |
$object_id = $this->getVal('object_id'); |
2315 |
|
$is_exists = $inst_lien->is_exists($object, $object_id, $external_uid, $this->getVal('dossier')); |
2316 |
|
// Dans le cas spécifique de la mise à jour d'une notification |
2317 |
|
// et de la création d'une liaison d'identifiant pour l'objet demande, |
2318 |
|
// l'identifiant de l'objet n'est plus celui de la notification |
2319 |
|
// d'instruction mais celui du dossier d'instruction |
2320 |
|
if ($object === 'demande' |
2321 |
|
&& ($this->getVal('type') === 'notification_recepisse' |
2322 |
|
|| $this->getVal('type') === 'notification_instruction' |
2323 |
|
|| $this->getVal('type') === 'notification_decision' |
2324 |
|
|| $this->getVal('type') === 'notification_service_consulte' |
2325 |
|
|| $this->getVal('type') === 'notification_tiers_consulte' |
2326 |
|
|| $this->getVal('type') === 'notification_signataire')) { |
2327 |
|
// |
2328 |
|
$object_id = $this->getVal('dossier'); |
2329 |
|
// Il ne doit y avoir qu'une liaison entre le numéro du dossier interne et un uid externe de "demande" |
2330 |
|
$is_exists = $inst_lien->is_exists($object, $object_id, null, $this->getVal('dossier')); |
2331 |
|
} |
2332 |
|
if ($is_exists === false) { |
2333 |
$valF = array( |
$valF = array( |
2334 |
'lien_id_interne_uid_externe' => '', |
'lien_id_interne_uid_externe' => '', |
2335 |
'object' => $object, |
'object' => $object, |
2336 |
'object_id' => $this->getVal('object_id'), |
'object_id' => $object_id, |
2337 |
'external_uid' => $this->f->get_submitted_post_value('external_uid'), |
'external_uid' => $external_uid, |
2338 |
'dossier' => $this->getVal('dossier'), |
'dossier' => $this->getVal('dossier'), |
2339 |
|
'category' => $this->getVal('category'), |
2340 |
); |
); |
2341 |
$add = $inst_lien->ajouter($valF); |
$add = $inst_lien->ajouter($valF); |
2342 |
$message_class = "valid"; |
$message_class = "valid"; |
2361 |
$result = $this->add_task(array( |
$result = $this->add_task(array( |
2362 |
'val' => array( |
'val' => array( |
2363 |
'stream' => 'input', |
'stream' => 'input', |
2364 |
'json_payload' => html_entity_decode($this->f->get_submitted_post_value('json_payload')), |
'json_payload' => html_entity_decode($this->f->get_submitted_post_value('json_payload'), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401), |
2365 |
'type' => $this->f->get_submitted_post_value('type'), |
'type' => $this->f->get_submitted_post_value('type'), |
2366 |
|
'category' => $this->f->get_submitted_post_value('category'), |
2367 |
) |
) |
2368 |
)); |
)); |
2369 |
$message = sprintf( |
$message = sprintf( |
2385 |
} |
} |
2386 |
|
|
2387 |
function setLayout(&$form, $maj) { |
function setLayout(&$form, $maj) { |
2388 |
|
// |
2389 |
// Récupération du mode de l'action |
$form->setBloc('json_payload', 'D', '', 'col_6'); |
2390 |
$crud = $this->get_action_crud($maj); |
$fieldset_title_payload = __("json_payload (calculée)"); |
2391 |
|
if ($this->getVal('json_payload') !== "{}") { |
2392 |
// MODE different de CREER |
$fieldset_title_payload = __("json_payload"); |
2393 |
if ($maj != 0 || $crud != 'create') { |
} |
2394 |
$form->setBloc('json_payload', 'D', '', 'col_6'); |
$form->setFieldset('json_payload', 'DF', $fieldset_title_payload, "collapsible, startClosed"); |
2395 |
$form->setFieldset('json_payload', 'DF', __("json_payload"), "collapsible, startClosed"); |
$form->setBloc('json_payload', 'F'); |
2396 |
$form->setBloc('json_payload', 'F'); |
$form->setBloc('timestamp_log', 'DF', __("historique"), 'col_9 timestamp_log_jsontotab'); |
|
} |
|
|
$form->setBloc('timestamp_log', 'DF', '', 'col_9'); |
|
2397 |
} |
} |
2398 |
|
|
2399 |
/** |
/** |
2400 |
* [get_objects_by_task_type description] |
* Récupère le nom de l'objet à mentionner dans la table lien_id_interne_uid_externe |
2401 |
* @param [type] $type [description] |
* en fonction du type et du stream de la tâche. |
2402 |
* @return [type] [description] |
* |
2403 |
|
* @param string $type Type de la tâche |
2404 |
|
* @param string $stream Stream de la tâche |
2405 |
|
* |
2406 |
|
* @return array |
2407 |
*/ |
*/ |
2408 |
function get_objects_by_task_type($type, $stream = 'all') { |
function get_objects_by_task_type($type, $stream = 'all') { |
2409 |
$objects = array(); |
$objects = array(); |
2418 |
} |
} |
2419 |
if (in_array($type, array('create_DI', )) === true |
if (in_array($type, array('create_DI', )) === true |
2420 |
&& $stream === 'input') { |
&& $stream === 'input') { |
2421 |
$objects = array('dossier', 'dossier_autorisation', ); |
$objects = array('dossier', 'dossier_autorisation', 'demande', ); |
2422 |
} |
} |
2423 |
if (in_array($type, array('decision_DI', 'incompletude_DI', 'completude_DI', )) === true) { |
if (in_array($type, array( |
2424 |
|
'decision_DI', |
2425 |
|
'incompletude_DI', |
2426 |
|
'completude_DI', |
2427 |
|
'lettre_incompletude', |
2428 |
|
'lettre_majoration' |
2429 |
|
)) === true) { |
2430 |
$objects = array('instruction', ); |
$objects = array('instruction', ); |
2431 |
} |
} |
2432 |
|
if (in_array($type, array('envoi_CL', )) === true) { |
2433 |
|
$objects = array('instruction_action_cl', ); |
2434 |
|
} |
2435 |
if (in_array($type, array('pec_metier_consultation', )) === true |
if (in_array($type, array('pec_metier_consultation', )) === true |
2436 |
&& $stream === 'output') { |
&& $stream === 'output') { |
2437 |
$objects = array('pec_dossier_consultation', ); |
$objects = array('pec_dossier_consultation', ); |
2440 |
&& $stream === 'output') { |
&& $stream === 'output') { |
2441 |
$objects = array('avis_dossier_consultation', ); |
$objects = array('avis_dossier_consultation', ); |
2442 |
} |
} |
2443 |
|
if (in_array($type, array('prescription', )) === true |
2444 |
|
&& $stream === 'output') { |
2445 |
|
$objects = array('prescription', ); |
2446 |
|
} |
2447 |
if (in_array($type, array('ajout_piece', 'add_piece', )) === true) { |
if (in_array($type, array('ajout_piece', 'add_piece', )) === true) { |
2448 |
$objects = array('piece', ); |
$objects = array('piece', ); |
2449 |
} |
} |
2458 |
&& $stream === 'input') { |
&& $stream === 'input') { |
2459 |
$objects = array('avis_consultation', ); |
$objects = array('avis_consultation', ); |
2460 |
} |
} |
2461 |
|
if (in_array($type, array('create_message', )) === true |
2462 |
|
&& $stream === 'input') { |
2463 |
|
$objects = array('dossier_message', ); |
2464 |
|
} |
2465 |
|
if (in_array( |
2466 |
|
$type, |
2467 |
|
array( |
2468 |
|
'notification_recepisse', |
2469 |
|
'notification_instruction', |
2470 |
|
'notification_decision', |
2471 |
|
'notification_service_consulte', |
2472 |
|
'notification_tiers_consulte', |
2473 |
|
'notification_signataire', |
2474 |
|
) |
2475 |
|
) === true) { |
2476 |
|
$objects = array('instruction_notification', 'demande', ); |
2477 |
|
} |
2478 |
return $objects; |
return $objects; |
2479 |
} |
} |
2480 |
|
|
2481 |
|
/** |
2482 |
|
* Récupère les tables auxquelles pourrait être rattaché l'objet lié à la tâche, |
2483 |
|
* par rapport à son type. |
2484 |
|
* |
2485 |
|
* @param string $type Type de la tâche |
2486 |
|
* @param string $stream input ou output |
2487 |
|
* @return array |
2488 |
|
*/ |
2489 |
|
function get_tables_by_task_type($type, $stream = 'all') { |
2490 |
|
$tables = array(); |
2491 |
|
if (in_array($type, array('creation_DA', 'modification_DA', )) === true) { |
2492 |
|
$tables = array('dossier_autorisation', ); |
2493 |
|
} |
2494 |
|
if (in_array($type, array('creation_DI', 'depot_DI', )) === true) { |
2495 |
|
$tables = array('dossier', ); |
2496 |
|
} |
2497 |
|
if (in_array($type, array('qualification_DI', )) === true) { |
2498 |
|
$tables = array('instruction', 'dossier', ); |
2499 |
|
} |
2500 |
|
if (in_array($type, array('create_DI_for_consultation', )) === true) { |
2501 |
|
$tables = array('dossier', ); |
2502 |
|
} |
2503 |
|
if (in_array($type, array('create_DI', )) === true |
2504 |
|
&& $stream === 'input') { |
2505 |
|
$tables = array('dossier', 'dossier_autorisation', 'demande', ); |
2506 |
|
} |
2507 |
|
if (in_array($type, array( |
2508 |
|
'decision_DI', |
2509 |
|
'incompletude_DI', |
2510 |
|
'completude_DI', |
2511 |
|
'lettre_incompletude', |
2512 |
|
'lettre_majoration' |
2513 |
|
)) === true) { |
2514 |
|
$tables = array('instruction', ); |
2515 |
|
} |
2516 |
|
if (in_array($type, array('envoi_CL', )) === true) { |
2517 |
|
$objects = array('instruction', ); |
2518 |
|
} |
2519 |
|
if (in_array($type, array('pec_metier_consultation', )) === true |
2520 |
|
&& $stream === 'output') { |
2521 |
|
$tables = array('instruction', ); |
2522 |
|
} |
2523 |
|
if (in_array($type, array('avis_consultation', )) === true |
2524 |
|
&& $stream === 'output') { |
2525 |
|
$tables = array('instruction', ); |
2526 |
|
} |
2527 |
|
if (in_array($type, array('prescription', )) === true |
2528 |
|
&& $stream === 'output') { |
2529 |
|
$tables = array('instruction', ); |
2530 |
|
} |
2531 |
|
if (in_array($type, array('ajout_piece', 'add_piece', )) === true) { |
2532 |
|
$tables = array('document_numerise', ); |
2533 |
|
} |
2534 |
|
if (in_array($type, array('creation_consultation', )) === true) { |
2535 |
|
$tables = array('consultation', ); |
2536 |
|
} |
2537 |
|
if (in_array($type, array('pec_metier_consultation', )) === true |
2538 |
|
&& $stream === 'input') { |
2539 |
|
$tables = array('consultation', ); |
2540 |
|
} |
2541 |
|
if (in_array($type, array('avis_consultation', )) === true |
2542 |
|
&& $stream === 'input') { |
2543 |
|
$tables = array('consultation', ); |
2544 |
|
} |
2545 |
|
if (in_array($type, array('create_message', )) === true |
2546 |
|
&& $stream === 'input') { |
2547 |
|
$tables = array('dossier_message', ); |
2548 |
|
} |
2549 |
|
if (in_array( |
2550 |
|
$type, |
2551 |
|
array( |
2552 |
|
'notification_recepisse', |
2553 |
|
'notification_instruction', |
2554 |
|
'notification_decision', |
2555 |
|
'notification_service_consulte', |
2556 |
|
'notification_tiers_consulte', |
2557 |
|
'notification_signataire' |
2558 |
|
) |
2559 |
|
) === true) { |
2560 |
|
$tables = array('instruction_notification', ); |
2561 |
|
} |
2562 |
|
return $tables; |
2563 |
|
} |
2564 |
|
|
2565 |
|
/** |
2566 |
|
* Vérifie si l'objet référencé par la tâche existe en base de données. |
2567 |
|
* |
2568 |
|
* Récupère la liste des tables de référence associé à la tâche à partir |
2569 |
|
* du type de tâche et de son flux (input ou output). |
2570 |
|
* Pour chaque table potentiellement référencé par la tâche on essaye d'instancier |
2571 |
|
* l'objet correspondant à partir de l'identifiant de l'objet de référence de la tâche. |
2572 |
|
* Si l'élément instancié existe renvoie true sinon renvoie false. |
2573 |
|
* |
2574 |
|
* @param string|integer $taskObjectId : identifiant de l'objet de référence de la tâche |
2575 |
|
* @param string $taskType : type de la tâche |
2576 |
|
* @param string $taskStream : flux entrant (output - valeur par défaut) ou sortant (input) |
2577 |
|
* @return boolean |
2578 |
|
*/ |
2579 |
|
protected function does_referenced_object_exist($taskObjectId, string $taskType, string $taskStream = 'output') { |
2580 |
|
$refTables = $this->get_tables_by_task_type($taskType, $taskStream); |
2581 |
|
if (empty($refTables) === true) { |
2582 |
|
$this->f->addToLog( |
2583 |
|
sprintf( |
2584 |
|
__("Impossible de vérifier si l'objet de référence existe, car le type de task '%s' n'a pas de correspondance avec une table dans la méthode %s."), |
2585 |
|
$taskType, |
2586 |
|
"get_tables_by_task_type()" |
2587 |
|
), |
2588 |
|
DEBUG_MODE |
2589 |
|
); |
2590 |
|
return true; |
2591 |
|
} |
2592 |
|
foreach ($refTables as $table) { |
2593 |
|
$inst = $this->f->get_inst__om_dbform(array( |
2594 |
|
'obj' => $table, |
2595 |
|
'idx' => $taskObjectId |
2596 |
|
)); |
2597 |
|
if ($inst->exists() === true) { |
2598 |
|
return true; |
2599 |
|
} |
2600 |
|
} |
2601 |
|
return false; |
2602 |
|
} |
2603 |
|
|
2604 |
} |
} |