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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10808 - (hide annotations)
Wed Nov 24 17:48:35 2021 UTC (3 years, 2 months ago) by softime
File size: 65224 byte(s)
* Fusion de la branche d'intégration 5.2.0-develop dans le trunk

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

Properties

Name Value
svn:executable *

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26