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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10043 - (hide annotations)
Tue Apr 27 13:53:22 2021 UTC (3 years, 9 months ago) by softime
Original Path: branches/4.14.0-develop/obj/task.class.php
File size: 57856 byte(s)
* Fusion de la branche de développement 4.14.0-develop_task_consultation dans la branche d'intégration 4.14.0-develop

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

Properties

Name Value
svn:executable *

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26