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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10362 - (show annotations)
Thu Sep 2 15:00:31 2021 UTC (3 years, 4 months ago) by cgarcin
Original Path: branches/5.0.0-develop/obj/task.class.php
File size: 59295 byte(s)
* Fusion de la branche de dev 5.0.0-develop-task-create-message dans la branche d'intégration 5.0.0-develop

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

Properties

Name Value
svn:executable *

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26