/[openfoncier]/trunk/obj/task.class.php
ViewVC logotype

Contents of /trunk/obj/task.class.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10036 - (show annotations)
Wed Apr 21 13:30:18 2021 UTC (3 years, 9 months ago) by softime
Original Path: branches/4.14.0-develop/obj/task.class.php
File size: 57319 byte(s)
* Correction d'ajout des tasks si flag depot_electronique
* Correction task creation_consultation si service_type platau

1 <?php
2 //$Id$
3 //gen openMairie le 14/04/2020 14:11
4
5 require_once "../gen/obj/task.class.php";
6
7 class task extends task_gen {
8
9 const STATUS_DRAFT = 'draft';
10 const STATUS_NEW = 'new';
11 const STATUS_PENDING = 'pending';
12 const STATUS_DONE = 'done';
13 const STATUS_ERROR = 'error';
14 const STATUS_DEBUG = 'debug';
15 const STATUS_ARCHIVED = 'archived';
16
17 /**
18 * Liste des types de tâche concernant les services instructeurs
19 */
20 const TASK_TYPE_SI = array(
21 'creation_DA',
22 'creation_DI',
23 'depot_DI',
24 'modification_DI',
25 'qualification_DI',
26 'decision_DI',
27 'incompletude_DI',
28 'completude_DI',
29 'ajout_piece',
30 'add_piece',
31 'creation_consultation',
32 );
33
34 /**
35 * Liste des types de tâche concernant les services consultés
36 */
37 const TASK_TYPE_SC = array(
38 'create_DI_for_consultation',
39 'avis_consultation',
40 'pec_metier_consultation',
41 );
42
43 /**
44 * Définition des actions disponibles sur la classe.
45 *
46 * @return void
47 */
48 public function init_class_actions() {
49 parent::init_class_actions();
50 //
51 $this->class_actions[998] = array(
52 "identifier" => "json_data",
53 "view" => "view_json_data",
54 "permission_suffix" => "consulter",
55 );
56 $this->class_actions[997] = array(
57 "identifier" => "json_data",
58 "view" => "post_update_task",
59 "permission_suffix" => "modifier",
60 );
61 $this->class_actions[996] = array(
62 "identifier" => "json_data",
63 "view" => "post_add_task",
64 "permission_suffix" => "ajouter",
65 );
66 }
67
68 public function setvalF($val = array()) {
69
70 // // les guillets doubles sont remplacés automatiquement par des simples
71 // // dans core/om_formulaire.clasS.php::recupererPostvar()
72 // // voir le ticket https://dev.atreal.fr/projets/openmairie/tracker/209
73 // // ceci est un hack sale temporaire en attendant résolution du ticket
74 // foreach(array('json_payload', 'timestamp_log') as $key) {
75 // if (isset($val[$key]) && ! empty($val[$key]) &&
76 // isset($_POST[$key]) && ! empty($_POST[$key])) {
77 // $submited_payload = $_POST[$key];
78 // if (! empty($submited_payload)) {
79 // $new_payload = str_replace("'", '"', $val[$key]);
80 // if ($new_payload == $submited_payload ||
81 // strpos($submited_payload, '"') === false) {
82 // $val[$key] = $new_payload;
83 // }
84 // else {
85 // $error_msg = sprintf(
86 // __("La convertion des guillemets de la payload JSON '%s' ".
87 // "n'est pas idempotente (courante: %s, postée: %s, convertie: %s)"),
88 // $key, var_export($val[$key], true), var_export($submited_payload, true),
89 // var_export($new_payload, true));
90 // $this->correct = false;
91 // $this->addToMessage($error_msg);
92 // $this->addToLog(__METHOD__."() erreur : $error_msg", DEBUG_MODE);
93 // return false;
94 // }
95 // }
96 // }
97 // }
98
99 parent::setvalF($val);
100
101 // XXX Ancien code : permet de ne pas avoir d'erreru lors de la modification d'une task
102 if (array_key_exists('timestamp_log', $val) === true) {
103 $this->valF['timestamp_log'] = str_replace("'", '"', $val['timestamp_log']);
104 }
105
106 // récupération de l'ID de l'objet existant
107 $id = property_exists($this, 'id') ? $this->id : null;
108 if(isset($val[$this->clePrimaire])) {
109 $id = $val[$this->clePrimaire];
110 } elseif(isset($this->valF[$this->clePrimaire])) {
111 $id = $this->valF[$this->clePrimaire];
112 }
113
114 // MODE MODIFIER
115 if (! empty($id)) {
116
117 // si aucune payload n'est fourni (devrait toujours être le cas)
118 if (! isset($val['json_payload']) || empty($val['json_payload'])) {
119
120 // récupère l'objet existant
121 $existing = $this->f->findObjectById(get_class($this), $id);
122 if (! empty($existing)) {
123
124 // récupère la payload de l'objet
125 $val['json_payload'] = $existing->getVal('json_payload');
126 $this->valF['json_payload'] = $existing->getVal('json_payload');
127 $this->f->addToLog(__METHOD__."() récupère la payload de la tâche existante ".
128 "'$id': ".$existing->getVal('json_payload'), EXTRA_VERBOSE_MODE);
129 }
130 }
131 }
132 }
133
134 /**
135 *
136 * @return array
137 */
138 function get_var_sql_forminc__champs() {
139 return array(
140 "task",
141 "type",
142 "state",
143 "object_id",
144 "dossier",
145 "stream",
146 "json_payload",
147 "timestamp_log",
148 );
149 }
150
151 function setType(&$form, $maj) {
152 parent::setType($form, $maj);
153
154 // Récupération du mode de l'action
155 $crud = $this->get_action_crud($maj);
156
157 // MODE CREER
158 if ($maj == 0 || $crud == 'create') {
159 $form->setType("state", "select");
160 $form->setType("stream", "select");
161 $form->setType("json_payload", "textarea");
162 }
163 // MDOE MODIFIER
164 if ($maj == 1 || $crud == 'update') {
165 $form->setType("state", "select");
166 $form->setType("stream", "select");
167 $form->setType("json_payload", "jsonprettyprint");
168 }
169 // MODE CONSULTER
170 if ($maj == 3 || $crud == 'read') {
171 $form->setType('dossier', 'link');
172 $form->setType('json_payload', 'jsonprettyprint');
173 }
174
175 }
176
177 /**
178 *
179 */
180 function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) {
181 if($maj < 2) {
182
183 $contenu = array();
184 foreach(array('DRAFT', 'NEW', 'PENDING', 'DONE', 'ERROR', 'DEBUG') as $key) {
185 $const_name = 'STATUS_'.$key;
186 $const_value = constant("self::$const_name");
187 $contenu[0][] = $const_value;
188 $contenu[1][] = __($const_value);
189 }
190
191 $form->setSelect("state", $contenu);
192
193 $contenu_stream =array();
194 $contenu_stream[0][0]="input";
195 $contenu_stream[1][0]=_('input');
196 $contenu_stream[0][1]="output";
197 $contenu_stream[1][1]=_('output');
198 $form->setSelect("stream", $contenu_stream);
199
200 }
201
202 if ($maj == 3) {
203 if ($this->getVal('stream') == 'output') {
204 $inst_dossier = $this->f->get_inst__om_dbform(array(
205 "obj" => "dossier",
206 "idx" => $form->val['dossier'],
207 ));
208
209 if($form->val['type'] == "creation_DA"){
210 $obj_link = 'dossier_autorisation';
211 } else {
212 $obj_link = 'dossier_instruction';
213 }
214
215 $params = array();
216 $params['obj'] = $obj_link;
217 $params['libelle'] = $inst_dossier->getVal('dossier');
218 $params['title'] = "Consulter le dossier";
219 $params['idx'] = $form->val['dossier'];
220 $form->setSelect("dossier", $params);
221 }
222 }
223 }
224
225 /**
226 * SETTER_FORM - setVal (setVal).
227 *
228 * @return void
229 */
230 function setVal(&$form, $maj, $validation, &$dnu1 = null, $dnu2 = null) {
231 // parent::setVal($form, $maj, $validation);
232 //
233 if ($this->getVal('stream') == "output") {
234 $form->setVal('json_payload', $this->view_form_json(true));
235 } else {
236 $form->setVal('json_payload', htmlentities($this->getVal('json_payload')));
237 }
238 }
239
240 function setLib(&$form, $maj) {
241 parent::setLib($form, $maj);
242
243 // Récupération du mode de l'action
244 $crud = $this->get_action_crud($maj);
245
246 // MODE different de CREER
247 if ($maj != 0 || $crud != 'create') {
248 $form->setLib('json_payload', '');
249 }
250 }
251
252 public function verifier($val = array(), &$dnu1 = null, $dnu2 = null) {
253 $ret = parent::verifier($val, $dnu1, $dnu2);
254
255 // une tâche entrante doit avoir un type et une payload non-vide
256 if (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') {
257 if (isset($this->valF['type']) === false) {
258 $this->correct = false;
259 $this->addToMessage(sprintf(
260 __("Le champ %s est obligatoire pour une tâche entrante."),
261 sprintf('<span class="bold">%s</span>', $this->getLibFromField('type'))
262 ));
263 $this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE);
264 }
265 if (isset($this->valF['json_payload']) === false) {
266 $this->correct = false;
267 $this->addToMessage(sprintf(
268 __("Le champ %s est obligatoire pour une tâche entrante."),
269 sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload'))
270 ));
271 $this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE);
272 }
273 }
274
275 // les JSONs doivent être décodables
276 foreach(array('json_payload', 'timestamp_log') as $key) {
277 if (isset($this->valF[$key]) && ! empty($this->valF[$key]) && (
278 is_array(json_decode($this->valF[$key], true)) === false
279 || json_last_error() !== JSON_ERROR_NONE)) {
280 $this->correct = false;
281 $champ_text = sprintf('<span class="bold">%s</span>', $this->getLibFromField($key));
282 $this->addToMessage(sprintf(
283 __("Le champ %s doit être dans un format JSON valide (erreur: %s).".
284 "<p>%s valF:</br><pre>%s</pre></p>".
285 "<p>%s val:</br><pre>%s</pre></p>".
286 "<p>%s POST:</br><pre>%s</pre></p>".
287 "<p>%s submitted POST value:</br><pre>%s</pre></p>"),
288 $champ_text,
289 json_last_error() !== JSON_ERROR_NONE ? json_last_error_msg() : __('invalide'),
290 $champ_text,
291 $this->valF[$key],
292 $champ_text,
293 $val[$key],
294 $champ_text,
295 isset($_POST[$key]) ? $_POST[$key] : '',
296 $champ_text,
297 $this->f->get_submitted_post_value($key)
298 ));
299 $this->addToLog(__METHOD__.'(): erreur JSON: '.$this->msg, DEBUG_MODE);
300 }
301 }
302
303 // une tâche entrante doit avoir une payload avec les clés requises
304 if ($this->correct && (isset($this->valF['stream']) === false ||
305 $this->valF['stream'] == 'input')) {
306
307 // décode la payload JSON
308 $json_payload = json_decode($this->valF['json_payload'], true);
309
310 // défini une liste de chemin de clés requises
311 $paths = array(
312 'external_uids/dossier'
313 );
314
315 // tâche de type création de DI/DA
316 if (isset($this->valF['type']) !== false && $this->valF['type'] == 'create_DI_for_consultation') {
317
318 $paths = array_merge($paths, array(
319 'dossier/dossier',
320 'dossier/dossier_autorisation_type_detaille_code',
321 'dossier/date_demande',
322 'dossier/depot_electronique',
323 ));
324
325 // si l'option commune est activée (mode MC)
326 if ($this->f->is_option_dossier_commune_enabled()) {
327 $paths[] = 'dossier/insee';
328 }
329
330 // présence d'un moyen d'identifier la collectivité/le service
331 if (! isset($json_payload['external_uids']['acteur']) &&
332 ! isset($json_payload['dossier']['om_collectivite'])) {
333 $this->correct = false;
334 $this->addToMessage(sprintf(
335 __("L'une des clés %s ou %s est obligatoire dans le contenu du champ %s pour une tâche entrante."),
336 sprintf('<span class="bold">%s</span>', 'external_uids/acteur'),
337 sprintf('<span class="bold">%s</span>', 'dossier/om_collectivite'),
338 sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload'))
339 ));
340 $this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE);
341 }
342 }
343
344 // pas d'erreur déjà trouvée
345 if($this->correct) {
346
347 // pour chaque chemin
348 foreach($paths as $path) {
349
350 // décompose le chemin
351 $tokens = explode('/', $path);
352 $cur_depth = $json_payload;
353
354 // descend au et à mesure dans l'arborescence du chemin
355 foreach($tokens as $token) {
356
357 // en vérifiant que chaque élément du chemin est défini et non-nul
358 if (isset($cur_depth[$token]) === false) {
359
360 // sinon on produit une erreur
361 $this->correct = false;
362 $this->addToMessage(sprintf(
363 __("La clé %s est obligatoire dans le contenu du champ %s pour une tâche entrante."),
364 sprintf('<span class="bold">%s</span>', $path),
365 sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload'))
366 ));
367 $this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE);
368 break 2;
369 }
370 $cur_depth = $cur_depth[$token];
371 }
372 }
373 }
374 }
375
376 return $ret && $this->correct;
377 }
378
379 protected function task_exists(string $type, string $object_id) {
380 $query = sprintf('
381 SELECT task
382 FROM %1$stask
383 WHERE state != \'%2$s\'
384 AND type = \'%3$s\'
385 AND object_id = \'%4$s\'
386 ',
387 DB_PREFIXE,
388 self::STATUS_DONE,
389 $type,
390 $object_id
391 );
392 $res = $this->f->get_one_result_from_db_query($query);
393 if ($res['result'] !== null && $res['result'] !== '') {
394 return $res['result'];
395 }
396 return false;
397 }
398
399 /**
400 * TRIGGER - triggerajouter.
401 *
402 * @param string $id
403 * @param null &$dnu1 @deprecated Ne pas utiliser.
404 * @param array $val Tableau des valeurs brutes.
405 * @param null $dnu2 @deprecated Ne pas utiliser.
406 *
407 * @return boolean
408 */
409 function triggerajouter($id, &$dnu1 = null, $val = array(), $dnu2 = null) {
410
411 // tâche entrante
412 if (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') {
413
414 // décode la paylod JSON pour extraire les données métiers à ajouter
415 // en tant que métadonnées de la tâche
416 $json_payload = json_decode($this->valF['json_payload'], true);
417
418 // si la tâche possède déjà une clé dossier
419 if (isset($json_payload['dossier']['dossier']) &&
420 ! empty($json_payload['dossier']['dossier'])) {
421 $this->valF["dossier"] = $json_payload['dossier']['dossier'];
422 }
423 }
424 }
425
426 /**
427 * TREATMENT - add_task
428 * Ajoute un enregistrement.
429 *
430 * @param array $params Tableau des paramètres
431 * @return boolean
432 */
433 public function add_task($params = array()) {
434 $this->begin_treatment(__METHOD__);
435
436 // Vérifie si la task doit être ajoutée en fonction du mode de l'application,
437 // seulement pour les tasks output
438 $task_types_si = self::TASK_TYPE_SI;
439 $task_types_sc = self::TASK_TYPE_SC;
440 $stream = isset($params['val']['stream']) === true ? $params['val']['stream'] : 'output';
441 if ($stream === 'output'
442 && isset($params['val']['type']) === true
443 && $this->f->is_option_mode_service_consulte_enabled() === true
444 && in_array($params['val']['type'], $task_types_sc) === false) {
445 //
446 return $this->end_treatment(__METHOD__, true);
447 }
448 if ($stream === 'output'
449 && isset($params['val']['type']) === true
450 && $this->f->is_option_mode_service_consulte_enabled() === false
451 && in_array($params['val']['type'], $task_types_si) === false) {
452 //
453 return $this->end_treatment(__METHOD__, true);
454 }
455
456 $timestamp_log = json_encode(array(
457 'creation_date' => date('Y-m-d H:i:s'),
458 ));
459
460 // Si la tâche est de type ajout_piece et de stream input alors on ajoute le fichier
461 // et on ajoute l'uid dans le champ json_payload avant l'ajout de la tâche
462 if (isset($params['val']['type'])
463 && $params['val']['type'] == "add_piece"
464 && isset($params['val']['stream'])
465 && $params['val']['stream'] == "input" ) {
466 //
467 $json_payload = json_decode($params['val']['json_payload'], true);
468 if (json_last_error() !== JSON_ERROR_NONE) {
469 $this->addToMessage(__("Le contenu JSON de la tâche n'est pas valide."));
470 return $this->end_treatment(__METHOD__, false);
471 }
472 $document_numerise = $json_payload['document_numerise'];
473 $file_content = base64_decode($document_numerise["file_content"]);
474 if ($file_content === false){
475 $this->addToMessage(__("Le contenu du fichier lié à la tâche n'a pas pu etre recupere."));
476 return $this->end_treatment(__METHOD__, false);
477 }
478 $metadata = array(
479 "filename" => $document_numerise['nom_fichier'],
480 "size" => strlen($file_content),
481 "mimetype" => $document_numerise['file_content_type'],
482 "date_creation" => $document_numerise['date_creation'],
483 );
484 $uid_fichier = $this->f->storage->create($file_content, $metadata, "from_content");
485 if ($uid_fichier === OP_FAILURE) {
486 $this->addToMessage(__("Erreur lors de la creation du fichier lié à la tâche."));
487 return $this->end_treatment(__METHOD__, false);
488 }
489 $json_payload["document_numerise"]["uid"] = $uid_fichier;
490 // Le fichier a été ajouté nous n'avons plus besoin du champ file_content dans la payload
491 unset($json_payload["document_numerise"]["file_content"]);
492 $params['val']['json_payload'] = json_encode($json_payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
493 }
494
495 // Mise à jour du DI
496 $valF = array(
497 'task' => '',
498 'type' => $params['val']['type'],
499 'timestamp_log' => $timestamp_log,
500 'state' => isset($params['val']['state']) === true ? $params['val']['state'] : self::STATUS_NEW,
501 'object_id' => isset($params['val']['object_id']) ? $params['val']['object_id'] : '',
502 'dossier' => isset($params['val']['dossier']) ? $params['val']['dossier'] : '',
503 'stream' => $stream,
504 'json_payload' => isset($params['val']['json_payload']) === true ? $params['val']['json_payload'] : '{}',
505 );
506
507 // tâche sortante
508 if($valF["stream"] == "output"){
509
510 // TODO expliquer ce code
511 $task_exists = $this->task_exists($valF['type'], $valF['object_id']);
512 if ($valF['type'] === 'modification_DI' && $task_exists === false) {
513 $task_exists = $this->task_exists('creation_DI', $valF['object_id']);
514 }
515 if ($task_exists !== false) {
516 $inst_task = $this->f->get_inst__om_dbform(array(
517 "obj" => "task",
518 "idx" => $task_exists,
519 ));
520 $update_state = $inst_task->getVal('state');
521 if (isset($params['update_val']['state']) === true) {
522 $update_state = $params['update_val']['state'];
523 }
524 $update_params = array(
525 'val' => array(
526 'state' => $update_state,
527 ),
528 );
529 return $inst_task->update_task($update_params);
530 }
531 }
532
533 $add = $this->ajouter($valF);
534 $this->addToLog(__METHOD__."(): retour de l'ajout de tâche: ".var_export($add, true), VERBOSE_MODE);
535 if ($add === false) {
536 $this->addToLog(__METHOD__."(): ".$this->msg, DEBUG_MODE);
537 return $this->end_treatment(__METHOD__, false);
538 }
539 return $this->end_treatment(__METHOD__, true);
540 }
541
542 /**
543 * TREATMENT - update_task
544 * Met à jour l'enregistrement instancié.
545 *
546 * @param array $params Tableau des paramètres
547 * @return boolean
548 */
549 public function update_task($params = array()) {
550 $this->begin_treatment(__METHOD__);
551 $timestamp_log = $this->get_timestamp_log();
552 if ($timestamp_log === false) {
553 $this->addToLog(__METHOD__."(): erreur timestamp log", DEBUG_MODE);
554 return $this->end_treatment(__METHOD__, false);
555 }
556 array_push($timestamp_log, array(
557 'modification_date' => date('Y-m-d H:i:s'),
558 'state' => $params['val']['state'],
559 'prev_state' => $this->getVal('state'),
560 ));
561 $timestamp_log = json_encode($timestamp_log);
562 $valF = array(
563 'task' => $this->getVal($this->clePrimaire),
564 'type' => $this->getVal('type'),
565 'timestamp_log' => $timestamp_log,
566 'state' => $params['val']['state'],
567 'object_id' => $this->getVal('object_id'),
568 'stream' => $this->getVal('stream'),
569 'dossier' => $this->getVal('dossier'),
570 'json_payload' => $this->getVal('json_payload'),
571 );
572 $update = $this->modifier($valF);
573 if ($update === false) {
574 $this->addToLog($this->msg, DEBUG_MODE);
575 return $this->end_treatment(__METHOD__, false);
576 }
577 return $this->end_treatment(__METHOD__, true);
578 }
579
580 /**
581 * Récupère le journal d'horodatage dans le champ timestamp_log de
582 * l'enregistrement instancié.
583 *
584 * @param array $params Tableau des paramètres
585 * @return array sinon false en cas d'erreur
586 */
587 protected function get_timestamp_log($params = array()) {
588 $val = $this->getVal('timestamp_log');
589 if ($val === '') {
590 $val = json_encode(array());
591 }
592 if($this->isJson($val) === false) {
593 return false;
594 }
595 return json_decode($val, true);
596 }
597
598 /**
599 * VIEW - view_json_data
600 * Affiche l'enregistrement dans le format JSON.
601 *
602 * @return void
603 */
604 public function view_json_data() {
605 $this->checkAccessibility();
606 $this->f->disableLog();
607 if ($this->getParameter('idx') !== ']'
608 && $this->getParameter('idx') !== '0') {
609 //
610 $this->view_form_json();
611 }
612 else {
613 $this->view_tab_json();
614 }
615 }
616
617 protected function view_tab_json() {
618 $where = '';
619 if ($this->f->get_submitted_get_value('state') !== null
620 && $this->f->get_submitted_get_value('state') !== '') {
621 //
622 $where = sprintf(' WHERE state = \'%s\' ', $this->f->get_submitted_get_value('state'));
623 }
624 $query = sprintf('
625 SELECT
626 *
627 FROM %1$stask
628 %2$s
629 ORDER BY task ASC
630 ',
631 DB_PREFIXE,
632 $where
633 );
634 $res = $this->f->get_all_results_from_db_query($query, true);
635 if ($res['code'] === 'KO') {
636 return false;
637 }
638 $list_tasks = array();
639 foreach ($res['result'] as $task) {
640 $task['timestamp_log'] = json_decode($task['timestamp_log'], true);
641 $task['dossier'] = $task['dossier'];
642 if ($task['type'] === 'ajout_piece') {
643 $val_dn = $this->get_document_numerise_data($task['object_id']);
644 }
645 if ($task['stream'] === 'output') {
646 $task['external_uids'] = $this->get_all_external_uids($task['dossier']);
647 }
648 $list_tasks[$task['task']] = $task;
649 }
650 printf(json_encode($list_tasks));
651 }
652
653 protected function get_dossier_data(string $dossier) {
654 $val_di = array();
655 $inst_di = $this->f->get_inst__om_dbform(array(
656 "obj" => "dossier",
657 "idx" => $dossier,
658 ));
659 $val_di = $inst_di->get_json_data();
660 if ($val_di['dossier_instruction_type_code'] === 'T') {
661 $val_di['date_decision_transfert'] = $val_di['date_decision'];
662 }
663 unset($val_di['initial_dt']);
664 unset($val_di['log_instructions']);
665 return $val_di;
666 }
667
668 protected function get_dossier_autorisation_data(string $da) {
669 $val_da = array();
670 $inst_da = $this->f->get_inst__om_dbform(array(
671 "obj" => "dossier_autorisation",
672 "idx" => $da,
673 ));
674 $val_da = $inst_da->get_json_data();
675 return $val_da;
676 }
677
678 protected function get_donnees_techniques_data(string $fk_idx, string $fk_field) {
679 $val_dt = array();
680 $inst_dt = $this->f->get_inst__by_other_idx(array(
681 "obj" => "donnees_techniques",
682 "fk_field" => $fk_field,
683 "fk_idx" => $fk_idx,
684 ));
685 $val_dt = array(
686 'donnees_techniques' => $inst_dt->getVal($inst_dt->clePrimaire),
687 'cerfa' => $inst_dt->getVal('cerfa'),
688 );
689 $val_dt = array_merge($val_dt, $inst_dt->get_donnees_techniques_applicables());
690 if (isset($val_dt['am_exist_date']) === true) {
691 $val_dt['am_exist_date_num'] = '';
692 if (is_numeric($val_dt['am_exist_date']) === true) {
693 $val_dt['am_exist_date_num'] = $val_dt['am_exist_date'];
694 }
695 }
696 // Correspond à la nomenclature de Plat'AU STATUT_INFO
697 $val_dt['tax_statut_info'] = 'Déclaré';
698 //
699 if ($inst_dt->is_tab_surf_ssdest_enabled() === true) {
700 $fields_tab_surf_dest = $inst_dt->get_fields_tab_surf_dest();
701 foreach ($fields_tab_surf_dest as $field) {
702 if (isset($val_dt[$field]) === true) {
703 unset($val_dt[$field]);
704 }
705 }
706 } else {
707 $fields_tab_surf_ssdest = $inst_dt->get_fields_tab_surf_ssdest();
708 foreach ($fields_tab_surf_ssdest as $field) {
709 if (isset($val_dt[$field]) === true) {
710 unset($val_dt[$field]);
711 }
712 }
713 }
714 // Correspond à la nouvelle ligne CERFA v7 dans le DENSI imposition 1.2.3
715 if (isset($val_dt['tax_su_non_habit_surf2']) === true
716 && isset($val_dt['tax_su_non_habit_surf3']) === true
717 && (($val_dt['tax_su_non_habit_surf2'] !== null
718 && $val_dt['tax_su_non_habit_surf2'] !== '')
719 || ($val_dt['tax_su_non_habit_surf3'] !== null
720 && $val_dt['tax_su_non_habit_surf3'] !== ''))) {
721 //
722 $val_dt['tax_su_non_habit_surf8'] = intval($val_dt['tax_su_non_habit_surf2']) + intval($val_dt['tax_su_non_habit_surf3']);
723 }
724 if (isset($val_dt['tax_su_non_habit_surf_stat2']) === true
725 && isset($val_dt['tax_su_non_habit_surf_stat3']) === true
726 && (($val_dt['tax_su_non_habit_surf_stat2'] !== null
727 && $val_dt['tax_su_non_habit_surf_stat2'] !== '')
728 || ($val_dt['tax_su_non_habit_surf_stat3'] !== null
729 && $val_dt['tax_su_non_habit_surf_stat3'] !== ''))) {
730 //
731 $val_dt['tax_su_non_habit_surf_stat8'] = intval($val_dt['tax_su_non_habit_surf_stat2']) + intval($val_dt['tax_su_non_habit_surf_stat3']);
732 }
733 // Cas particulier d'un projet réduit à l'extension d'une habitation existante
734 $particular_case = false;
735 $fields_tab_crea_loc_hab = $inst_dt->get_fields_tab_crea_loc_hab();
736 foreach ($fields_tab_crea_loc_hab as $field) {
737 if (isset($val_dt[$field]) === false
738 || (isset($val_dt[$field]) === true
739 && ($val_dt[$field] === null
740 || $val_dt[$field] === ''))) {
741 //
742 $particular_case = true;
743 }
744 }
745 if ($particular_case === true) {
746 if (isset($val_dt['tax_ext_pret']) === true
747 && $val_dt['tax_ext_pret'] === 'f') {
748 //
749 $val_dt['tax_su_princ_surf1'] = $val_dt['tax_surf_tot_cstr'];
750 $val_dt['tax_su_princ_surf_stat1'] = $val_dt['tax_surf_loc_stat'];
751 }
752 if (isset($val_dt['tax_ext_pret']) === true
753 && $val_dt['tax_ext_pret'] === 't') {
754 //
755 if (isset($val_dt['tax_ext_desc']) === true) {
756 if (preg_match('/[pP].*[lL].*[aA].*[iI]/', $val_dt['tax_ext_desc']) === 1
757 || preg_match('/[lL].*[lL].*[tT].*[sS]/', $val_dt['tax_ext_desc']) === 1) {
758 //
759 $val_dt['tax_su_princ_surf2'] = $val_dt['tax_surf_tot_cstr'];
760 $val_dt['tax_su_princ_surf_stat2'] = $val_dt['tax_surf_loc_stat'];
761 }
762 // if (preg_match('/[pP].*[tT].*[zZ]/', $val_dt['tax_ext_desc']) === 1) {
763 // $val_dt['tax_su_princ_surf4'] = $val_dt['tax_surf_tot_cstr'];
764 // $val_dt['tax_su_princ_surf_stat4'] = $val_dt['tax_surf_loc_stat'];
765 // }
766 // if (preg_match('/[pP].*[lL].*[uU].*[sS]/', $val_dt['tax_ext_desc']) === 1
767 // || preg_match('/[lL].*[eE].*[sS]/', $val_dt['tax_ext_desc']) === 1
768 // || preg_match('/[pP].*[sS].*[lL].*[aA]/', $val_dt['tax_ext_desc']) === 1
769 // || preg_match('/[pP].*[lL].*[sS]/', $val_dt['tax_ext_desc']) === 1
770 // || preg_match('/[lL].*[lL].*[sS]/', $val_dt['tax_ext_desc']) === 1) {
771 // //
772 // $val_dt['tax_su_princ_surf3'] = $val_dt['tax_surf_tot_cstr'];
773 // $val_dt['tax_su_princ_surf_stat3'] = $val_dt['tax_surf_loc_stat'];
774 // }
775 }
776 }
777 }
778 // Cas particulier de la surface taxable démolie
779 if (isset($val_dt['tax_surf_tot_demo']) === true
780 && isset($val_dt['tax_surf_tax_demo']) === true
781 && ($val_dt['tax_surf_tot_demo'] === null
782 || $val_dt['tax_surf_tot_demo'] === '')) {
783 //
784 $val_dt['tax_surf_tot_demo'] = $val_dt['tax_surf_tax_demo'];
785 }
786 return $val_dt;
787 }
788
789 /**
790 * Récupère la liste des objets distincts existants dans la table des liens
791 * entre identifiants internes et identifiants externes.
792 *
793 * @return array
794 */
795 protected function get_list_distinct_objects_external_link() {
796 $query = sprintf('
797 SELECT
798 DISTINCT(object)
799 FROM %1$slien_id_interne_uid_externe
800 ORDER BY object ASC
801 ',
802 DB_PREFIXE
803 );
804 $res = $this->f->get_all_results_from_db_query($query, true);
805 if ($res['code'] === 'KO') {
806 return array();
807 }
808 $result = array();
809 foreach ($res['result'] as $object) {
810 $result[] = $object['object'];
811 }
812 return $result;
813 }
814
815 protected function get_external_uid($fk_idx, string $fk_idx_2) {
816 $inst_external_uid = $this->f->get_inst__by_other_idx(array(
817 "obj" => "lien_id_interne_uid_externe",
818 "fk_field" => 'object_id',
819 "fk_idx" => $fk_idx,
820 "fk_field_2" => 'object',
821 "fk_idx_2" => $fk_idx_2,
822 ));
823 return $inst_external_uid->getVal('external_uid');
824 }
825
826 protected function get_all_external_uids($fk_idx, $link_objects = array()) {
827 if (count($link_objects) == 0) {
828 $link_objects = $this->get_list_distinct_objects_external_link();
829 }
830 $val_external_uid = array();
831 foreach ($link_objects as $link_object) {
832 $external_uid = $this->get_external_uid($fk_idx, $link_object);
833 if ($external_uid !== '' && $external_uid !== null) {
834 $val_external_uid[$link_object] = $external_uid;
835 }
836 }
837 return $val_external_uid;
838 }
839
840 protected function get_demandeurs_data(string $dossier) {
841 $val_demandeur = array();
842 $inst_di = $this->f->get_inst__om_dbform(array(
843 "obj" => "dossier",
844 "idx" => $dossier,
845 ));
846 $list_demandeurs = $inst_di->get_demandeurs();
847 foreach ($list_demandeurs as $demandeur) {
848 $inst_demandeur = $this->f->get_inst__om_dbform(array(
849 "obj" => "demandeur",
850 "idx" => $demandeur['demandeur'],
851 ));
852 $val_demandeur[$demandeur['demandeur']] = $inst_demandeur->get_json_data();
853 $val_demandeur[$demandeur['demandeur']]['petitionnaire_principal'] = $demandeur['petitionnaire_principal'];
854 }
855 return $val_demandeur;
856 }
857
858 protected function get_architecte_data($architecte = null) {
859 $val_architecte = null;
860 if ($architecte !== null
861 && $architecte !== '') {
862 //
863 $inst_architecte = $this->f->get_inst__om_dbform(array(
864 "obj" => "architecte",
865 "idx" => $architecte,
866 ));
867 $val_architecte = $inst_architecte->get_json_data();
868 }
869 return $val_architecte;
870 }
871
872 protected function get_instruction_data(string $dossier, $type = 'decision', $extra_params = array()) {
873 $val_instruction = null;
874 $instruction_with_doc = null;
875 $inst_di = $this->f->get_inst__om_dbform(array(
876 "obj" => "dossier",
877 "idx" => $dossier,
878 ));
879 $idx = null;
880 if ($type === 'decision') {
881 $idx = $inst_di->get_last_instruction_decision();
882 }
883 if ($type === 'incompletude') {
884 $idx = $inst_di->get_last_instruction_incompletude();
885 }
886 // XXX Permet de récupérer l'instruction par son identifiant
887 if ($type === 'with-id') {
888 $idx = $extra_params['with-id'];
889 }
890 $inst_instruction = $this->f->get_inst__om_dbform(array(
891 "obj" => "instruction",
892 "idx" => $idx,
893 ));
894 if (count($inst_instruction->val) > 0) {
895 $val_instruction = array();
896 $instruction_data = $inst_instruction->get_json_data();
897 $val_instruction = $this->sort_instruction_data($instruction_data, $val_instruction);
898 if ($instruction_data['om_fichier_instruction'] !== null
899 && $instruction_data['om_fichier_instruction'] !== '') {
900 //
901 $instruction_with_doc = $inst_instruction->getVal($inst_instruction->clePrimaire);
902 }
903 $inst_ev = $this->f->get_inst__om_dbform(array(
904 "obj" => "evenement",
905 "idx" => $inst_instruction->getVal('evenement'),
906 ));
907 if ($inst_ev->getVal('retour') === 't') {
908 $instructions_related = $inst_instruction->get_related_instructions();
909 foreach ($instructions_related as $instruction) {
910 if ($instruction !== null && $instruction !== '') {
911 $inst_related_instruction = $this->f->get_inst__om_dbform(array(
912 "obj" => "instruction",
913 "idx" => $instruction,
914 ));
915 $instruction_data = $inst_related_instruction->get_json_data();
916 $val_instruction = $this->sort_instruction_data($instruction_data, $val_instruction);
917 if ($instruction_data['om_fichier_instruction'] !== null
918 && $instruction_data['om_fichier_instruction'] !== '') {
919 //
920 $instruction_with_doc = $inst_related_instruction->getVal($inst_related_instruction->clePrimaire);
921 }
922 }
923 }
924 }
925 if ($instruction_with_doc !== null) {
926 //
927 $val_instruction['path'] = sprintf('%s&snippet=%s&obj=%s&champ=%s&id=%s', 'app/index.php?module=form', 'file', 'instruction', 'om_fichier_instruction', $instruction_with_doc);
928 }
929 }
930 return $val_instruction;
931 }
932
933 protected function sort_instruction_data(array $values, array $res) {
934 $fields = array(
935 "date_evenement",
936 "date_envoi_signature",
937 "date_retour_signature",
938 "date_envoi_rar",
939 "date_retour_rar",
940 "date_envoi_controle_legalite",
941 "date_retour_controle_legalite",
942 "signataire_arrete",
943 "om_fichier_instruction",
944 "tacite",
945 "lettretype",
946 );
947 foreach ($values as $key => $value) {
948 if (in_array($key, $fields) === true) {
949 if (array_key_exists($key, $res) === false
950 && $value !== null
951 && $value !== '') {
952 //
953 $res[$key] = $value;
954 } elseif ($key === 'tacite'
955 && $value === 't') {
956 //
957 $res[$key] = $value;
958 }
959 }
960 }
961 return $res;
962 }
963
964 protected function get_document_numerise_data(string $dn) {
965 $val_dn = array();
966 $inst_dn = $this->f->get_inst__om_dbform(array(
967 "obj" => "document_numerise",
968 "idx" => $dn,
969 ));
970 $val_dn = $inst_dn->get_json_data();
971 $val_dn['path'] = sprintf('%s&snippet=%s&obj=%s&champ=%s&id=%s', 'app/index.php?module=form', 'file', 'document_numerise', 'uid', $this->getVal('object_id'));
972 // Correspond à la nomenclature Plat'AU NATURE_PIECE
973 $val_dn['nature'] = $val_dn['document_numerise_nature_libelle'];
974 return $val_dn;
975 }
976
977 protected function get_parcelles_data(string $object, string $idx) {
978 $val_dp = array();
979 $inst_di = $this->f->get_inst__om_dbform(array(
980 "obj" => $object,
981 "idx" => $idx,
982 ));
983 $list_parcelles = $inst_di->get_parcelles();
984 $no_ordre = 1;
985 foreach ($list_parcelles as $parcelle) {
986 $val_dp[$parcelle[$object.'_parcelle']] = array(
987 $object.'_parcelle' => $parcelle[$object.'_parcelle'],
988 'libelle' => $parcelle['libelle'],
989 'no_ordre' => $no_ordre,
990 );
991 $no_ordre++;
992 }
993 return $val_dp;
994 }
995
996 protected function get_avis_decision_data(string $dossier) {
997 $inst_di = $this->f->get_inst__om_dbform(array(
998 "obj" => "dossier",
999 "idx" => $dossier,
1000 ));
1001 $ad = $inst_di->getVal('avis_decision');
1002 $val_ad = array();
1003 $inst_ad = $this->f->get_inst__om_dbform(array(
1004 "obj" => "avis_decision",
1005 "idx" => $ad,
1006 ));
1007 $val_ad = $inst_ad->get_json_data();
1008 $val_ad['txAvis'] = "Voir document joint";
1009 if (isset($val_ad['tacite']) === true
1010 && $val_ad['tacite'] === 't') {
1011 //
1012 $val_ad['txAvis'] = "Sans objet";
1013 }
1014 return $val_ad;
1015 }
1016
1017 protected function get_signataire_arrete_data(string $sa) {
1018 $inst_sa = $this->f->get_inst__om_dbform(array(
1019 "obj" => "signataire_arrete",
1020 "idx" => $sa,
1021 ));
1022 $val_sa = array_combine($inst_sa->champs, $inst_sa->val);
1023 foreach ($val_sa as $key => $value) {
1024 $val_sa[$key] = strip_tags($value);
1025 }
1026 return $val_sa;
1027 }
1028
1029 // XXX WIP
1030 protected function get_consultation_data(string $consultation) {
1031 $val_consultation = array();
1032 $inst_consultation = $this->f->get_inst__om_dbform(array(
1033 "obj" => "consultation",
1034 "idx" => $consultation,
1035 ));
1036 $val_consultation = $inst_consultation->get_json_data();
1037 $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'));
1038 $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'));
1039 return $val_consultation;
1040 }
1041
1042 // XXX WIP
1043 protected function get_service_data(string $service) {
1044 $val_service = array();
1045 $inst_service = $this->f->get_inst__om_dbform(array(
1046 "obj" => "service",
1047 "idx" => $service,
1048 ));
1049 $val_service = $inst_service->get_json_data();
1050 return $val_service;
1051 }
1052
1053 protected function view_form_json($in_field = false) {
1054 //
1055 if ($this->f->get_submitted_post_value('valid') === null) {
1056 // Liste des valeurs à afficher
1057 $val = array();
1058 //
1059 $val_task = array_combine($this->champs, $this->val);
1060 foreach ($val_task as $key => $value) {
1061 $val_task[$key] = strip_tags($value);
1062 }
1063 $val_task['timestamp_log'] = json_decode($val_task['timestamp_log'], true);
1064 $val['task'] = $val_task;
1065 //
1066 if ($this->getVal('type') === 'creation_DA') {
1067 $val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id'));
1068 $val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation');
1069 $val['dossier_autorisation_parcelle'] = $this->get_parcelles_data('dossier_autorisation', $val['dossier_autorisation']['dossier_autorisation']);
1070 $val_external_uid = array();
1071 $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier_autorisation']['dossier_autorisation'], 'dossier_autorisation');
1072 $val['external_uids'] = $val_external_uid;
1073 }
1074 //
1075 if ($this->getVal('type') === 'creation_DI'
1076 || $this->getVal('type') === 'modification_DI'
1077 || $this->getVal('type') === 'depot_DI') {
1078 //
1079 $val['dossier'] = $this->get_dossier_data($this->getVal('object_id'));
1080 $val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_instruction');
1081 $val['demandeur'] = $this->get_demandeurs_data($val['dossier']['dossier']);
1082 $architecte = isset($val['donnees_techniques']['architecte']) === true ? $val['donnees_techniques']['architecte'] : null;
1083 $val['architecte'] = $this->get_architecte_data($architecte);
1084 $val['dossier_parcelle'] = $this->get_parcelles_data('dossier', $val['dossier']['dossier']);
1085 $val_external_uid = array();
1086 $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation');
1087 $val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier');
1088 $val['external_uids'] = $val_external_uid;
1089 }
1090 //
1091 if ($this->getVal('type') === 'qualification_DI') {
1092 $val['dossier'] = $this->get_dossier_data($this->getVal('object_id'));
1093 $val_external_uid = array();
1094 $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation');
1095 $val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier');
1096 $val['external_uids'] = $val_external_uid;
1097 }
1098 //
1099 if ($this->getVal('type') === 'ajout_piece') {
1100 $val['document_numerise'] = $this->get_document_numerise_data($this->getVal('object_id'));
1101 $val['dossier'] = $this->get_dossier_data($val['document_numerise']['dossier']);
1102 $val_external_uid = array();
1103 $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation');
1104 $val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier');
1105 $val_external_uid['document_numerise'] = $this->get_external_uid($val['document_numerise']['document_numerise'], 'document_numerise');
1106 $val['external_uids'] = $val_external_uid;
1107 }
1108 //
1109 if ($this->getVal('type') === 'decision_DI') {
1110 $val['dossier'] = $this->get_dossier_data($this->getVal('dossier'));
1111 $val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id')));
1112 $val_external_uid = array();
1113 $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation');
1114 $val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier');
1115 $val['external_uids'] = $val_external_uid;
1116 }
1117 //
1118 if ($this->getVal('type') === 'incompletude_DI') {
1119 $val['dossier'] = $this->get_dossier_data($this->getVal('dossier'));
1120 $val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id')));
1121 $val_external_uid = array();
1122 $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation');
1123 $val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier');
1124 $val['external_uids'] = $val_external_uid;
1125 }
1126 //
1127 if ($this->getVal('type') === 'completude_DI') {
1128 $val['dossier'] = $this->get_dossier_data($this->getVal('dossier'));
1129 $val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id')));
1130 $val_external_uid = array();
1131 $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation');
1132 $val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier');
1133 $val['external_uids'] = $val_external_uid;
1134 }
1135 //
1136 if ($this->getVal('type') === 'pec_metier_consultation') {
1137 $val['dossier'] = $this->get_dossier_data($this->getVal('dossier'));
1138 $val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id')));
1139 $val_external_uid = array();
1140 $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation');
1141 $val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier');
1142 $val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation');
1143 $val['external_uids'] = $val_external_uid;
1144 }
1145 //
1146 if ($this->getVal('type') === 'avis_consultation') {
1147 $val['dossier'] = $this->get_dossier_data($this->getVal('dossier'));
1148 $val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id')));
1149 $val['avis_decision'] = $this->get_avis_decision_data($this->getVal('dossier'));
1150 if (isset($val['instruction']['signataire_arrete']) === true) {
1151 $val['signataire_arrete'] = $this->get_signataire_arrete_data($val['instruction']['signataire_arrete']);
1152 }
1153 $val_external_uid = array();
1154 $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation');
1155 $val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier');
1156 $val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation');
1157 $val['external_uids'] = $val_external_uid;
1158 }
1159 // XXX WIP
1160 if ($this->getVal('type') === 'creation_consultation') {
1161 //
1162 $val['dossier'] = $this->get_dossier_data($this->getVal('dossier'));
1163 $val['consultation'] = $this->get_consultation_data($this->getVal('object_id'));
1164 $val['service'] = $this->get_service_data($val['consultation']['service']);
1165 $val_external_uid = array();
1166 $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation');
1167 $val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier');
1168 $val['external_uids'] = $val_external_uid;
1169 }
1170
1171 if ($in_field === true) {
1172 return json_encode($val, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
1173 } else {
1174 // Liste des valeurs affichée en JSON
1175 printf(json_encode($val, JSON_UNESCAPED_SLASHES));
1176 }
1177 }
1178 }
1179
1180 function post_update_task() {
1181 // Mise à jour des valeurs
1182
1183 // Modification de l'état de la tâche
1184 if ($this->f->get_submitted_post_value('state') !== null) {
1185 $params = array(
1186 'val' => array(
1187 'state' => $this->f->get_submitted_post_value('state')
1188 ),
1189 );
1190 $update = $this->update_task($params);
1191 $message_class = "valid";
1192 $message = $this->msg;
1193 if ($update === false) {
1194 $this->addToLog($this->msg, DEBUG_MODE);
1195 $message_class = "error";
1196 $message = sprintf(
1197 '%s %s',
1198 __('Impossible de mettre à jour la tâche.'),
1199 __('Veuillez contacter votre administrateur.')
1200 );
1201 }
1202 $this->f->displayMessage($message_class, $message);
1203 }
1204
1205 // Sauvegarde de l'uid externe retourné
1206 if ($this->f->get_submitted_post_value('external_uid') !== null) {
1207 //
1208 $objects = $this->get_objects_by_task_type($this->getVal('type'), $this->getVal('stream'));
1209 foreach ($objects as $object) {
1210 $inst_lien = $this->f->get_inst__om_dbform(array(
1211 "obj" => "lien_id_interne_uid_externe",
1212 "idx" => ']',
1213 ));
1214 if ($inst_lien->is_exists($object, $this->getVal('object_id'), $this->f->get_submitted_post_value('external_uid'), $this->getVal('dossier')) === false) {
1215 $valF = array(
1216 'lien_id_interne_uid_externe' => '',
1217 'object' => $object,
1218 'object_id' => $this->getVal('object_id'),
1219 'external_uid' => $this->f->get_submitted_post_value('external_uid'),
1220 'dossier' => $this->getVal('dossier'),
1221 );
1222 $add = $inst_lien->ajouter($valF);
1223 $message_class = "valid";
1224 $message = $inst_lien->msg;
1225 if ($add === false) {
1226 $this->addToLog($inst_lien->msg, DEBUG_MODE);
1227 $message_class = "error";
1228 $message = sprintf(
1229 '%s %s',
1230 __("Impossible de mettre à jour le lien entre l'identifiant interne et l'identifiant de l'application externe."),
1231 __('Veuillez contacter votre administrateur.')
1232 );
1233 }
1234 $this->f->displayMessage($message_class, $message);
1235 }
1236 }
1237 }
1238 }
1239
1240 function post_add_task() {
1241 // TODO Tester de remplacer la ligne de json_payload par un $_POST
1242 $result = $this->add_task(array(
1243 'val' => array(
1244 'stream' => 'input',
1245 'json_payload' => html_entity_decode($this->f->get_submitted_post_value('json_payload')),
1246 'type' => $this->f->get_submitted_post_value('type'),
1247 )
1248 ));
1249 $message = sprintf(
1250 __("Tâche %s ajoutée avec succès"),
1251 $this->getVal($this->clePrimaire)).
1252 '<br/><br/>'.
1253 $this->msg;
1254 $message_class = "valid";
1255 if ($result === false){
1256 $this->addToLog($this->msg, DEBUG_MODE);
1257 $message_class = "error";
1258 $message = sprintf(
1259 '%s %s',
1260 __('Impossible d\'ajouter la tâche.'),
1261 __('Veuillez contacter votre administrateur.')
1262 );
1263 }
1264 $this->f->displayMessage($message_class, $message);
1265 }
1266
1267 function setLayout(&$form, $maj) {
1268
1269 // Récupération du mode de l'action
1270 $crud = $this->get_action_crud($maj);
1271
1272 // MODE different de CREER
1273 if ($maj != 0 || $crud != 'create') {
1274 $form->setBloc('json_payload', 'D', '', 'col_6');
1275 $form->setFieldset('json_payload', 'DF', __("json_payload"), "collapsible, startClosed");
1276 $form->setBloc('json_payload', 'F');
1277 }
1278 $form->setBloc('timestamp_log', 'DF', '', 'col_9');
1279 }
1280
1281 /**
1282 * [get_objects_by_task_type description]
1283 * @param [type] $type [description]
1284 * @return [type] [description]
1285 */
1286 function get_objects_by_task_type($type, $stream = 'all') {
1287 $objects = array();
1288 if (in_array($type, array('creation_DA', )) === true) {
1289 $objects = array('dossier_autorisation', );
1290 }
1291 if (in_array($type, array('creation_DI', 'depot_DI', 'notification_DI', 'qualification_DI', )) === true) {
1292 $objects = array('dossier', );
1293 }
1294 if (in_array($type, array('create_DI_for_consultation', )) === true) {
1295 $objects = array('dossier', 'dossier_consultation', );
1296 }
1297 if (in_array($type, array('decision_DI', 'incompletude_DI', 'completude_DI', )) === true) {
1298 $objects = array('instruction', );
1299 }
1300 if (in_array($type, array('pec_metier_consultation', )) === true
1301 && $stream === 'output') {
1302 $objects = array('pec_dossier_consultation', );
1303 }
1304 if (in_array($type, array('avis_consultation', )) === true
1305 && $stream === 'output') {
1306 $objects = array('avis_dossier_consultation', );
1307 }
1308 if (in_array($type, array('ajout_piece', 'add_piece', )) === true) {
1309 $objects = array('piece', );
1310 }
1311 if (in_array($type, array('creation_consultation', )) === true) {
1312 $objects = array('consultation', );
1313 }
1314 if (in_array($type, array('pec_metier_consultation', 'avis_consultation', )) === true
1315 && $stream === 'input') {
1316 $objects = array('consultation', );
1317 }
1318 return $objects;
1319 }
1320
1321 }

Properties

Name Value
svn:executable *

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26