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 |
20 |
|
*/ |
21 |
|
const TASK_TYPE_SI = array( |
22 |
|
'creation_DA', |
23 |
|
'creation_DI', |
24 |
|
'depot_DI', |
25 |
|
'modification_DI', |
26 |
|
'qualification_DI', |
27 |
|
'decision_DI', |
28 |
|
'incompletude_DI', |
29 |
|
'completude_DI', |
30 |
|
'ajout_piece', |
31 |
|
'add_piece', |
32 |
|
'creation_consultation', |
33 |
|
'modification_DA', |
34 |
|
'create_DI', |
35 |
|
'envoi_CL', |
36 |
|
'notification_recepisse', |
37 |
|
'notification_instruction', |
38 |
|
'notification_decision', |
39 |
|
'notification_service_consulte', |
40 |
|
'notification_tiers_consulte', |
41 |
|
); |
42 |
|
|
43 |
|
/** |
44 |
|
* Liste des types de tâche concernant les services consultés |
45 |
|
*/ |
46 |
|
const TASK_TYPE_SC = array( |
47 |
|
'create_DI_for_consultation', |
48 |
|
'avis_consultation', |
49 |
|
'pec_metier_consultation', |
50 |
|
'create_message', |
51 |
|
'notification_recepisse', |
52 |
|
'notification_instruction', |
53 |
|
'notification_decision', |
54 |
|
'notification_service_consulte', |
55 |
|
'notification_tiers_consulte', |
56 |
|
'prescription', |
57 |
|
); |
58 |
|
|
59 |
|
/** |
60 |
|
* Catégorie de la tâche |
61 |
|
*/ |
62 |
|
var $category = 'platau'; |
63 |
|
|
64 |
/** |
/** |
65 |
* Définition des actions disponibles sur la classe. |
* Définition des actions disponibles sur la classe. |
139 |
if (! isset($val['json_payload']) || empty($val['json_payload'])) { |
if (! isset($val['json_payload']) || empty($val['json_payload'])) { |
140 |
|
|
141 |
// récupère l'objet existant |
// récupère l'objet existant |
142 |
$existing = $this->f->findObjectById(get_class($this), $id); |
$existing = $this->f->findObjectById('task', $id); |
143 |
if (! empty($existing)) { |
if (! empty($existing)) { |
144 |
|
|
145 |
// récupère la payload de l'objet |
// récupère la payload de l'objet |
150 |
} |
} |
151 |
} |
} |
152 |
} |
} |
153 |
|
|
154 |
|
if (array_key_exists('category', $val) === false |
155 |
|
|| $this->valF['category'] === '' |
156 |
|
|| $this->valF['category'] === null) { |
157 |
|
// |
158 |
|
$this->valF['category'] = $this->category; |
159 |
|
} |
160 |
} |
} |
161 |
|
|
162 |
/** |
/** |
173 |
"stream", |
"stream", |
174 |
"json_payload", |
"json_payload", |
175 |
"timestamp_log", |
"timestamp_log", |
176 |
|
"category", |
177 |
); |
); |
178 |
} |
} |
179 |
|
|
183 |
// Récupération du mode de l'action |
// Récupération du mode de l'action |
184 |
$crud = $this->get_action_crud($maj); |
$crud = $this->get_action_crud($maj); |
185 |
|
|
186 |
|
// ALL |
187 |
|
$form->setType("category", "hidden"); |
188 |
|
|
189 |
// MODE CREER |
// MODE CREER |
190 |
if ($maj == 0 || $crud == 'create') { |
if ($maj == 0 || $crud == 'create') { |
191 |
$form->setType("state", "select"); |
$form->setType("state", "select"); |
213 |
if($maj < 2) { |
if($maj < 2) { |
214 |
|
|
215 |
$contenu = array(); |
$contenu = array(); |
216 |
foreach(array('DRAFT', 'NEW', 'PENDING', 'DONE', 'ERROR', 'DEBUG') as $key) { |
foreach(array('DRAFT', 'NEW', 'PENDING', 'DONE', 'ERROR', 'DEBUG', 'ARCHIVED', 'CANCELED') as $key) { |
217 |
$const_name = 'STATUS_'.$key; |
$const_name = 'STATUS_'.$key; |
218 |
$const_value = constant("self::$const_name"); |
$const_value = constant("self::$const_name"); |
219 |
$contenu[0][] = $const_value; |
$contenu[0][] = $const_value; |
220 |
$contenu[1][] = __($const_value); |
$contenu[1][] = $const_value; |
221 |
} |
} |
222 |
|
|
223 |
$form->setSelect("state", $contenu); |
$form->setSelect("state", $contenu); |
238 |
"idx" => $form->val['dossier'], |
"idx" => $form->val['dossier'], |
239 |
)); |
)); |
240 |
|
|
241 |
if($form->val['type'] == "creation_DA"){ |
if($form->val['type'] == "creation_DA" |
242 |
|
|| $form->val['type'] == "modification_DA"){ |
243 |
|
// |
244 |
$obj_link = 'dossier_autorisation'; |
$obj_link = 'dossier_autorisation'; |
245 |
} else { |
} else { |
246 |
$obj_link = 'dossier_instruction'; |
$obj_link = 'dossier_instruction'; |
342 |
$json_payload = json_decode($this->valF['json_payload'], true); |
$json_payload = json_decode($this->valF['json_payload'], true); |
343 |
|
|
344 |
// défini une liste de chemin de clés requises |
// défini une liste de chemin de clés requises |
345 |
$paths = array( |
$paths = array(); |
346 |
'external_uids/dossier' |
if ($this->valF['category'] === 'platau') { |
347 |
); |
$paths = array( |
348 |
|
'external_uids/dossier' |
349 |
|
); |
350 |
|
} |
351 |
|
|
352 |
// tâche de type création de DI/DA |
// tâche de type création de DI/DA |
353 |
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') { |
413 |
return $ret && $this->correct; |
return $ret && $this->correct; |
414 |
} |
} |
415 |
|
|
416 |
protected function task_exists(string $type, string $object_id) { |
/** |
417 |
|
* [task_exists description] |
418 |
|
* @param string $type [description] |
419 |
|
* @param string $object_id [description] |
420 |
|
* @param bool $is_not_done [description] |
421 |
|
* @return [type] [description] |
422 |
|
*/ |
423 |
|
public function task_exists(string $type, string $object_id, string $dossier = null, bool $is_not_done = true) { |
424 |
$query = sprintf(' |
$query = sprintf(' |
425 |
SELECT task |
SELECT task |
426 |
FROM %1$stask |
FROM %1$stask |
427 |
WHERE state != \'%2$s\' |
WHERE %2$s |
428 |
AND type = \'%3$s\' |
type = \'%3$s\' |
429 |
AND object_id = \'%4$s\' |
AND (object_id = \'%4$s\' |
430 |
|
%5$s) |
431 |
|
AND state != \'%6$s\' |
432 |
', |
', |
433 |
DB_PREFIXE, |
DB_PREFIXE, |
434 |
self::STATUS_DONE, |
$is_not_done == true ? 'state != \''.self::STATUS_DONE.'\' AND' : '', |
435 |
$type, |
$type, |
436 |
$object_id |
$object_id, |
437 |
|
$dossier !== null ? sprintf('OR dossier = \'%s\'', $dossier) : '', |
438 |
|
self::STATUS_CANCELED |
439 |
); |
); |
440 |
$res = $this->f->get_one_result_from_db_query($query); |
$res = $this->f->get_one_result_from_db_query($query); |
441 |
if ($res['result'] !== null && $res['result'] !== '') { |
if ($res['result'] !== null && $res['result'] !== '') { |
445 |
} |
} |
446 |
|
|
447 |
/** |
/** |
448 |
|
* Permet la recherche multi-critères des tasks. |
449 |
|
* |
450 |
|
* @param array $search_values Chaque entrée du tableau est une ligne dans le WHERE |
451 |
|
* @return mixed Retourne le résultat de la requête ou false |
452 |
|
*/ |
453 |
|
public function task_exists_multi_search(array $search_values) { |
454 |
|
$query = sprintf(' |
455 |
|
SELECT * |
456 |
|
FROM %1$stask |
457 |
|
%2$s |
458 |
|
%3$s |
459 |
|
', |
460 |
|
DB_PREFIXE, |
461 |
|
empty($search_values) === false ? ' WHERE ' : '', |
462 |
|
implode(' AND ', $search_values) |
463 |
|
); |
464 |
|
$res = $this->f->get_all_results_from_db_query($query); |
465 |
|
if (count($res['result']) > 0) { |
466 |
|
return $res['result']; |
467 |
|
} |
468 |
|
return false; |
469 |
|
} |
470 |
|
|
471 |
|
/** |
472 |
* TRIGGER - triggerajouter. |
* TRIGGER - triggerajouter. |
473 |
* |
* |
474 |
* @param string $id |
* @param string $id |
493 |
$this->valF["dossier"] = $json_payload['dossier']['dossier']; |
$this->valF["dossier"] = $json_payload['dossier']['dossier']; |
494 |
} |
} |
495 |
} |
} |
496 |
|
|
497 |
|
// gestion d'une tache de type notification et de category mail |
498 |
|
if (isset($val['type']) |
499 |
|
&& ((//$val['type'] === 'notification_recepisse' |
500 |
|
$val['type'] === 'notification_instruction' |
501 |
|
|| $val['type'] === 'notification_decision') |
502 |
|
&& isset($val['category']) |
503 |
|
&& $val['category'] === 'mail') |
504 |
|
|| $val['type'] === 'notification_service_consulte' |
505 |
|
|| $val['type'] === 'notification_tiers_consulte' |
506 |
|
) { |
507 |
|
// Récupère la payload de la tache |
508 |
|
$data = array(); |
509 |
|
// TODO : pour l'instant la gestion des notifs des demandeurs a été séparée |
510 |
|
// de celle des autres type de notif afin de ne pas risquer de casser l'existant |
511 |
|
// et pour des contraintes de temps. A optimiser plus tard |
512 |
|
if ($val['type'] === 'notification_service_consulte' |
513 |
|
|| $val['type'] === 'notification_tiers_consulte') { |
514 |
|
$data['instruction_notification'] = $this->get_instruction_notification_data_annexe_multiple( |
515 |
|
$this->valF['category'], |
516 |
|
'with-id', |
517 |
|
array('with-id' => $this->valF['object_id']) |
518 |
|
); |
519 |
|
} else { |
520 |
|
$data['instruction_notification'] = $this->get_instruction_notification_data( |
521 |
|
$this->valF['category'], |
522 |
|
'with-id', |
523 |
|
array('with-id' => $this->valF['object_id']) |
524 |
|
); |
525 |
|
} |
526 |
|
$data['dossier'] = $this->get_dossier_data($this->valF['dossier']); |
527 |
|
|
528 |
|
// Récupère l'instance de la notification |
529 |
|
$inst_notif = $this->f->get_inst__om_dbform(array( |
530 |
|
"obj" => "instruction_notification", |
531 |
|
"idx" => $val['object_id'], |
532 |
|
)); |
533 |
|
// Envoi le mail et met à jour le suivi |
534 |
|
$envoiMail = $inst_notif->send_mail_notification($data, $val['type']); |
535 |
|
// Passage de la tache à done si elle a réussi et à error |
536 |
|
// si l'envoi a échoué |
537 |
|
$this->valF['state'] = 'done'; |
538 |
|
if ($envoiMail === false) { |
539 |
|
$this->valF['state'] = 'error'; |
540 |
|
} |
541 |
|
} |
542 |
|
} |
543 |
|
|
544 |
|
/** |
545 |
|
* TRIGGER - triggermodifierapres. |
546 |
|
* |
547 |
|
* @param string $id |
548 |
|
* @param null &$dnu1 @deprecated Ne pas utiliser. |
549 |
|
* @param array $val Tableau des valeurs brutes. |
550 |
|
* @param null $dnu2 @deprecated Ne pas utiliser. |
551 |
|
* |
552 |
|
* @return boolean |
553 |
|
*/ |
554 |
|
public function triggermodifierapres($id, &$dnu1 = null, $val = array(), $dnu2 = null) { |
555 |
|
parent::triggermodifierapres($id, $dnu1, $val, $dnu2); |
556 |
|
|
557 |
|
// Suivi des notificiations |
558 |
|
// En cas de changement de l'état de la tâche de notification, alors |
559 |
|
// le suivi des dates de la notification et de l'instruction, est effectué |
560 |
|
if (isset($val['category']) === true |
561 |
|
&& $val['category'] === 'portal' |
562 |
|
&& isset($val['type']) === true |
563 |
|
&& ($val['type'] === 'notification_recepisse' |
564 |
|
|| $val['type'] === 'notification_instruction' |
565 |
|
|| $val['type'] === 'notification_decision' |
566 |
|
|| $val['type'] === 'notification_service_consulte' |
567 |
|
|| $val['type'] === 'notification_tiers_consulte')) { |
568 |
|
// |
569 |
|
if (isset($this->valF['state']) === true |
570 |
|
&& $this->valF['state'] !== $this->getVal('state') |
571 |
|
&& $this->valF['state'] !== self::STATUS_CANCELED) { |
572 |
|
// |
573 |
|
$inst_in = $this->f->get_inst__om_dbform(array( |
574 |
|
"obj" => "instruction_notification", |
575 |
|
"idx" => $val['object_id'], |
576 |
|
)); |
577 |
|
$valF_in = array(); |
578 |
|
foreach ($inst_in->champs as $champ) { |
579 |
|
$valF_in[$champ] = $inst_in->getVal($champ); |
580 |
|
} |
581 |
|
// Par défaut la date d'envoi et la date de premier accès sur |
582 |
|
// la notification ne sont pas renseignées |
583 |
|
$valF_in['date_envoi'] = null; |
584 |
|
$valF_in['date_premier_acces'] = null; |
585 |
|
// Lorsque la tâche est correctement traitée |
586 |
|
if ($this->valF['state'] === self::STATUS_DONE) { |
587 |
|
// |
588 |
|
$valF_in['statut'] = __("envoyé"); |
589 |
|
$valF_in['commentaire'] = __("Notification traitée"); |
590 |
|
$valF_in['date_envoi'] = date('d/m/Y H:i:s'); |
591 |
|
// Si l'instruction possède un document lié, alors ses dates |
592 |
|
// de suivi sont mises à jour |
593 |
|
$inst_instruction = $this->f->get_inst__om_dbform(array( |
594 |
|
"obj" => "instruction", |
595 |
|
"idx" => $inst_in->getVal('instruction'), |
596 |
|
)); |
597 |
|
if ($inst_instruction->has_an_edition() === true) { |
598 |
|
$valF_instruction = array(); |
599 |
|
foreach ($inst_instruction->champs as $champ) { |
600 |
|
$valF_instruction[$champ] = $inst_instruction->getVal($champ); |
601 |
|
} |
602 |
|
$valF_instruction['date_envoi_rar'] = date('d/m/Y'); |
603 |
|
$valF_instruction['date_retour_rar'] = date('d/m/Y', strtotime('now + 1 day')); |
604 |
|
$inst_instruction->setParameter('maj', 1); |
605 |
|
$update_instruction = $inst_instruction->modifier($valF_instruction); |
606 |
|
if ($update_instruction === false) { |
607 |
|
$this->addToLog(__METHOD__."(): ".$inst_instruction->msg, DEBUG_MODE); |
608 |
|
return false; |
609 |
|
} |
610 |
|
} |
611 |
|
} |
612 |
|
// En cas d'erreur lors du traitement de la task |
613 |
|
if ($this->valF['state'] === self::STATUS_ERROR) { |
614 |
|
$valF_in['statut'] = __("échec"); |
615 |
|
$valF_in['commentaire'] = __("Le traitement de la notification a échoué"); |
616 |
|
} |
617 |
|
// Met à jour la notification |
618 |
|
$inst_in->setParameter('maj', 1); |
619 |
|
$update_in = $inst_in->modifier($valF_in); |
620 |
|
if ($update_in === false) { |
621 |
|
$this->addToLog(__METHOD__."(): ".$inst_in->msg, DEBUG_MODE); |
622 |
|
return false; |
623 |
|
} |
624 |
|
} |
625 |
|
} |
626 |
|
|
627 |
|
// Envoi au contrôle de légalité |
628 |
|
// En cas de changement de l'état de la tâche envoi_CL, alors le suivi |
629 |
|
// des dates de l'instruction est effectué |
630 |
|
if ($val['type'] === 'envoi_CL' |
631 |
|
&& isset($this->valF['state']) === true |
632 |
|
&& $this->valF['state'] === self::STATUS_DONE) { |
633 |
|
// |
634 |
|
$inst_instruction = $this->f->get_inst__om_dbform(array( |
635 |
|
"obj" => "instruction", |
636 |
|
"idx" => $this->getVal('object_id'), |
637 |
|
)); |
638 |
|
if ($inst_instruction->has_an_edition() === true) { |
639 |
|
$valF_instruction = array(); |
640 |
|
foreach ($inst_instruction->champs as $champ) { |
641 |
|
$valF_instruction[$champ] = $inst_instruction->getVal($champ); |
642 |
|
} |
643 |
|
} |
644 |
|
$valF_instruction['date_envoi_controle_legalite'] = date("Y-m-d"); |
645 |
|
$inst_instruction->setParameter('maj', 1); |
646 |
|
$update_instruction = $inst_instruction->modifier($valF_instruction); |
647 |
|
if ($update_instruction === false) { |
648 |
|
$this->addToLog(__METHOD__."(): ".$inst_instruction->msg, DEBUG_MODE); |
649 |
|
return false; |
650 |
|
} |
651 |
|
} |
652 |
|
|
653 |
|
// |
654 |
|
return true; |
655 |
} |
} |
656 |
|
|
657 |
/** |
/** |
666 |
|
|
667 |
// Vérifie si la task doit être ajoutée en fonction du mode de l'application, |
// Vérifie si la task doit être ajoutée en fonction du mode de l'application, |
668 |
// seulement pour les tasks output |
// seulement pour les tasks output |
669 |
$task_types_si = array( |
$task_types_si = self::TASK_TYPE_SI; |
670 |
'creation_DA', |
$task_types_sc = self::TASK_TYPE_SC; |
|
'creation_DI', |
|
|
'depot_DI', |
|
|
'modification_DI', |
|
|
'qualification_DI', |
|
|
'decision_DI', |
|
|
'incompletude_DI', |
|
|
'completude_DI', |
|
|
'ajout_piece', |
|
|
'add_piece', |
|
|
); |
|
|
$task_types_sc = array( |
|
|
'create_DI_for_consultation', |
|
|
'avis_consultation', |
|
|
'pec_metier_consultation', |
|
|
); |
|
671 |
$stream = isset($params['val']['stream']) === true ? $params['val']['stream'] : 'output'; |
$stream = isset($params['val']['stream']) === true ? $params['val']['stream'] : 'output'; |
672 |
if ($stream === 'output' |
if ($stream === 'output' |
673 |
&& isset($params['val']['type']) === true |
&& isset($params['val']['type']) === true |
684 |
return $this->end_treatment(__METHOD__, true); |
return $this->end_treatment(__METHOD__, true); |
685 |
} |
} |
686 |
|
|
687 |
|
// |
688 |
$timestamp_log = json_encode(array( |
$timestamp_log = json_encode(array( |
689 |
'creation_date' => date('Y-m-d H:i:s'), |
'creation_date' => date('Y-m-d H:i:s'), |
690 |
)); |
)); |
691 |
|
|
692 |
|
// |
693 |
|
$category = isset($params['val']['category']) === true ? $params['val']['category'] : $this->category; |
694 |
|
|
695 |
// 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 |
696 |
// 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 |
697 |
if (isset($params['val']['type']) |
if (isset($params['val']['type']) |
698 |
&& $params['val']['type'] == "add_piece" |
&& ($params['val']['type'] == "add_piece" || $params['val']['type'] == "avis_consultation") |
699 |
&& isset($params['val']['stream']) |
&& isset($params['val']['stream']) |
700 |
&& $params['val']['stream'] == "input" ) { |
&& $params['val']['stream'] == "input" ) { |
701 |
// |
// |
704 |
$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.")); |
705 |
return $this->end_treatment(__METHOD__, false); |
return $this->end_treatment(__METHOD__, false); |
706 |
} |
} |
707 |
$document_numerise = $json_payload['document_numerise']; |
if (isset($json_payload['document_numerise']) === true |
708 |
$file_content = base64_decode($document_numerise["file_content"]); |
&& empty($json_payload['document_numerise']) === false) { |
709 |
if ($file_content === false){ |
// |
710 |
$this->addToMessage(__("Le contenu du fichier lié à la tâche n'a pas pu etre recupere.")); |
$document_numerise = $json_payload['document_numerise']; |
711 |
return $this->end_treatment(__METHOD__, false); |
$file_content = base64_decode($document_numerise["file_content"]); |
712 |
} |
if ($file_content === false){ |
713 |
$metadata = array( |
$this->addToMessage(__("Le contenu du fichier lié à la tâche n'a pas pu etre recupere.")); |
714 |
"filename" => $document_numerise['nom_fichier'], |
return $this->end_treatment(__METHOD__, false); |
715 |
"size" => strlen($file_content), |
} |
716 |
"mimetype" => $document_numerise['file_content_type'], |
$metadata = array( |
717 |
"date_creation" => $document_numerise['date_creation'], |
"filename" => $document_numerise['nom_fichier'], |
718 |
); |
"size" => strlen($file_content), |
719 |
$uid_fichier = $this->f->storage->create($file_content, $metadata, "from_content"); |
"mimetype" => $document_numerise['file_content_type'], |
720 |
if ($uid_fichier === OP_FAILURE) { |
"date_creation" => isset($document_numerise['date_creation']) === true ? $document_numerise['date_creation'] : date("Y-m-d"), |
721 |
$this->addToMessage(__("Erreur lors de la creation du fichier lié à la tâche.")); |
); |
722 |
return $this->end_treatment(__METHOD__, false); |
$uid_fichier = $this->f->storage->create($file_content, $metadata, "from_content", "task.uid_fichier"); |
723 |
|
if ($uid_fichier === OP_FAILURE) { |
724 |
|
$this->addToMessage(__("Erreur lors de la creation du fichier lié à la tâche.")); |
725 |
|
return $this->end_treatment(__METHOD__, false); |
726 |
|
} |
727 |
|
$json_payload["document_numerise"]["uid"] = $uid_fichier; |
728 |
|
// Le fichier a été ajouté nous n'avons plus besoin du champ file_content dans la payload |
729 |
|
unset($json_payload["document_numerise"]["file_content"]); |
730 |
|
$params['val']['json_payload'] = json_encode($json_payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
731 |
} |
} |
|
$json_payload["document_numerise"]["uid"] = $uid_fichier; |
|
|
// Le fichier a été ajouté nous n'avons plus besoin du champ file_content dans la payload |
|
|
unset($json_payload["document_numerise"]["file_content"]); |
|
|
$params['val']['json_payload'] = json_encode($json_payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
|
732 |
} |
} |
733 |
|
|
734 |
// Mise à jour du DI |
// Mise à jour du DI |
741 |
'dossier' => isset($params['val']['dossier']) ? $params['val']['dossier'] : '', |
'dossier' => isset($params['val']['dossier']) ? $params['val']['dossier'] : '', |
742 |
'stream' => $stream, |
'stream' => $stream, |
743 |
'json_payload' => isset($params['val']['json_payload']) === true ? $params['val']['json_payload'] : '{}', |
'json_payload' => isset($params['val']['json_payload']) === true ? $params['val']['json_payload'] : '{}', |
744 |
|
'category' => $category, |
745 |
); |
); |
746 |
|
|
747 |
// tâche sortante |
// tâche sortante |
748 |
if($valF["stream"] == "output"){ |
$typeNonConcerne = array( |
749 |
|
'notification_recepisse', |
750 |
|
'notification_instruction', |
751 |
|
'notification_decision', |
752 |
|
'notification_service_consulte', |
753 |
|
'notification_tiers_consulte' |
754 |
|
); |
755 |
|
if ($valF["stream"] == "output" |
756 |
|
&& ! in_array($valF['type'], $typeNonConcerne)) { |
757 |
// TODO expliquer ce code |
// TODO expliquer ce code |
758 |
$task_exists = $this->task_exists($valF['type'], $valF['object_id']); |
$task_exists = $this->task_exists($valF['type'], $valF['object_id'], $valF['dossier']); |
759 |
if ($valF['type'] === 'modification_DI' && $task_exists === false) { |
if ($valF['type'] === 'modification_DI' && $task_exists === false) { |
760 |
$task_exists = $this->task_exists('creation_DI', $valF['object_id']); |
$task_exists = $this->task_exists('creation_DI', $valF['object_id']); |
761 |
} |
} |
762 |
|
if ($valF['type'] === 'modification_DA' && $task_exists === false) { |
763 |
|
$task_exists = $this->task_exists('creation_DA', $valF['object_id']); |
764 |
|
} |
765 |
|
if ($valF['type'] === 'ajout_piece') { |
766 |
|
$task_exists = $this->task_exists('ajout_piece', $valF['object_id']); |
767 |
|
} |
768 |
|
if ($valF['type'] === 'creation_consultation') { |
769 |
|
$task_exists = $this->task_exists('creation_consultation', $valF['object_id']); |
770 |
|
} |
771 |
if ($task_exists !== false) { |
if ($task_exists !== false) { |
772 |
$inst_task = $this->f->get_inst__om_dbform(array( |
$inst_task = $this->f->get_inst__om_dbform(array( |
773 |
"obj" => "task", |
"obj" => "task", |
781 |
'val' => array( |
'val' => array( |
782 |
'state' => $update_state, |
'state' => $update_state, |
783 |
), |
), |
784 |
|
'object_id' => $valF['object_id'], |
785 |
); |
); |
786 |
return $inst_task->update_task($update_params); |
return $inst_task->update_task($update_params); |
787 |
} |
} |
788 |
} |
} |
|
|
|
789 |
$add = $this->ajouter($valF); |
$add = $this->ajouter($valF); |
790 |
$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); |
791 |
if ($add === false) { |
if ($add === false) { |
809 |
$this->addToLog(__METHOD__."(): erreur timestamp log", DEBUG_MODE); |
$this->addToLog(__METHOD__."(): erreur timestamp log", DEBUG_MODE); |
810 |
return $this->end_treatment(__METHOD__, false); |
return $this->end_treatment(__METHOD__, false); |
811 |
} |
} |
812 |
|
// Vérification des object_id précédent en cas de tentative d'appliquer |
813 |
|
// l'état CANCELED sur la tâche |
814 |
|
if (isset($params['val']['state']) === true |
815 |
|
&& $params['val']['state'] === self::STATUS_CANCELED) { |
816 |
|
// Récupération du journal d'activité de la tâche sous forme de tableau |
817 |
|
// trié par ordre décroissant |
818 |
|
$log = $timestamp_log; |
819 |
|
unset($log['creation_date']); |
820 |
|
krsort($log); |
821 |
|
// Pour chaque entrée dans le journal d'activité de la tâche : |
822 |
|
// - vérification de la présence de l'object_id précédent |
823 |
|
// - vérification que l'object_id précédent existe toujours dans la base de données |
824 |
|
// - l'object_id est mise à jour avec la valeur de l'object_id précédent |
825 |
|
// - le state n'est pas modifié |
826 |
|
// - sortie du traitement dès que le premier object_id précédent existant est trouvé |
827 |
|
// - si aucun object_id précédent existant n'est trouvé alors ni le state, ni l'object_id n'est modifiés |
828 |
|
foreach ($log as $key => $value) { |
829 |
|
// |
830 |
|
if (isset($value['prev_object_id']) === true |
831 |
|
&& $this->getVal('object_id') !== $value['prev_object_id']) { |
832 |
|
// Récupère la liste des tables potentielles pour un type de tâche |
833 |
|
$tables = $this->get_tables_by_task_type($this->getVal('type'), $this->getVal('stream')); |
834 |
|
foreach ($tables as $table) { |
835 |
|
// Vérifie s'il y a un ou aucun résultat |
836 |
|
$query = sprintf(' |
837 |
|
SELECT COUNT(%2$s) |
838 |
|
FROM %1$s%2$s |
839 |
|
WHERE %2$s::CHARACTER VARYING = \'%3$s\' |
840 |
|
', |
841 |
|
DB_PREFIXE, |
842 |
|
$table, |
843 |
|
$value['prev_object_id'] |
844 |
|
); |
845 |
|
$res = $this->f->get_one_result_from_db_query($query, true); |
846 |
|
if ($res['code'] === 'KO') { |
847 |
|
return $this->end_treatment(__METHOD__, false); |
848 |
|
} |
849 |
|
// Affectation des valeurs et sortie de la boucle |
850 |
|
if ($res['result'] == '1') { |
851 |
|
$params['object_id'] = $value['prev_object_id']; |
852 |
|
$params['val']['state'] = $this->getVal('state'); |
853 |
|
break; |
854 |
|
} |
855 |
|
} |
856 |
|
// Sortie de la boucle si les valeurs sont affectées |
857 |
|
if (isset($params['object_id']) === true |
858 |
|
&& $params['object_id'] === $value['prev_object_id']) { |
859 |
|
// |
860 |
|
break; |
861 |
|
} |
862 |
|
} |
863 |
|
} |
864 |
|
} |
865 |
|
// Mise à jour du journal d'activité de la tâche |
866 |
array_push($timestamp_log, array( |
array_push($timestamp_log, array( |
867 |
'modification_date' => date('Y-m-d H:i:s'), |
'modification_date' => date('Y-m-d H:i:s'), |
868 |
'state' => $params['val']['state'], |
'state' => $params['val']['state'], |
869 |
'prev_state' => $this->getVal('state'), |
'prev_state' => $this->getVal('state'), |
870 |
|
'object_id' => isset($params['object_id']) == true ? $params['object_id'] : $this->getVal('object_id'), |
871 |
|
'prev_object_id' => $this->getVal('object_id'), |
872 |
)); |
)); |
873 |
$timestamp_log = json_encode($timestamp_log); |
$timestamp_log = json_encode($timestamp_log); |
874 |
|
// Mise à jour de la tâche |
875 |
$valF = array( |
$valF = array( |
876 |
'task' => $this->getVal($this->clePrimaire), |
'task' => $this->getVal($this->clePrimaire), |
877 |
'type' => $this->getVal('type'), |
'type' => $this->getVal('type'), |
878 |
'timestamp_log' => $timestamp_log, |
'timestamp_log' => $timestamp_log, |
879 |
'state' => $params['val']['state'], |
'state' => $params['val']['state'], |
880 |
'object_id' => $this->getVal('object_id'), |
'object_id' => isset($params['object_id']) == true ? $params['object_id'] : $this->getVal('object_id'), |
881 |
'stream' => $this->getVal('stream'), |
'stream' => $this->getVal('stream'), |
882 |
'dossier' => $this->getVal('dossier'), |
'dossier' => $this->getVal('dossier'), |
883 |
'json_payload' => $this->getVal('json_payload'), |
'json_payload' => $this->getVal('json_payload'), |
884 |
|
'category' => $this->getVal('category'), |
885 |
); |
); |
886 |
$update = $this->modifier($valF); |
$update = $this->modifier($valF); |
887 |
if ($update === false) { |
if ($update === false) { |
933 |
if ($this->f->get_submitted_get_value('state') !== null |
if ($this->f->get_submitted_get_value('state') !== null |
934 |
&& $this->f->get_submitted_get_value('state') !== '') { |
&& $this->f->get_submitted_get_value('state') !== '') { |
935 |
// |
// |
936 |
$where = sprintf(' WHERE state = \'%s\' ', $this->f->get_submitted_get_value('state')); |
$where_or_and = 'WHERE'; |
937 |
|
if ($where !== '') { |
938 |
|
$where_or_and = 'AND'; |
939 |
|
} |
940 |
|
$where .= sprintf(' %s state = \'%s\' ', $where_or_and, $this->f->get_submitted_get_value('state')); |
941 |
|
} |
942 |
|
if ($this->f->get_submitted_get_value('category') !== null |
943 |
|
&& $this->f->get_submitted_get_value('category') !== '') { |
944 |
|
// |
945 |
|
$where_or_and = 'WHERE'; |
946 |
|
if ($where !== '') { |
947 |
|
$where_or_and = 'AND'; |
948 |
|
} |
949 |
|
$where .= sprintf(' %s category = \'%s\' ', $where_or_and, $this->f->get_submitted_get_value('category')); |
950 |
} |
} |
951 |
$query = sprintf(' |
$query = sprintf(' |
952 |
SELECT |
SELECT |
983 |
"obj" => "dossier", |
"obj" => "dossier", |
984 |
"idx" => $dossier, |
"idx" => $dossier, |
985 |
)); |
)); |
986 |
|
if (empty($inst_di->val) === true) { |
987 |
|
return $val_di; |
988 |
|
} |
989 |
$val_di = $inst_di->get_json_data(); |
$val_di = $inst_di->get_json_data(); |
990 |
if ($val_di['dossier_instruction_type_code'] === 'T') { |
if ($val_di['dossier_instruction_type_code'] === 'T') { |
991 |
$val_di['date_decision_transfert'] = $val_di['date_decision']; |
$val_di['date_decision_transfert'] = $val_di['date_decision']; |
1167 |
return $val_external_uid; |
return $val_external_uid; |
1168 |
} |
} |
1169 |
|
|
1170 |
protected function get_demandeurs_data(string $dossier) { |
protected function get_demandeurs_data($dossier) { |
1171 |
$val_demandeur = array(); |
$val_demandeur = array(); |
1172 |
|
if ($dossier === null) { |
1173 |
|
return $val_demandeur; |
1174 |
|
} |
1175 |
$inst_di = $this->f->get_inst__om_dbform(array( |
$inst_di = $this->f->get_inst__om_dbform(array( |
1176 |
"obj" => "dossier", |
"obj" => "dossier", |
1177 |
"idx" => $dossier, |
"idx" => $dossier, |
1202 |
return $val_architecte; |
return $val_architecte; |
1203 |
} |
} |
1204 |
|
|
1205 |
protected function get_instruction_data(string $dossier, $type = 'decision', $extra_params = array()) { |
protected function get_instruction_data($dossier, $type = 'decision', $extra_params = array()) { |
1206 |
$val_instruction = null; |
$val_instruction = null; |
1207 |
|
if ($dossier === null) { |
1208 |
|
return $val_instruction; |
1209 |
|
} |
1210 |
$instruction_with_doc = null; |
$instruction_with_doc = null; |
1211 |
$inst_di = $this->f->get_inst__om_dbform(array( |
$inst_di = $this->f->get_inst__om_dbform(array( |
1212 |
"obj" => "dossier", |
"obj" => "dossier", |
1266 |
return $val_instruction; |
return $val_instruction; |
1267 |
} |
} |
1268 |
|
|
1269 |
|
/** |
1270 |
|
* Récupère les informations |
1271 |
|
*/ |
1272 |
|
protected function get_instruction_notification_data($category, $type = '', $extra_params = array()) { |
1273 |
|
$val_in = null; |
1274 |
|
|
1275 |
|
$idx = null; |
1276 |
|
if ($type === 'with-id') { |
1277 |
|
$idx = $extra_params['with-id']; |
1278 |
|
} |
1279 |
|
|
1280 |
|
// récupére les données à intégrer à la payload |
1281 |
|
$inst_in = $this->f->get_inst__om_dbform(array( |
1282 |
|
"obj" => "instruction_notification", |
1283 |
|
"idx" => $idx, |
1284 |
|
)); |
1285 |
|
if (count($inst_in->val) > 0) { |
1286 |
|
$val_in = $inst_in->get_json_data(); |
1287 |
|
|
1288 |
|
$val_in['parametre_courriel_type_titre'] = ''; |
1289 |
|
$val_in['parametre_courriel_type_message'] = ''; |
1290 |
|
// Récupération du message et du titre |
1291 |
|
if ($category === 'mail') { |
1292 |
|
$inst_instruction = $this->f->get_inst__om_dbform(array( |
1293 |
|
"obj" => "instruction", |
1294 |
|
"idx" => $inst_in->getVal('instruction'), |
1295 |
|
)); |
1296 |
|
$collectivite_id = $inst_instruction->get_dossier_instruction_om_collectivite($inst_instruction->getVal('dossier')); |
1297 |
|
$phrase_type_notification = array(); |
1298 |
|
$phrase_type_notification = $this->f->get_notification_parametre_courriel_type($collectivite_id); |
1299 |
|
$val_in['parametre_courriel_type_titre'] = $phrase_type_notification['parametre_courriel_type_titre']; |
1300 |
|
$val_in['parametre_courriel_type_message'] = $phrase_type_notification['parametre_courriel_type_message']; |
1301 |
|
} |
1302 |
|
|
1303 |
|
// Récupération des liens vers les documents et de l'id de l'instruction |
1304 |
|
// de l'annexe |
1305 |
|
$infoDocNotif = $inst_in->getInfosDocumentsNotif($inst_in->getVal($inst_in->clePrimaire)); |
1306 |
|
$val_in['lien_telechargement_document'] = $infoDocNotif['document']['lien']; |
1307 |
|
$val_in['lien_telechargement_annexe'] = $infoDocNotif['annexe']['lien']; |
1308 |
|
$val_in['instruction_annexe'] = $infoDocNotif['annexe']['id_instruction']; |
1309 |
|
} |
1310 |
|
|
1311 |
|
return $val_in; |
1312 |
|
} |
1313 |
|
|
1314 |
|
/** |
1315 |
|
* Récupère les informations pour les notifications ayant plusieurs annexe |
1316 |
|
*/ |
1317 |
|
protected function get_instruction_notification_data_annexe_multiple($category, $type = '', $extra_params = array()) { |
1318 |
|
$val_in = null; |
1319 |
|
|
1320 |
|
$idx = null; |
1321 |
|
if ($type === 'with-id') { |
1322 |
|
$idx = $extra_params['with-id']; |
1323 |
|
} |
1324 |
|
|
1325 |
|
// récupére les données à intégrer à la payload |
1326 |
|
$inst_in = $this->f->get_inst__om_dbform(array( |
1327 |
|
"obj" => "instruction_notification", |
1328 |
|
"idx" => $idx, |
1329 |
|
)); |
1330 |
|
if (count($inst_in->val) > 0) { |
1331 |
|
$val_in = $inst_in->get_json_data(); |
1332 |
|
|
1333 |
|
$val_in['parametre_courriel_type_titre'] = ''; |
1334 |
|
$val_in['parametre_courriel_type_message'] = ''; |
1335 |
|
// Récupération du message et du titre |
1336 |
|
if ($category === 'mail') { |
1337 |
|
$inst_instruction = $this->f->get_inst__om_dbform(array( |
1338 |
|
"obj" => "instruction", |
1339 |
|
"idx" => $inst_in->getVal('instruction'), |
1340 |
|
)); |
1341 |
|
$collectivite_id = $inst_instruction->get_dossier_instruction_om_collectivite($inst_instruction->getVal('dossier')); |
1342 |
|
$phrase_type_notification = array(); |
1343 |
|
$phrase_type_notification = $this->f->get_notification_parametre_courriel_type($collectivite_id); |
1344 |
|
$val_in['parametre_courriel_type_titre'] = $phrase_type_notification['parametre_courriel_type_titre']; |
1345 |
|
$val_in['parametre_courriel_type_message'] = $phrase_type_notification['parametre_courriel_type_message']; |
1346 |
|
} |
1347 |
|
|
1348 |
|
// Récupération des liens vers les documents et de l'id de l'instruction |
1349 |
|
// de l'annexe |
1350 |
|
$infoDocNotif = $inst_in->getInfosDocumentsNotifAnnexeMultiple($inst_in->getVal($inst_in->clePrimaire)); |
1351 |
|
$val_in['lien_telechargement_document'] = $infoDocNotif['document']['lien']; |
1352 |
|
$val_in['annexes'] = $infoDocNotif['annexes']; |
1353 |
|
} |
1354 |
|
|
1355 |
|
return $val_in; |
1356 |
|
} |
1357 |
|
|
1358 |
protected function sort_instruction_data(array $values, array $res) { |
protected function sort_instruction_data(array $values, array $res) { |
1359 |
$fields = array( |
$fields = array( |
1360 |
"date_evenement", |
"date_evenement", |
1368 |
"om_fichier_instruction", |
"om_fichier_instruction", |
1369 |
"tacite", |
"tacite", |
1370 |
"lettretype", |
"lettretype", |
1371 |
|
"commentaire", |
1372 |
|
"complement_om_html", |
1373 |
); |
); |
1374 |
foreach ($values as $key => $value) { |
foreach ($values as $key => $value) { |
1375 |
if (in_array($key, $fields) === true) { |
if (in_array($key, $fields) === true) { |
1388 |
return $res; |
return $res; |
1389 |
} |
} |
1390 |
|
|
1391 |
|
/** |
1392 |
|
* Permet de définir si l'instruction passée en paramètre est une instruction |
1393 |
|
* récépissé d'une demande et si la demande en question a générée un dossier d'instruction. |
1394 |
|
* |
1395 |
|
* @param integer $instruction Identifiant de l'instruction |
1396 |
|
* @return boolean |
1397 |
|
*/ |
1398 |
|
protected function is_demande_instruction_recepisse_without_dossier($instruction) { |
1399 |
|
if ($instruction === null) { |
1400 |
|
return false; |
1401 |
|
} |
1402 |
|
$query = sprintf(' |
1403 |
|
SELECT demande_type.dossier_instruction_type |
1404 |
|
FROM %1$sdemande |
1405 |
|
INNER JOIN %1$sdemande_type ON demande.demande_type = demande_type.demande_type |
1406 |
|
WHERE demande.instruction_recepisse = %2$s |
1407 |
|
', |
1408 |
|
DB_PREFIXE, |
1409 |
|
$instruction |
1410 |
|
); |
1411 |
|
$res = $this->f->get_one_result_from_db_query( |
1412 |
|
$query, |
1413 |
|
true |
1414 |
|
); |
1415 |
|
if ($res['code'] === 'KO') { |
1416 |
|
return null; |
1417 |
|
} |
1418 |
|
if ($res['result'] === '') { |
1419 |
|
return true; |
1420 |
|
} |
1421 |
|
return false; |
1422 |
|
} |
1423 |
|
|
1424 |
protected function get_document_numerise_data(string $dn) { |
protected function get_document_numerise_data(string $dn) { |
1425 |
$val_dn = array(); |
$val_dn = array(); |
1426 |
$inst_dn = $this->f->get_inst__om_dbform(array( |
$inst_dn = $this->f->get_inst__om_dbform(array( |
1460 |
)); |
)); |
1461 |
$ad = $inst_di->getVal('avis_decision'); |
$ad = $inst_di->getVal('avis_decision'); |
1462 |
$val_ad = array(); |
$val_ad = array(); |
1463 |
$inst_ad = $this->f->get_inst__om_dbform(array( |
if ($ad !== null) { |
1464 |
"obj" => "avis_decision", |
$inst_ad = $this->f->get_inst__om_dbform(array( |
1465 |
"idx" => $ad, |
"obj" => "avis_decision", |
1466 |
)); |
"idx" => $ad, |
1467 |
$val_ad = $inst_ad->get_json_data(); |
)); |
1468 |
$val_ad['txAvis'] = "Voir document joint"; |
$val_ad = $inst_ad->get_json_data(); |
1469 |
if (isset($val_ad['tacite']) === true |
$val_ad['txAvis'] = "Voir document joint"; |
1470 |
&& $val_ad['tacite'] === 't') { |
if (isset($val_ad['tacite']) === true |
1471 |
// |
&& $val_ad['tacite'] === 't') { |
1472 |
$val_ad['txAvis'] = "Sans objet"; |
// |
1473 |
|
$val_ad['txAvis'] = "Sans objet"; |
1474 |
|
} |
1475 |
} |
} |
1476 |
return $val_ad; |
return $val_ad; |
1477 |
} |
} |
1488 |
return $val_sa; |
return $val_sa; |
1489 |
} |
} |
1490 |
|
|
1491 |
|
// XXX WIP |
1492 |
|
protected function get_consultation_data(string $consultation) { |
1493 |
|
$val_consultation = array(); |
1494 |
|
$inst_consultation = $this->f->get_inst__om_dbform(array( |
1495 |
|
"obj" => "consultation", |
1496 |
|
"idx" => $consultation, |
1497 |
|
)); |
1498 |
|
$val_consultation = $inst_consultation->get_json_data(); |
1499 |
|
if (isset($val_consultation['fichier']) === true |
1500 |
|
&& $val_consultation['fichier'] !== '') { |
1501 |
|
// |
1502 |
|
$val_consultation['path_fichier'] = sprintf('%s&snippet=%s&obj=%s&champ=%s&id=%s', 'app/index.php?module=form', 'file', 'consultation', 'fichier', $this->getVal('object_id')); |
1503 |
|
} |
1504 |
|
if (isset($val_consultation['om_fichier_consultation']) === true |
1505 |
|
&& $val_consultation['om_fichier_consultation'] !== '') { |
1506 |
|
// |
1507 |
|
$val_consultation['path_om_fichier_consultation'] = sprintf('%s&snippet=%s&obj=%s&champ=%s&id=%s', 'app/index.php?module=form', 'file', 'consultation', 'om_fichier_consultation', $this->getVal('object_id')); |
1508 |
|
} |
1509 |
|
return $val_consultation; |
1510 |
|
} |
1511 |
|
|
1512 |
|
// XXX WIP |
1513 |
|
protected function get_service_data(string $service) { |
1514 |
|
$val_service = array(); |
1515 |
|
$inst_service = $this->f->get_inst__om_dbform(array( |
1516 |
|
"obj" => "service", |
1517 |
|
"idx" => $service, |
1518 |
|
)); |
1519 |
|
$val_service = $inst_service->get_json_data(); |
1520 |
|
return $val_service; |
1521 |
|
} |
1522 |
|
|
1523 |
protected function view_form_json($in_field = false) { |
protected function view_form_json($in_field = false) { |
1524 |
// |
// |
1525 |
if ($this->f->get_submitted_post_value('valid') === null) { |
if ($this->f->get_submitted_post_value('valid') === null |
1526 |
|
&& $this->getVal('state') !== self::STATUS_CANCELED) { |
1527 |
// Liste des valeurs à afficher |
// Liste des valeurs à afficher |
1528 |
$val = array(); |
$val = array(); |
1529 |
// |
// |
1534 |
$val_task['timestamp_log'] = json_decode($val_task['timestamp_log'], true); |
$val_task['timestamp_log'] = json_decode($val_task['timestamp_log'], true); |
1535 |
$val['task'] = $val_task; |
$val['task'] = $val_task; |
1536 |
// |
// |
1537 |
if ($this->getVal('type') === 'creation_DA') { |
if ($this->getVal('type') === 'creation_DA' |
1538 |
|
|| $this->getVal('type') === 'modification_DA') { |
1539 |
|
// |
1540 |
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id')); |
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id')); |
1541 |
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation'); |
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation'); |
1542 |
$val['dossier_autorisation_parcelle'] = $this->get_parcelles_data('dossier_autorisation', $val['dossier_autorisation']['dossier_autorisation']); |
$val['dossier_autorisation_parcelle'] = $this->get_parcelles_data('dossier_autorisation', $val['dossier_autorisation']['dossier_autorisation']); |
1562 |
} |
} |
1563 |
// |
// |
1564 |
if ($this->getVal('type') === 'qualification_DI') { |
if ($this->getVal('type') === 'qualification_DI') { |
1565 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1566 |
$val_external_uid = array(); |
$val_external_uid = array(); |
1567 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1568 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1582 |
if ($this->getVal('type') === 'decision_DI') { |
if ($this->getVal('type') === 'decision_DI') { |
1583 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1584 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1585 |
|
$val['instruction']['final'] = 't'; |
1586 |
|
if (isset($val['instruction']['signataire_arrete']) === true) { |
1587 |
|
$val['signataire_arrete'] = $this->get_signataire_arrete_data($val['instruction']['signataire_arrete']); |
1588 |
|
} |
1589 |
$val_external_uid = array(); |
$val_external_uid = array(); |
1590 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1591 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1633 |
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
1634 |
$val['external_uids'] = $val_external_uid; |
$val['external_uids'] = $val_external_uid; |
1635 |
} |
} |
1636 |
|
// XXX WIP |
1637 |
|
if ($this->getVal('type') === 'creation_consultation') { |
1638 |
|
// |
1639 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1640 |
|
$val['consultation'] = $this->get_consultation_data($this->getVal('object_id')); |
1641 |
|
$val['service'] = $this->get_service_data($val['consultation']['service']); |
1642 |
|
$val_external_uid = array(); |
1643 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1644 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1645 |
|
$val['external_uids'] = $val_external_uid; |
1646 |
|
} |
1647 |
|
// |
1648 |
|
if ($this->getVal('type') === 'envoi_CL') { |
1649 |
|
// |
1650 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1651 |
|
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
1652 |
|
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($val['dossier']['dossier_autorisation']); |
1653 |
|
$val_external_uid = array(); |
1654 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1655 |
|
$val_external_uid['dossier'] = $this->get_external_uid($this->getVal('dossier'), 'dossier'); |
1656 |
|
$val_external_uid['decision'] = $this->get_external_uid($this->getVal('object_id'), 'instruction'); |
1657 |
|
if ($val_external_uid['decision'] === null) { |
1658 |
|
$inst_instruction = $this->f->get_inst__om_dbform(array( |
1659 |
|
"obj" => "instruction", |
1660 |
|
"idx" => $this->getVal('object_id'), |
1661 |
|
)); |
1662 |
|
$val_external_uid['decision'] = $this->get_external_uid($inst_instruction->get_related_instructions_next('retour_signature'), 'instruction'); |
1663 |
|
} |
1664 |
|
$val['external_uids'] = $val_external_uid; |
1665 |
|
} |
1666 |
|
// |
1667 |
|
if ($this->getVal('type') === 'notification_instruction' |
1668 |
|
|| $this->getVal('type') === 'notification_recepisse' |
1669 |
|
|| $this->getVal('type') === 'notification_decision') { |
1670 |
|
// |
1671 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1672 |
|
$dossier_id = isset($val['dossier']['dossier']) === true ? $val['dossier']['dossier'] : null; |
1673 |
|
$val['demandeur'] = $this->get_demandeurs_data($dossier_id); |
1674 |
|
$val['instruction_notification'] = $this->get_instruction_notification_data($this->getVal('category'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
1675 |
|
$instruction_id = isset($val['instruction_notification']['instruction']) === true ? $val['instruction_notification']['instruction'] : null; |
1676 |
|
$instruction_annexe = isset($val['instruction_notification']['instruction_annexe']) === true ? $val['instruction_notification']['instruction_annexe'] : null; |
1677 |
|
$val['instruction'] = $this->get_instruction_data($dossier_id, 'with-id', array('with-id' => $instruction_id)); |
1678 |
|
// Précise qu'il s'agit d'une instruction final si l'instruction est liée à une |
1679 |
|
// demande dont le type ne génère pas de dossier |
1680 |
|
if ($this->is_demande_instruction_recepisse_without_dossier($instruction_id) === true) { |
1681 |
|
$val['instruction']['final'] = 't'; |
1682 |
|
} |
1683 |
|
// |
1684 |
|
if ($instruction_annexe != '') { |
1685 |
|
$val['instruction_annexe'] = $this->get_instruction_data($dossier_id, 'with-id', array('with-id' => $instruction_annexe)); |
1686 |
|
} |
1687 |
|
$val_external_uid = array(); |
1688 |
|
// Affiche l'identifiant externe lié à l'instruction si cette combinaison existe, sinon celui lié au dossier |
1689 |
|
$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'); |
1690 |
|
$val['external_uids'] = $val_external_uid; |
1691 |
|
} |
1692 |
|
if ($this->getVal('type') === 'notification_service_consulte' |
1693 |
|
|| $this->getVal('type') === 'notification_tiers_consulte') { |
1694 |
|
// |
1695 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1696 |
|
$dossier_id = isset($val['dossier']['dossier']) === true ? $val['dossier']['dossier'] : null; |
1697 |
|
$val['demandeur'] = $this->get_demandeurs_data($dossier_id); |
1698 |
|
$val['instruction_notification'] = $this->get_instruction_notification_data_annexe_multiple($this->getVal('category'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
1699 |
|
$instruction_id = isset($val['instruction_notification']['instruction']) === true ? $val['instruction_notification']['instruction'] : null; |
1700 |
|
$instruction_annexes = isset($val['instruction_notification']['annexes']) === true ? $val['instruction_notification']['annexes'] : null; |
1701 |
|
$val['instruction'] = $this->get_instruction_data($dossier_id, 'with-id', array('with-id' => $instruction_id)); |
1702 |
|
// Précise qu'il s'agit d'une instruction final si l'instruction est liée à une |
1703 |
|
// demande dont le type ne génère pas de dossier |
1704 |
|
if ($this->is_demande_instruction_recepisse_without_dossier($instruction_id) === true) { |
1705 |
|
$val['instruction']['final'] = 't'; |
1706 |
|
} |
1707 |
|
// |
1708 |
|
if (is_array($instruction_annexes) && $instruction_annexes != array()) { |
1709 |
|
$val['instruction_annexe'] = array(); |
1710 |
|
$numAnnexe = 0; |
1711 |
|
foreach ($instruction_annexes as $annexe) { |
1712 |
|
if ($annexe['document_type'] === 'instruction') { |
1713 |
|
$val['instruction_annexe']['annexe_'.$numAnnexe++] = $this->get_instruction_data($dossier_id, 'with-id', array('with-id' => $annexe['document_id'])); |
1714 |
|
} elseif ($annexe['document_type'] === 'consultation') { |
1715 |
|
$val['instruction_annexe']['annexe_'.$numAnnexe++] = $this->get_consultation_data($annexe['document_id']); |
1716 |
|
} |
1717 |
|
} |
1718 |
|
} |
1719 |
|
$val_external_uid = array(); |
1720 |
|
// Affiche l'identifiant externe lié à l'instruction si cette combinaison existe, sinon celui lié au dossier |
1721 |
|
$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'); |
1722 |
|
$val['external_uids'] = $val_external_uid; |
1723 |
|
} |
1724 |
|
// |
1725 |
|
if ($this->getVal('type') === 'prescription') { |
1726 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1727 |
|
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
1728 |
|
$val['avis_decision'] = $this->get_avis_decision_data($this->getVal('dossier')); |
1729 |
|
if (isset($val['instruction']['signataire_arrete']) === true) { |
1730 |
|
$val['signataire_arrete'] = $this->get_signataire_arrete_data($val['instruction']['signataire_arrete']); |
1731 |
|
} |
1732 |
|
$val_external_uid = array(); |
1733 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1734 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1735 |
|
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
1736 |
|
$val['external_uids'] = $val_external_uid; |
1737 |
|
} |
1738 |
|
|
1739 |
if ($in_field === true) { |
if ($in_field === true) { |
1740 |
return json_encode($val, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
return json_encode($val, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
1741 |
} else { |
} else { |
1742 |
// Liste des valeurs affichée en JSON |
// Liste des valeurs affichée en JSON |
1743 |
printf(json_encode($val, JSON_UNESCAPED_SLASHES)); |
echo(json_encode($val, JSON_UNESCAPED_SLASHES)); |
1744 |
} |
} |
1745 |
} |
} |
1746 |
} |
} |
1773 |
// Sauvegarde de l'uid externe retourné |
// Sauvegarde de l'uid externe retourné |
1774 |
if ($this->f->get_submitted_post_value('external_uid') !== null) { |
if ($this->f->get_submitted_post_value('external_uid') !== null) { |
1775 |
// |
// |
1776 |
$objects = $this->get_objects_by_task_type($this->getVal('type')); |
$objects = $this->get_objects_by_task_type($this->getVal('type'), $this->getVal('stream')); |
1777 |
foreach ($objects as $object) { |
foreach ($objects as $object) { |
1778 |
$inst_lien = $this->f->get_inst__om_dbform(array( |
$inst_lien = $this->f->get_inst__om_dbform(array( |
1779 |
"obj" => "lien_id_interne_uid_externe", |
"obj" => "lien_id_interne_uid_externe", |
1780 |
"idx" => ']', |
"idx" => ']', |
1781 |
)); |
)); |
1782 |
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'); |
1783 |
|
// Dans le cas spécifique de la mise à jour d'une notification |
1784 |
|
// et de la création d'une liaison d'identifiant pour l'objet demande, |
1785 |
|
// l'identifiant de l'objet n'est plus celui de la notification |
1786 |
|
// d'instruction mais celui du dossier d'instruction |
1787 |
|
if ($object === 'demande' |
1788 |
|
&& ($this->getVal('type') === 'notification_recepisse' |
1789 |
|
|| $this->getVal('type') === 'notification_instruction' |
1790 |
|
|| $this->getVal('type') === 'notification_decision' |
1791 |
|
|| $this->getVal('type') === 'notification_service_consulte' |
1792 |
|
|| $this->getVal('type') === 'notification_tiers_consulte')) { |
1793 |
|
// |
1794 |
|
$object_id = $this->getVal('dossier'); |
1795 |
|
} |
1796 |
|
if ($inst_lien->is_exists($object, $object_id, $this->f->get_submitted_post_value('external_uid'), $this->getVal('dossier')) === false) { |
1797 |
$valF = array( |
$valF = array( |
1798 |
'lien_id_interne_uid_externe' => '', |
'lien_id_interne_uid_externe' => '', |
1799 |
'object' => $object, |
'object' => $object, |
1800 |
'object_id' => $this->getVal('object_id'), |
'object_id' => $object_id, |
1801 |
'external_uid' => $this->f->get_submitted_post_value('external_uid'), |
'external_uid' => $this->f->get_submitted_post_value('external_uid'), |
1802 |
'dossier' => $this->getVal('dossier'), |
'dossier' => $this->getVal('dossier'), |
1803 |
|
'category' => $this->getVal('category'), |
1804 |
); |
); |
1805 |
$add = $inst_lien->ajouter($valF); |
$add = $inst_lien->ajouter($valF); |
1806 |
$message_class = "valid"; |
$message_class = "valid"; |
1827 |
'stream' => 'input', |
'stream' => 'input', |
1828 |
'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')), |
1829 |
'type' => $this->f->get_submitted_post_value('type'), |
'type' => $this->f->get_submitted_post_value('type'), |
1830 |
|
'category' => $this->f->get_submitted_post_value('category'), |
1831 |
) |
) |
1832 |
)); |
)); |
1833 |
$message = sprintf( |
$message = sprintf( |
1863 |
} |
} |
1864 |
|
|
1865 |
/** |
/** |
1866 |
* [get_objects_by_task_type description] |
* Récupère le nom de l'objet à mentionner dans la table lien_id_interne_uid_externe |
1867 |
* @param [type] $type [description] |
* en fonction du type et du stream de la tâche. |
1868 |
* @return [type] [description] |
* |
1869 |
|
* @param string $type Type de la tâche |
1870 |
|
* @param string $stream Stream de la tâche |
1871 |
|
* |
1872 |
|
* @return array |
1873 |
*/ |
*/ |
1874 |
function get_objects_by_task_type($type) { |
function get_objects_by_task_type($type, $stream = 'all') { |
1875 |
$objects = array(); |
$objects = array(); |
1876 |
if (in_array($type, array('creation_DA', )) === true) { |
if (in_array($type, array('creation_DA', 'modification_DA', )) === true) { |
1877 |
$objects = array('dossier_autorisation', ); |
$objects = array('dossier_autorisation', ); |
1878 |
} |
} |
1879 |
if (in_array($type, array('creation_DI', 'depot_DI', 'notification_DI', 'qualification_DI', )) === true) { |
if (in_array($type, array('creation_DI', 'depot_DI', 'notification_DI', 'qualification_DI', )) === true) { |
1882 |
if (in_array($type, array('create_DI_for_consultation', )) === true) { |
if (in_array($type, array('create_DI_for_consultation', )) === true) { |
1883 |
$objects = array('dossier', 'dossier_consultation', ); |
$objects = array('dossier', 'dossier_consultation', ); |
1884 |
} |
} |
1885 |
|
if (in_array($type, array('create_DI', )) === true |
1886 |
|
&& $stream === 'input') { |
1887 |
|
$objects = array('dossier', 'dossier_autorisation', 'demande', ); |
1888 |
|
} |
1889 |
if (in_array($type, array('decision_DI', 'incompletude_DI', 'completude_DI', )) === true) { |
if (in_array($type, array('decision_DI', 'incompletude_DI', 'completude_DI', )) === true) { |
1890 |
$objects = array('instruction', ); |
$objects = array('instruction', ); |
1891 |
} |
} |
1892 |
if (in_array($type, array('pec_metier_consultation', )) === true) { |
if (in_array($type, array('envoi_CL', )) === true) { |
1893 |
|
$objects = array('instruction_action_cl', ); |
1894 |
|
} |
1895 |
|
if (in_array($type, array('pec_metier_consultation', )) === true |
1896 |
|
&& $stream === 'output') { |
1897 |
$objects = array('pec_dossier_consultation', ); |
$objects = array('pec_dossier_consultation', ); |
1898 |
} |
} |
1899 |
if (in_array($type, array('avis_consultation', )) === true) { |
if (in_array($type, array('avis_consultation', )) === true |
1900 |
|
&& $stream === 'output') { |
1901 |
$objects = array('avis_dossier_consultation', ); |
$objects = array('avis_dossier_consultation', ); |
1902 |
} |
} |
1903 |
|
if (in_array($type, array('prescription', )) === true |
1904 |
|
&& $stream === 'output') { |
1905 |
|
$objects = array('prescription', ); |
1906 |
|
} |
1907 |
if (in_array($type, array('ajout_piece', 'add_piece', )) === true) { |
if (in_array($type, array('ajout_piece', 'add_piece', )) === true) { |
1908 |
$objects = array('piece', ); |
$objects = array('piece', ); |
1909 |
} |
} |
1910 |
|
if (in_array($type, array('creation_consultation', )) === true) { |
1911 |
|
$objects = array('consultation', ); |
1912 |
|
} |
1913 |
|
if (in_array($type, array('pec_metier_consultation', )) === true |
1914 |
|
&& $stream === 'input') { |
1915 |
|
$objects = array('pec_metier_consultation', ); |
1916 |
|
} |
1917 |
|
if (in_array($type, array('avis_consultation', )) === true |
1918 |
|
&& $stream === 'input') { |
1919 |
|
$objects = array('avis_consultation', ); |
1920 |
|
} |
1921 |
|
if (in_array($type, array('create_message', )) === true |
1922 |
|
&& $stream === 'input') { |
1923 |
|
$objects = array('dossier_message', ); |
1924 |
|
} |
1925 |
|
if (in_array( |
1926 |
|
$type, |
1927 |
|
array( |
1928 |
|
'notification_recepisse', |
1929 |
|
'notification_instruction', |
1930 |
|
'notification_decision', |
1931 |
|
'notification_service_consulte', |
1932 |
|
'notification_tiers_consulte', |
1933 |
|
) |
1934 |
|
) === true) { |
1935 |
|
$objects = array('instruction_notification', 'demande', ); |
1936 |
|
} |
1937 |
return $objects; |
return $objects; |
1938 |
} |
} |
1939 |
|
|
1940 |
|
/** |
1941 |
|
* Récupère les tables auxquelles pourrait être rattaché l'objet lié à la tâche, |
1942 |
|
* par rapport à son type. |
1943 |
|
* |
1944 |
|
* @param string $type Type de la tâche |
1945 |
|
* @param string $stream input ou output |
1946 |
|
* @return array |
1947 |
|
*/ |
1948 |
|
function get_tables_by_task_type($type, $stream = 'all') { |
1949 |
|
$tables = array(); |
1950 |
|
if (in_array($type, array('creation_DA', 'modification_DA', )) === true) { |
1951 |
|
$tables = array('dossier_autorisation', ); |
1952 |
|
} |
1953 |
|
if (in_array($type, array('creation_DI', 'depot_DI', )) === true) { |
1954 |
|
$tables = array('dossier', ); |
1955 |
|
} |
1956 |
|
if (in_array($type, array('qualification_DI', )) === true) { |
1957 |
|
$tables = array('instruction', 'dossier', ); |
1958 |
|
} |
1959 |
|
if (in_array($type, array('create_DI_for_consultation', )) === true) { |
1960 |
|
$tables = array('dossier', ); |
1961 |
|
} |
1962 |
|
if (in_array($type, array('create_DI', )) === true |
1963 |
|
&& $stream === 'input') { |
1964 |
|
$tables = array('dossier', 'dossier_autorisation', 'demande', ); |
1965 |
|
} |
1966 |
|
if (in_array($type, array('decision_DI', 'incompletude_DI', 'completude_DI', )) === true) { |
1967 |
|
$tables = array('instruction', ); |
1968 |
|
} |
1969 |
|
if (in_array($type, array('pec_metier_consultation', )) === true |
1970 |
|
&& $stream === 'output') { |
1971 |
|
$tables = array('instruction', ); |
1972 |
|
} |
1973 |
|
if (in_array($type, array('avis_consultation', )) === true |
1974 |
|
&& $stream === 'output') { |
1975 |
|
$tables = array('instruction', ); |
1976 |
|
} |
1977 |
|
if (in_array($type, array('prescription', )) === true |
1978 |
|
&& $stream === 'output') { |
1979 |
|
$tables = array('instruction', ); |
1980 |
|
} |
1981 |
|
if (in_array($type, array('ajout_piece', 'add_piece', )) === true) { |
1982 |
|
$tables = array('document_numerise', ); |
1983 |
|
} |
1984 |
|
if (in_array($type, array('creation_consultation', )) === true) { |
1985 |
|
$tables = array('consultation', ); |
1986 |
|
} |
1987 |
|
if (in_array($type, array('pec_metier_consultation', )) === true |
1988 |
|
&& $stream === 'input') { |
1989 |
|
$tables = array('consultation', ); |
1990 |
|
} |
1991 |
|
if (in_array($type, array('avis_consultation', )) === true |
1992 |
|
&& $stream === 'input') { |
1993 |
|
$tables = array('consultation', ); |
1994 |
|
} |
1995 |
|
if (in_array($type, array('create_message', )) === true |
1996 |
|
&& $stream === 'input') { |
1997 |
|
$tables = array('dossier_message', ); |
1998 |
|
} |
1999 |
|
if (in_array( |
2000 |
|
$type, |
2001 |
|
array( |
2002 |
|
'notification_recepisse', |
2003 |
|
'notification_instruction', |
2004 |
|
'notification_decision', |
2005 |
|
'notification_service_consulte', |
2006 |
|
'notification_tiers_consulte' |
2007 |
|
) |
2008 |
|
) === true) { |
2009 |
|
$tables = array('instruction_notification', ); |
2010 |
|
} |
2011 |
|
return $tables; |
2012 |
|
} |
2013 |
|
|
2014 |
} |
} |