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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9973 - (hide annotations)
Thu Feb 25 19:01:57 2021 UTC (3 years, 11 months ago) by softime
Original Path: branches/4.14.0-develop/obj/task.class.php
File size: 54024 byte(s)
* Modification gestion external uid lors de la MàJ d'une task sortante

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

Properties

Name Value
svn:executable *

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26