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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9765 - (show annotations)
Tue Dec 15 13:52:17 2020 UTC (4 years, 1 month ago) by gmalvolti
Original Path: branches/4.14.0-develop_demat/obj/task.class.php
File size: 42875 byte(s)
Fusion de la branche de développement 4.14.0-develop_ws_crea_di dans la branche d'intégration 4.14.0-develop_demat.

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 /**
10 * Définition des actions disponibles sur la classe.
11 *
12 * @return void
13 */
14 public function init_class_actions() {
15 parent::init_class_actions();
16 //
17 $this->class_actions[998] = array(
18 "identifier" => "json_data",
19 "view" => "view_json_data",
20 "permission_suffix" => "consulter",
21 );
22 $this->class_actions[997] = array(
23 "identifier" => "json_data",
24 "view" => "post_update_task",
25 "permission_suffix" => "modifier",
26 );
27 $this->class_actions[996] = array(
28 "identifier" => "json_data",
29 "view" => "post_add_task",
30 "permission_suffix" => "ajouter",
31 );
32 }
33
34 public function setvalF($val = array()) {
35 parent::setvalF($val);
36 //
37 if (array_key_exists('timestamp_log', $val) === true) {
38 $this->valF['timestamp_log'] = str_replace("'", '"', $val['timestamp_log']);
39 }
40 }
41
42 /**
43 *
44 * @return array
45 */
46 function get_var_sql_forminc__champs() {
47 return array(
48 "task",
49 "type",
50 "state",
51 "object_id",
52 "dossier",
53 "stream",
54 "json_payload",
55 "timestamp_log",
56 );
57 }
58
59 function setType(&$form, $maj) {
60 parent::setType($form, $maj);
61 // Récupération du mode de l'action
62 $crud = $this->get_action_crud($maj);
63
64 if ($maj < 2) {
65 $form->setType("state", "select");
66 $form->setType("stream", "select");
67 $form->setType("json_payload", "jsonprettyprint");
68 }
69 if ($maj == 3){
70 $form->setType('dossier', 'link');
71 $form->setType('json_payload', 'jsonprettyprint');
72 }
73
74 }
75
76 /**
77 *
78 */
79 function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) {
80 if($maj < 2) {
81 $contenu=array();
82
83 $contenu[0][0]="draft";
84 $contenu[1][0]=_('draft');
85 $contenu[0][1]="new";
86 $contenu[1][1]=_('new');
87 $contenu[0][2]="pending";
88 $contenu[1][2]=_('pending');
89 $contenu[0][3]="done";
90 $contenu[1][3]=_('done');
91 $contenu[0][4]="archived";
92 $contenu[1][4]=_('archived');
93 $contenu[0][5]="error";
94 $contenu[1][5]=_('error');
95 $contenu[0][6]="debug";
96 $contenu[1][6]=_('debug');
97
98 $form->setSelect("state", $contenu);
99
100 $contenu_stream =array();
101 $contenu_stream[0][0]="input";
102 $contenu_stream[1][0]=_('input');
103 $contenu_stream[0][1]="output";
104 $contenu_stream[1][1]=_('output');
105 $form->setSelect("stream", $contenu_stream);
106
107 }
108
109 if ($maj == 3) {
110 if ($this->getVal('stream') == 'output') {
111 $inst_dossier = $this->f->get_inst__om_dbform(array(
112 "obj" => "dossier",
113 "idx" => $form->val['dossier'],
114 ));
115
116 if($form->val['type'] == "creation_DA"){
117 $obj_link = 'dossier_autorisation';
118 } else {
119 $obj_link = 'dossier_instruction';
120 }
121
122 $params = array();
123 $params['obj'] = $obj_link;
124 $params['libelle'] = $inst_dossier->getVal('dossier');
125 $params['title'] = "Consulter le dossier";
126 $params['idx'] = $form->val['dossier'];
127 $form->setSelect("dossier", $params);
128 }
129 }
130 }
131
132 /**
133 * SETTER_FORM - setVal (setVal).
134 *
135 * @return void
136 */
137 function setVal(&$form, $maj, $validation, &$dnu1 = null, $dnu2 = null) {
138 // parent::setVal($form, $maj, $validation);
139 //
140 if ($this->getVal('stream') == "output") {
141 $form->setVal('json_payload', $this->view_form_json(true));
142 } else {
143 if ($this->getVal('type') == 'ajout_piece'){
144 // On modifie la valeur du champ "file_content" afin de tronquer le base64
145 $json_payload = json_decode($this->getVal("json_payload"), true);
146 $json_payload["document_numerise"]["file_content"] = substr($json_payload["document_numerise"]["file_content"], 0, 64)."[...]";
147 $json_payload_result = json_encode($json_payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
148 $form->setVal('json_payload', htmlentities($json_payload_result));
149 } else {
150 //
151 $form->setVal('json_payload', htmlentities($this->getVal('json_payload')));
152 }
153 }
154 }
155
156 function setLib(&$form, $maj) {
157 parent::setLib($form, $maj);
158 $form->setLib('json_payload', '');
159 }
160
161 public function verifier($val = array(), &$dnu1 = null, $dnu2 = null) {
162 $ret = parent::verifier($val, $dnu1, $dnu2);
163
164 if (array_key_exists('timestamp_log', $this->valF) === true
165 && is_array(json_decode($this->valF['timestamp_log'], true)) === false) {
166 //
167 $this->correct = false;
168 $this->addToMessage(sprintf(
169 __("Le champ %s doit être dans un format JSON valide."),
170 sprintf('<span class="bold">%s</span>', $this->getLibFromField('timestamp_log'))
171 ));
172 }
173
174 // une tâche entrante doit avoir un type et une payload non-vide
175 if (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') {
176 if (isset($this->valF['type']) === false) {
177 $this->correct = false;
178 $this->addToMessage(sprintf(
179 __("Le champ %s est obligatoire pour une tâche entrante."),
180 sprintf('<span class="bold">%s</span>', $this->getLibFromField('type'))
181 ));
182 $this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE);
183 }
184 if (isset($this->valF['json_payload']) === false) {
185 $this->correct = false;
186 $this->addToMessage(sprintf(
187 __("Le champ %s est obligatoire pour une tâche entrante."),
188 sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload'))
189 ));
190 $this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE);
191 }
192 }
193
194 // le JSON doit être décodable
195 if (isset($this->valF['json_payload']) && ! empty($this->valF['json_payload']) && (
196 is_array(json_decode($this->valF['json_payload'], true)) === false
197 || json_last_error() !== JSON_ERROR_NONE)) {
198 $this->correct = false;
199 $this->addToMessage(sprintf(
200 __("Le champ %s doit être dans un format JSON valide (erreur: %s)."),
201 sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload'),
202 json_last_error() !== JSON_ERROR_NONE ? json_last_error_msg() : __('invalide'))
203 ));
204 $this->addToLog(__METHOD__.'(): erreur JSON: '.$this->msg, DEBUG_MODE);
205 }
206
207 // une tâche entrante doit avoir une payload avec les clés requises
208 elseif (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') {
209
210 // décode la payload JSON
211 $json_payload = json_decode($this->valF['json_payload'], true);
212
213 // défini une liste de chemin de clés requises
214 $paths = array(
215 'dossier/dossier'
216 );
217
218 // tâche de type création de DI/DA
219 if (isset($this->valF['type']) !== false && $this->valF['type'] == 'creation_DI') {
220
221 $paths = array_merge($paths, array(
222 'dossier/dossier_autorisation_type_detaille',
223 'dossier/date_demande',
224 'dossier/depot_electronique',
225 ));
226
227 // si l'option commune est activée (mode MC)
228 if ($this->f->is_option_dossier_commune_enabled()) {
229 $paths[] = 'dossier/insee';
230 }
231
232 // présence d'un moyen d'identifier la collectivité/le service
233 if (! isset($json_payload['dossier']['acteur']) &&
234 ! isset($json_payload['dossier']['om_collectivite'])) {
235 $this->correct = false;
236 $this->addToMessage(sprintf(
237 __("L'une des clés %s ou %s est obligatoire dans le contenu du champ %s pour une tâche entrante."),
238 sprintf('<span class="bold">%s</span>', 'dossier/acteur'),
239 sprintf('<span class="bold">%s</span>', 'dossier/om_collectivite'),
240 sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload'))
241 ));
242 $this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE);
243 }
244 }
245
246 // pas d'erreur déjà trouvée
247 if($this->correct) {
248
249 // pour chaque chemin
250 foreach($paths as $path) {
251
252 // décompose le chemin
253 $tokens = explode('/', $path);
254 $cur_depth = $json_payload;
255
256 // descend au et à mesure dans l'arborescence du chemin
257 foreach($tokens as $token) {
258
259 // en vérifiant que chaque élément du chemin est défini et non-nul
260 if (isset($cur_depth[$token]) === false) {
261
262 // sinon on produit une erreur
263 $this->correct = false;
264 $this->addToMessage(sprintf(
265 __("La clé %s est obligatoire dans le contenu du champ %s pour une tâche entrante."),
266 sprintf('<span class="bold">%s</span>', $path),
267 sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload'))
268 ));
269 $this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE);
270 break 2;
271 }
272 $cur_depth = $cur_depth[$token];
273 }
274 }
275 }
276 }
277
278 return $ret && $this->correct;
279 }
280
281 protected function task_exists(string $type, string $object_id) {
282 $query = sprintf('
283 SELECT task
284 FROM %1$stask
285 WHERE state != \'%2$s\'
286 AND type = \'%3$s\'
287 AND object_id = \'%4$s\'
288 ',
289 DB_PREFIXE,
290 'done',
291 $type,
292 $object_id
293 );
294 $res = $this->f->get_one_result_from_db_query($query);
295 if ($res['result'] !== null && $res['result'] !== '') {
296 return $res['result'];
297 }
298 return false;
299 }
300
301 /**
302 * TRIGGER - triggerajouter.
303 *
304 * @param string $id
305 * @param null &$dnu1 @deprecated Ne pas utiliser.
306 * @param array $val Tableau des valeurs brutes.
307 * @param null $dnu2 @deprecated Ne pas utiliser.
308 *
309 * @return boolean
310 */
311 function triggerajouter($id, &$dnu1 = null, $val = array(), $dnu2 = null) {
312
313 // tâche entrante
314 if (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') {
315
316 // décode la paylod JSON pour extraire les données métiers à ajouter
317 // en tant que métadonnées de la tâche
318 $json_payload = json_decode($this->valF['json_payload'], true);
319 $this->valF["dossier"] = $json_payload['dossier']['dossier'];
320 }
321 }
322
323 /**
324 * TREATMENT - add_task
325 * Ajoute un enregistrement.
326 *
327 * @param array $params Tableau des paramètres
328 * @return boolean
329 */
330 public function add_task($params = array()) {
331 $this->begin_treatment(__METHOD__);
332 $timestamp_log = json_encode(array(
333 'creation_date' => date('Y-m-d H:i:s'),
334 ));
335
336 // Si la tâche est de type ajout_piece et de stream input alors on ajoute le fichier
337 // et on ajoute l'uid dans le champ json_payload avant l'ajout de la tâche
338 if (isset($params['val']['type'])
339 && $params['val']['type'] == "ajout_piece"
340 && isset($params['val']['stream'])
341 && $params['val']['stream'] == "input" ) {
342 //
343 $json_payload = json_decode($params['val']['json_payload'], true);
344 $document_numerise = $json_payload['document_numerise'];
345 $file_content = base64_decode($document_numerise["file_content"]);
346 if ($file_content === false){
347 $this->addToMessage(__("Le contenu du fichier lié à la tâche n'a pas pu etre recupere."));
348 return $this->end_treatment(__METHOD__, false);
349 }
350 $metadata = array(
351 "filename" => $document_numerise['nom_fichier'],
352 "size" => strlen($file_content),
353 "mimetype" => $document_numerise['file_content_type'],
354 "date_creation" => $document_numerise['date_creation'],
355 );
356 $uid_fichier = $this->f->storage->create($file_content, $metadata, "from_content");
357 if ($uid_fichier === OP_FAILURE) {
358 $this->addToMessage(__("Erreur lors de la creation du fichier lié à la tâche."));
359 return $this->end_treatment(__METHOD__, false);
360 }
361 $json_payload["document_numerise"]["uid"] = $uid_fichier;
362 $params['val']['json_payload'] = json_encode($json_payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
363 }
364
365 // Mise à jour du DI
366 $valF = array(
367 'task' => '',
368 'type' => $params['val']['type'],
369 'timestamp_log' => $timestamp_log,
370 'state' => isset($params['val']['state']) === true ? $params['val']['state'] : 'new',
371 'object_id' => isset($params['val']['object_id']) ? $params['val']['object_id'] : '',
372 'dossier' => isset($params['val']['dossier']) ? $params['val']['dossier'] : '',
373 'stream' => isset($params['val']['stream']) === true ? $params['val']['stream'] : 'output',
374 'json_payload' => isset($params['val']['json_payload']) === true ? $params['val']['json_payload'] : '{}',
375 );
376
377 // tâche sortante
378 if($valF["stream"] == "output"){
379
380 // TODO expliquer ce code
381 $task_exists = $this->task_exists($valF['type'], $valF['object_id']);
382 if ($valF['type'] === 'modification_DI' && $task_exists === false) {
383 $task_exists = $this->task_exists('creation_DI', $valF['object_id']);
384 }
385 if ($task_exists !== false) {
386 $inst_task = $this->f->get_inst__om_dbform(array(
387 "obj" => "task",
388 "idx" => $task_exists,
389 ));
390 $update_state = $inst_task->getVal('state');
391 if (isset($params['update_val']['state']) === true) {
392 $update_state = $params['update_val']['state'];
393 }
394 $update_params = array(
395 'val' => array(
396 'state' => $update_state,
397 ),
398 );
399 return $inst_task->update_task($update_params);
400 }
401 }
402
403 $add = $this->ajouter($valF);
404 $this->addToLog(__METHOD__."(): retour de l'ajout de tâche: ".var_export($add, true), DEBUG_MODE);
405 if ($add === false) {
406 $this->addToLog(__METHOD__."(): ".$this->msg, DEBUG_MODE);
407 return $this->end_treatment(__METHOD__, false);
408 }
409 return $this->end_treatment(__METHOD__, true);
410 }
411
412 /**
413 * TREATMENT - update_task
414 * Met à jour l'enregistrement instancié.
415 *
416 * @param array $params Tableau des paramètres
417 * @return boolean
418 */
419 public function update_task($params = array()) {
420 $this->begin_treatment(__METHOD__);
421 $timestamp_log = $this->get_timestamp_log();
422 if ($timestamp_log === false) {
423 $this->addToLog(__('XXX'), DEBUG_MODE);
424 return $this->end_treatment(__METHOD__, false);
425 }
426 array_push($timestamp_log, array(
427 'modification_date' => date('Y-m-d H:i:s'),
428 'state' => $params['val']['state'],
429 'prev_state' => $this->getVal('state'),
430 ));
431 $timestamp_log = json_encode($timestamp_log);
432 $valF = array(
433 'task' => $this->getVal($this->clePrimaire),
434 'type' => $this->getVal('type'),
435 'timestamp_log' => $timestamp_log,
436 'state' => $params['val']['state'],
437 'object_id' => $this->getVal('object_id'),
438 'stream' => $this->getVal('stream'),
439 'dossier' => $this->getVal('dossier'),
440 'json_payload' => $this->getVal('json_payload'),
441 );
442 $update = $this->modifier($valF);
443 if ($update === false) {
444 $this->addToLog($this->msg, DEBUG_MODE);
445 return $this->end_treatment(__METHOD__, false);
446 }
447 return $this->end_treatment(__METHOD__, true);
448 }
449
450 /**
451 * Récupère le journal d'horodatage dans le champ timestamp_log de
452 * l'enregistrement instancié.
453 *
454 * @param array $params Tableau des paramètres
455 * @return array sinon false en cas d'erreur
456 */
457 protected function get_timestamp_log($params = array()) {
458 $val = $this->getVal('timestamp_log');
459 if ($val === '') {
460 $val = json_encode(array());
461 }
462 if($this->isJson($val) === false) {
463 return false;
464 }
465 return json_decode($val, true);
466 }
467
468 /**
469 * VIEW - view_json_data
470 * Affiche l'enregistrement dans le format JSON.
471 *
472 * @return void
473 */
474 public function view_json_data() {
475 $this->checkAccessibility();
476 $this->f->disableLog();
477 if ($this->getParameter('idx') !== ']'
478 && $this->getParameter('idx') !== '0') {
479 //
480 $this->view_form_json();
481 }
482 else {
483 $this->view_tab_json();
484 }
485 }
486
487 protected function view_tab_json() {
488 $where = '';
489 if ($this->f->get_submitted_get_value('state') !== null
490 && $this->f->get_submitted_get_value('state') !== '') {
491 //
492 $where = sprintf(' WHERE state = \'%s\' ', $this->f->get_submitted_get_value('state'));
493 }
494 $query = sprintf('
495 SELECT
496 *
497 FROM %1$stask
498 %2$s
499 ORDER BY task ASC
500 ',
501 DB_PREFIXE,
502 $where
503 );
504 $res = $this->f->get_all_results_from_db_query($query, true);
505 if ($res['code'] === 'KO') {
506 return false;
507 }
508 $list_tasks = array();
509 foreach ($res['result'] as $task) {
510 $task['timestamp_log'] = json_decode($task['timestamp_log'], true);
511 $task['dossier'] = $task['object_id'];
512 if ($this->get_lien_objet_by_type($task['type']) === 'document_numerise') {
513 $val_dn = $this->get_document_numerise_data($task['object_id']);
514 $task['dossier'] = $val_dn['dossier'];
515 }
516 $list_tasks[$task['task']] = $task;
517 }
518 printf(json_encode($list_tasks));
519 }
520
521 protected function get_dossier_data(string $dossier) {
522 $val_di = array();
523 $inst_di = $this->f->get_inst__om_dbform(array(
524 "obj" => "dossier",
525 "idx" => $dossier,
526 ));
527 $val_di = $inst_di->get_json_data();
528 if ($val_di['dossier_instruction_type_code'] === 'T') {
529 $val_di['date_decision_transfert'] = $val_di['date_decision'];
530 }
531 unset($val_di['initial_dt']);
532 unset($val_di['log_instructions']);
533 return $val_di;
534 }
535
536 protected function get_dossier_autorisation_data(string $da) {
537 $val_da = array();
538 $inst_da = $this->f->get_inst__om_dbform(array(
539 "obj" => "dossier_autorisation",
540 "idx" => $da,
541 ));
542 $val_da = $inst_da->get_json_data();
543 return $val_da;
544 }
545
546 protected function get_donnees_techniques_data(string $fk_idx, string $fk_field) {
547 $val_dt = array();
548 $inst_dt = $this->f->get_inst__by_other_idx(array(
549 "obj" => "donnees_techniques",
550 "fk_field" => $fk_field,
551 "fk_idx" => $fk_idx,
552 ));
553 $val_dt = array(
554 'donnees_techniques' => $inst_dt->getVal($inst_dt->clePrimaire),
555 'cerfa' => $inst_dt->getVal('cerfa'),
556 );
557 $val_dt = array_merge($val_dt, $inst_dt->get_donnees_techniques_applicables());
558 if (isset($val_dt['am_exist_date']) === true) {
559 $val_dt['am_exist_date_num'] = '';
560 if (is_numeric($val_dt['am_exist_date']) === true) {
561 $val_dt['am_exist_date_num'] = $val_dt['am_exist_date'];
562 }
563 }
564 // Correspond à la nomenclature de Plat'AU STATUT_INFO
565 $val_dt['tax_statut_info'] = 'Déclaré';
566 //
567 if ($inst_dt->is_tab_surf_ssdest_enabled() === true) {
568 $fields_tab_surf_dest = $inst_dt->get_fields_tab_surf_dest();
569 foreach ($fields_tab_surf_dest as $field) {
570 if (isset($val_dt[$field]) === true) {
571 unset($val_dt[$field]);
572 }
573 }
574 } else {
575 $fields_tab_surf_ssdest = $inst_dt->get_fields_tab_surf_ssdest();
576 foreach ($fields_tab_surf_ssdest as $field) {
577 if (isset($val_dt[$field]) === true) {
578 unset($val_dt[$field]);
579 }
580 }
581 }
582 // Correspond à la nouvelle ligne CERFA v7 dans le DENSI imposition 1.2.3
583 if (isset($val_dt['tax_su_non_habit_surf2']) === true
584 && isset($val_dt['tax_su_non_habit_surf3']) === true
585 && (($val_dt['tax_su_non_habit_surf2'] !== null
586 && $val_dt['tax_su_non_habit_surf2'] !== '')
587 || ($val_dt['tax_su_non_habit_surf3'] !== null
588 && $val_dt['tax_su_non_habit_surf3'] !== ''))) {
589 //
590 $val_dt['tax_su_non_habit_surf8'] = intval($val_dt['tax_su_non_habit_surf2']) + intval($val_dt['tax_su_non_habit_surf3']);
591 }
592 if (isset($val_dt['tax_su_non_habit_surf_stat2']) === true
593 && isset($val_dt['tax_su_non_habit_surf_stat3']) === true
594 && (($val_dt['tax_su_non_habit_surf_stat2'] !== null
595 && $val_dt['tax_su_non_habit_surf_stat2'] !== '')
596 || ($val_dt['tax_su_non_habit_surf_stat3'] !== null
597 && $val_dt['tax_su_non_habit_surf_stat3'] !== ''))) {
598 //
599 $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']);
600 }
601 // Cas particulier d'un projet réduit à l'extension d'une habitation existante
602 $particular_case = false;
603 $fields_tab_crea_loc_hab = $inst_dt->get_fields_tab_crea_loc_hab();
604 foreach ($fields_tab_crea_loc_hab as $field) {
605 if (isset($val_dt[$field]) === false
606 || (isset($val_dt[$field]) === true
607 && ($val_dt[$field] === null
608 || $val_dt[$field] === ''))) {
609 //
610 $particular_case = true;
611 }
612 }
613 if ($particular_case === true) {
614 if (isset($val_dt['tax_ext_pret']) === true
615 && $val_dt['tax_ext_pret'] === 'f') {
616 //
617 $val_dt['tax_su_princ_surf1'] = $val_dt['tax_surf_tot_cstr'];
618 $val_dt['tax_su_princ_surf_stat1'] = $val_dt['tax_surf_loc_stat'];
619 }
620 if (isset($val_dt['tax_ext_pret']) === true
621 && $val_dt['tax_ext_pret'] === 't') {
622 //
623 if (isset($val_dt['tax_ext_desc']) === true) {
624 if (preg_match('/[pP].*[lL].*[aA].*[iI]/', $val_dt['tax_ext_desc']) === 1
625 || preg_match('/[lL].*[lL].*[tT].*[sS]/', $val_dt['tax_ext_desc']) === 1) {
626 //
627 $val_dt['tax_su_princ_surf2'] = $val_dt['tax_surf_tot_cstr'];
628 $val_dt['tax_su_princ_surf_stat2'] = $val_dt['tax_surf_loc_stat'];
629 }
630 // if (preg_match('/[pP].*[tT].*[zZ]/', $val_dt['tax_ext_desc']) === 1) {
631 // $val_dt['tax_su_princ_surf4'] = $val_dt['tax_surf_tot_cstr'];
632 // $val_dt['tax_su_princ_surf_stat4'] = $val_dt['tax_surf_loc_stat'];
633 // }
634 // if (preg_match('/[pP].*[lL].*[uU].*[sS]/', $val_dt['tax_ext_desc']) === 1
635 // || preg_match('/[lL].*[eE].*[sS]/', $val_dt['tax_ext_desc']) === 1
636 // || preg_match('/[pP].*[sS].*[lL].*[aA]/', $val_dt['tax_ext_desc']) === 1
637 // || preg_match('/[pP].*[lL].*[sS]/', $val_dt['tax_ext_desc']) === 1
638 // || preg_match('/[lL].*[lL].*[sS]/', $val_dt['tax_ext_desc']) === 1) {
639 // //
640 // $val_dt['tax_su_princ_surf3'] = $val_dt['tax_surf_tot_cstr'];
641 // $val_dt['tax_su_princ_surf_stat3'] = $val_dt['tax_surf_loc_stat'];
642 // }
643 }
644 }
645 }
646 // Cas particulier de la surface taxable démolie
647 if (isset($val_dt['tax_surf_tot_demo']) === true
648 && isset($val_dt['tax_surf_tax_demo']) === true
649 && ($val_dt['tax_surf_tot_demo'] === null
650 || $val_dt['tax_surf_tot_demo'] === '')) {
651 //
652 $val_dt['tax_surf_tot_demo'] = $val_dt['tax_surf_tax_demo'];
653 }
654 return $val_dt;
655 }
656
657 protected function get_external_uid($fk_idx, string $fk_idx_2) {
658 $inst_external_uid = $this->f->get_inst__by_other_idx(array(
659 "obj" => "lien_id_interne_uid_externe",
660 "fk_field" => 'object_id',
661 "fk_idx" => $fk_idx,
662 "fk_field_2" => 'object',
663 "fk_idx_2" => $fk_idx_2,
664 ));
665 return $inst_external_uid->getVal('external_uid');
666 }
667
668 protected function get_demandeurs_data(string $dossier) {
669 $val_demandeur = array();
670 $inst_di = $this->f->get_inst__om_dbform(array(
671 "obj" => "dossier",
672 "idx" => $dossier,
673 ));
674 $list_demandeurs = $inst_di->get_demandeurs();
675 foreach ($list_demandeurs as $demandeur) {
676 $inst_demandeur = $this->f->get_inst__om_dbform(array(
677 "obj" => "demandeur",
678 "idx" => $demandeur['demandeur'],
679 ));
680 $val_demandeur[$demandeur['demandeur']] = $inst_demandeur->get_json_data();
681 $val_demandeur[$demandeur['demandeur']]['petitionnaire_principal'] = $demandeur['petitionnaire_principal'];
682 }
683 return $val_demandeur;
684 }
685
686 protected function get_architecte_data($architecte = null) {
687 $val_architecte = null;
688 if ($architecte !== null
689 && $architecte !== '') {
690 //
691 $inst_architecte = $this->f->get_inst__om_dbform(array(
692 "obj" => "architecte",
693 "idx" => $architecte,
694 ));
695 $val_architecte = $inst_architecte->get_json_data();
696 }
697 return $val_architecte;
698 }
699
700 protected function get_instruction_data(string $dossier, $type = 'decision') {
701 $val_instruction = null;
702 $instruction_with_doc = null;
703 $inst_di = $this->f->get_inst__om_dbform(array(
704 "obj" => "dossier",
705 "idx" => $dossier,
706 ));
707 $idx = null;
708 if ($type === 'decision') {
709 $idx = $inst_di->get_last_instruction_decision();
710 }
711 if ($type === 'incompletude') {
712 $idx = $inst_di->get_last_instruction_incompletude();
713 }
714 $inst_instruction = $this->f->get_inst__om_dbform(array(
715 "obj" => "instruction",
716 "idx" => $idx,
717 ));
718 if (count($inst_instruction->val) > 0) {
719 $val_instruction = array();
720 $instruction_data = $inst_instruction->get_json_data();
721 $val_instruction = $this->sort_instruction_data($instruction_data, $val_instruction);
722 if ($instruction_data['om_fichier_instruction'] !== null
723 && $instruction_data['om_fichier_instruction'] !== '') {
724 //
725 $instruction_with_doc = $inst_instruction->getVal($inst_instruction->clePrimaire);
726 }
727 $inst_ev = $this->f->get_inst__om_dbform(array(
728 "obj" => "evenement",
729 "idx" => $inst_instruction->getVal('evenement'),
730 ));
731 if ($inst_ev->getVal('retour') === 't') {
732 $instructions_related = $inst_instruction->get_related_instructions();
733 foreach ($instructions_related as $instruction) {
734 if ($instruction !== null && $instruction !== '') {
735 $inst_related_instruction = $this->f->get_inst__om_dbform(array(
736 "obj" => "instruction",
737 "idx" => $instruction,
738 ));
739 $instruction_data = $inst_related_instruction->get_json_data();
740 $val_instruction = $this->sort_instruction_data($instruction_data, $val_instruction);
741 if ($instruction_data['om_fichier_instruction'] !== null
742 && $instruction_data['om_fichier_instruction'] !== '') {
743 //
744 $instruction_with_doc = $inst_related_instruction->getVal($inst_related_instruction->clePrimaire);
745 }
746 }
747 }
748 }
749 if ($instruction_with_doc !== null) {
750 //
751 $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);
752 }
753 }
754 return $val_instruction;
755 }
756
757 protected function sort_instruction_data(array $values, array $res) {
758 $fields = array(
759 "date_envoi_signature",
760 "date_retour_signature",
761 "date_envoi_rar",
762 "date_retour_rar",
763 "date_envoi_controle_legalite",
764 "date_retour_controle_legalite",
765 "signataire_arrete",
766 "om_fichier_instruction",
767 "tacite",
768 "lettretype",
769 );
770 foreach ($values as $key => $value) {
771 if (in_array($key, $fields) === true) {
772 if (array_key_exists($key, $res) === false
773 && $value !== null
774 && $value !== '') {
775 //
776 $res[$key] = $value;
777 } elseif ($key === 'tacite'
778 && $value === 't') {
779 //
780 $res[$key] = $value;
781 }
782 }
783 }
784 return $res;
785 }
786
787 protected function get_document_numerise_data(string $dn) {
788 $val_dn = array();
789 $inst_dn = $this->f->get_inst__om_dbform(array(
790 "obj" => "document_numerise",
791 "idx" => $dn,
792 ));
793 $val_dn = $inst_dn->get_json_data();
794 $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'));
795 // Correspond à la nomenclature Plat'AU NATURE_PIECE
796 $val_dn['nature'] = $val_dn['document_numerise_nature_libelle'];
797 return $val_dn;
798 }
799
800 protected function get_parcelles_data(string $object, string $idx) {
801 $val_dp = array();
802 $inst_di = $this->f->get_inst__om_dbform(array(
803 "obj" => $object,
804 "idx" => $idx,
805 ));
806 $list_parcelles = $inst_di->get_parcelles();
807 $no_ordre = 1;
808 foreach ($list_parcelles as $parcelle) {
809 $val_dp[$parcelle[$object.'_parcelle']] = array(
810 $object.'_parcelle' => $parcelle[$object.'_parcelle'],
811 'libelle' => $parcelle['libelle'],
812 'no_ordre' => $no_ordre,
813 );
814 $no_ordre++;
815 }
816 return $val_dp;
817 }
818
819 protected function view_form_json($in_field = false) {
820 //
821 if ($this->f->get_submitted_post_value('valid') === null) {
822 // Liste des valeurs à afficher
823 $val = array();
824 //
825 $val_task = array_combine($this->champs, $this->val);
826 foreach ($val_task as $key => $value) {
827 $val_task[$key] = strip_tags($value);
828 }
829 $val_task['timestamp_log'] = json_decode($val_task['timestamp_log'], true);
830 $val['task'] = $val_task;
831 //
832 if ($this->getVal('type') === 'creation_DA') {
833 $val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id'));
834 $val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation');
835 $val['dossier_autorisation_parcelle'] = $this->get_parcelles_data('dossier_autorisation', $val['dossier_autorisation']['dossier_autorisation']);
836 $val_external_uid = array();
837 $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier_autorisation']['dossier_autorisation'], 'dossier_autorisation');
838 $val['external_uids'] = $val_external_uid;
839 }
840 //
841 if ($this->getVal('type') === 'creation_DI'
842 || $this->getVal('type') === 'modification_DI'
843 || $this->getVal('type') === 'depot_DI') {
844 //
845 $val['dossier'] = $this->get_dossier_data($this->getVal('object_id'));
846 $val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_instruction');
847 $val['demandeur'] = $this->get_demandeurs_data($val['dossier']['dossier']);
848 $architecte = isset($val['donnees_techniques']['architecte']) === true ? $val['donnees_techniques']['architecte'] : null;
849 $val['architecte'] = $this->get_architecte_data($architecte);
850 $val['dossier_parcelle'] = $this->get_parcelles_data('dossier', $val['dossier']['dossier']);
851 $val_external_uid = array();
852 $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation');
853 $val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier');
854 $val['external_uids'] = $val_external_uid;
855 }
856 //
857 if ($this->getVal('type') === 'qualification_DI') {
858 $val['dossier'] = $this->get_dossier_data($this->getVal('object_id'));
859 $val_external_uid = array();
860 $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation');
861 $val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier');
862 $val['external_uids'] = $val_external_uid;
863 }
864 //
865 if ($this->getVal('type') === 'ajout_piece') {
866 $val['document_numerise'] = $this->get_document_numerise_data($this->getVal('object_id'));
867 $val['dossier'] = $this->get_dossier_data($val['document_numerise']['dossier']);
868 $val_external_uid = array();
869 $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation');
870 $val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier');
871 $val_external_uid['document_numerise'] = $this->get_external_uid($val['document_numerise']['document_numerise'], 'document_numerise');
872 $val['external_uids'] = $val_external_uid;
873 }
874 //
875 if ($this->getVal('type') === 'decision_DI') {
876 $val['dossier'] = $this->get_dossier_data($this->getVal('object_id'));
877 $val['instruction'] = $this->get_instruction_data($val['dossier']['dossier']);
878 $val_external_uid = array();
879 $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation');
880 $val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier');
881 $val['external_uids'] = $val_external_uid;
882 }
883 //
884 if ($this->getVal('type') === 'incompletude_DI') {
885 $val['dossier'] = $this->get_dossier_data($this->getVal('object_id'));
886 $val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'incompletude');
887 $val_external_uid = array();
888 $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation');
889 $val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier');
890 $val['external_uids'] = $val_external_uid;
891 }
892 //
893 if ($this->getVal('type') === 'completude_DI') {
894 $val['dossier'] = $this->get_dossier_data($this->getVal('object_id'));
895 $val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'completude');
896 $val_external_uid = array();
897 $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation');
898 $val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier');
899 $val['external_uids'] = $val_external_uid;
900 }
901
902 if ($in_field === true) {
903 return json_encode($val, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
904 } else {
905 // Liste des valeurs affichée en JSON
906 printf(json_encode($val, JSON_UNESCAPED_SLASHES));
907 }
908 }
909 }
910
911 function post_update_task() {
912 // Mise à jour des valeurs
913 //
914 $params = array(
915 'val' => array(
916 'state' => $this->f->get_submitted_post_value('state')
917 ),
918 );
919 $update = $this->update_task($params);
920 $message_class = "valid";
921 $message = $this->msg;
922 if ($update === false) {
923 $this->addToLog($this->msg, DEBUG_MODE);
924 $message_class = "error";
925 $message = sprintf(
926 '%s %s',
927 __('Impossible de mettre à jour la tâche.'),
928 __('Veuillez contacter votre administrateur.')
929 );
930 }
931 $this->f->displayMessage($message_class, $message);
932 //
933 $inst_lien = $this->f->get_inst__om_dbform(array(
934 "obj" => "lien_id_interne_uid_externe",
935 "idx" => ']',
936 ));
937 $valF = array(
938 'lien_id_interne_uid_externe' => '',
939 'object' => $this->get_lien_objet_by_type($this->getVal('type')),
940 'object_id' => $this->getVal('object_id'),
941 'external_uid' => $this->f->get_submitted_post_value('external_uid'),
942 );
943 $add = $inst_lien->ajouter($valF);
944 $message_class = "valid";
945 $message = $inst_lien->msg;
946 if ($add === false) {
947 $this->addToLog($inst_lien->msg, DEBUG_MODE);
948 $message_class = "error";
949 $message = sprintf(
950 '%s %s',
951 __("Impossible de mettre à jour le lien entre l'identifiant interne et l'identifiant de l'application externe."),
952 __('Veuillez contacter votre administrateur.')
953 );
954 }
955 $this->f->displayMessage($message_class, $message);
956 }
957
958 function post_add_task() {
959 // TODO Tester de remplacer la ligne de json_payload par un $_POST
960 $result = $this->add_task(array(
961 'val' => array(
962 'stream' => 'input',
963 'json_payload' => html_entity_decode($this->f->get_submitted_post_value('json_payload')),
964 'type' => $this->f->get_submitted_post_value('type'),
965 )
966 ));
967 $message = $this->msg;
968 $message_class = "valid";
969 if ($result === false){
970 $this->addToLog($this->msg, DEBUG_MODE);
971 $message_class = "error";
972 $message = sprintf(
973 '%s %s',
974 __('Impossible d\'ajouter la tâche.'),
975 __('Veuillez contacter votre administrateur.')
976 );
977 }
978 $this->f->displayMessage($message_class, $message);
979 }
980
981 function get_lien_objet_by_type($type) {
982 //
983 $objet = '';
984 if ($type === 'creation_DA') {
985 $objet = 'dossier_autorisation';
986 }
987 if ($type === 'creation_DI'
988 || $type === 'depot_DI'
989 || $type === 'modification_DI'
990 || $type === 'qualification_DI'
991 || $type === 'decision_DI'
992 || $type === 'incompletude_DI'
993 || $type === 'completude_DI') {
994 //
995 $objet = 'dossier';
996 }
997 if ($type === 'ajout_piece') {
998 $objet = 'document_numerise';
999 }
1000 return $objet;
1001 }
1002
1003 function setLayout(&$form, $maj) {
1004 $form->setBloc('json_payload', 'D', '', 'col_6');
1005 $form->setFieldset('json_payload', 'DF', __("json_payload"), "collapsible, startClosed");
1006 $form->setBloc('json_payload', 'F');
1007 $form->setBloc('timestamp_log', 'DF', '', 'col_9');
1008 }
1009
1010 }

Properties

Name Value
svn:executable *

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26