1 |
<?php |
2 |
//$Id$ |
3 |
//gen openMairie le 14/04/2020 14:11 |
4 |
|
5 |
require_once "../gen/obj/task.class.php"; |
6 |
|
7 |
class task extends task_gen { |
8 |
|
9 |
const STATUS_DRAFT = 'draft'; |
10 |
const STATUS_NEW = 'new'; |
11 |
const STATUS_PENDING = 'pending'; |
12 |
const STATUS_DONE = 'done'; |
13 |
const STATUS_ERROR = 'error'; |
14 |
const STATUS_DEBUG = 'debug'; |
15 |
const STATUS_ARCHIVED = 'archived'; |
16 |
|
17 |
/** |
18 |
* Liste des types de tâche concernant les services instructeurs |
19 |
*/ |
20 |
const TASK_TYPE_SI = array( |
21 |
'creation_DA', |
22 |
'creation_DI', |
23 |
'depot_DI', |
24 |
'modification_DI', |
25 |
'qualification_DI', |
26 |
'decision_DI', |
27 |
'incompletude_DI', |
28 |
'completude_DI', |
29 |
'ajout_piece', |
30 |
'add_piece', |
31 |
'creation_consultation', |
32 |
); |
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 |
* 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 |
"identifier" => "json_data", |
53 |
"view" => "view_json_data", |
54 |
"permission_suffix" => "consulter", |
55 |
); |
56 |
$this->class_actions[997] = array( |
57 |
"identifier" => "json_data", |
58 |
"view" => "post_update_task", |
59 |
"permission_suffix" => "modifier", |
60 |
); |
61 |
$this->class_actions[996] = array( |
62 |
"identifier" => "json_data", |
63 |
"view" => "post_add_task", |
64 |
"permission_suffix" => "ajouter", |
65 |
); |
66 |
} |
67 |
|
68 |
public function setvalF($val = array()) { |
69 |
|
70 |
// // 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 |
|
99 |
parent::setvalF($val); |
100 |
|
101 |
// 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 |
// 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 |
} |
113 |
|
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 |
} |
133 |
|
134 |
/** |
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 |
"stream", |
146 |
"json_payload", |
147 |
"timestamp_log", |
148 |
); |
149 |
} |
150 |
|
151 |
function setType(&$form, $maj) { |
152 |
parent::setType($form, $maj); |
153 |
|
154 |
// Récupération du mode de l'action |
155 |
$crud = $this->get_action_crud($maj); |
156 |
|
157 |
// MODE CREER |
158 |
if ($maj == 0 || $crud == 'create') { |
159 |
$form->setType("state", "select"); |
160 |
$form->setType("stream", "select"); |
161 |
$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 |
$form->setType("json_payload", "jsonprettyprint"); |
168 |
} |
169 |
// MODE CONSULTER |
170 |
if ($maj == 3 || $crud == 'read') { |
171 |
$form->setType('dossier', 'link'); |
172 |
$form->setType('json_payload', 'jsonprettyprint'); |
173 |
} |
174 |
|
175 |
} |
176 |
|
177 |
/** |
178 |
* |
179 |
*/ |
180 |
function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) { |
181 |
if($maj < 2) { |
182 |
|
183 |
$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 |
|
191 |
$form->setSelect("state", $contenu); |
192 |
|
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 |
} |
201 |
|
202 |
if ($maj == 3) { |
203 |
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 |
|
209 |
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 |
} |
222 |
} |
223 |
} |
224 |
|
225 |
/** |
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 |
if ($this->getVal('stream') == "output") { |
234 |
$form->setVal('json_payload', $this->view_form_json(true)); |
235 |
} else { |
236 |
$form->setVal('json_payload', htmlentities($this->getVal('json_payload'))); |
237 |
} |
238 |
} |
239 |
|
240 |
function setLib(&$form, $maj) { |
241 |
parent::setLib($form, $maj); |
242 |
|
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 |
} |
251 |
|
252 |
public function verifier($val = array(), &$dnu1 = null, $dnu2 = null) { |
253 |
$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 |
// 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 |
} |
302 |
|
303 |
// une tâche entrante doit avoir une payload avec les clés requises |
304 |
if ($this->correct && (isset($this->valF['stream']) === false || |
305 |
$this->valF['stream'] == 'input')) { |
306 |
|
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 |
'external_uids/dossier' |
313 |
); |
314 |
|
315 |
// tâche de type création de DI/DA |
316 |
if (isset($this->valF['type']) !== false && $this->valF['type'] == 'create_DI_for_consultation') { |
317 |
|
318 |
$paths = array_merge($paths, array( |
319 |
'dossier/dossier', |
320 |
'dossier/dossier_autorisation_type_detaille_code', |
321 |
'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 |
if (! isset($json_payload['external_uids']['acteur']) && |
332 |
! 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 |
sprintf('<span class="bold">%s</span>', 'external_uids/acteur'), |
337 |
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 |
} |
378 |
|
379 |
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 |
self::STATUS_DONE, |
389 |
$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 |
/** |
400 |
* 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 |
|
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 |
} |
424 |
} |
425 |
|
426 |
/** |
427 |
* 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 |
|
436 |
// Vérifie si la task doit être ajoutée en fonction du mode de l'application, |
437 |
// seulement pour les tasks output |
438 |
$task_types_si = self::TASK_TYPE_SI; |
439 |
$task_types_sc = self::TASK_TYPE_SC; |
440 |
$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 |
$timestamp_log = json_encode(array( |
457 |
'creation_date' => date('Y-m-d H:i:s'), |
458 |
)); |
459 |
|
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 |
if (isset($params['val']['type']) |
463 |
&& ($params['val']['type'] == "add_piece" || $params['val']['type'] == "avis_consultation") |
464 |
&& isset($params['val']['stream']) |
465 |
&& $params['val']['stream'] == "input" ) { |
466 |
// |
467 |
$json_payload = json_decode($params['val']['json_payload'], true); |
468 |
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 |
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", "task.uid_fichier"); |
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 |
} |
497 |
} |
498 |
|
499 |
// Mise à jour du DI |
500 |
$valF = array( |
501 |
'task' => '', |
502 |
'type' => $params['val']['type'], |
503 |
'timestamp_log' => $timestamp_log, |
504 |
'state' => isset($params['val']['state']) === true ? $params['val']['state'] : self::STATUS_NEW, |
505 |
'object_id' => isset($params['val']['object_id']) ? $params['val']['object_id'] : '', |
506 |
'dossier' => isset($params['val']['dossier']) ? $params['val']['dossier'] : '', |
507 |
'stream' => $stream, |
508 |
'json_payload' => isset($params['val']['json_payload']) === true ? $params['val']['json_payload'] : '{}', |
509 |
); |
510 |
|
511 |
// tâche sortante |
512 |
if($valF["stream"] == "output"){ |
513 |
|
514 |
// TODO expliquer ce code |
515 |
$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 |
} |
519 |
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 |
} |
536 |
|
537 |
$add = $this->ajouter($valF); |
538 |
$this->addToLog(__METHOD__."(): retour de l'ajout de tâche: ".var_export($add, true), VERBOSE_MODE); |
539 |
if ($add === false) { |
540 |
$this->addToLog(__METHOD__."(): ".$this->msg, DEBUG_MODE); |
541 |
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 |
$this->addToLog(__METHOD__."(): erreur timestamp log", DEBUG_MODE); |
558 |
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 |
'object_id' => $this->getVal('object_id'), |
572 |
'stream' => $this->getVal('stream'), |
573 |
'dossier' => $this->getVal('dossier'), |
574 |
'json_payload' => $this->getVal('json_payload'), |
575 |
); |
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 |
* |
588 |
* @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 |
* VIEW - view_json_data |
604 |
* Affiche l'enregistrement dans le format JSON. |
605 |
* |
606 |
* @return void |
607 |
*/ |
608 |
public function view_json_data() { |
609 |
$this->checkAccessibility(); |
610 |
$this->f->disableLog(); |
611 |
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 |
$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 |
$query = sprintf(' |
629 |
SELECT |
630 |
* |
631 |
FROM %1$stask |
632 |
%2$s |
633 |
ORDER BY task ASC |
634 |
', |
635 |
DB_PREFIXE, |
636 |
$where |
637 |
); |
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 |
$task['timestamp_log'] = json_decode($task['timestamp_log'], true); |
645 |
$task['dossier'] = $task['dossier']; |
646 |
if ($task['type'] === 'ajout_piece') { |
647 |
$val_dn = $this->get_document_numerise_data($task['object_id']); |
648 |
} |
649 |
if ($task['stream'] === 'output') { |
650 |
$task['external_uids'] = $this->get_all_external_uids($task['dossier']); |
651 |
} |
652 |
$list_tasks[$task['task']] = $task; |
653 |
} |
654 |
printf(json_encode($list_tasks)); |
655 |
} |
656 |
|
657 |
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 |
$val_di = $inst_di->get_json_data(); |
664 |
if ($val_di['dossier_instruction_type_code'] === 'T') { |
665 |
$val_di['date_decision_transfert'] = $val_di['date_decision']; |
666 |
} |
667 |
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 |
$val_da = $inst_da->get_json_data(); |
679 |
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 |
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 |
// Correspond à la nomenclature de Plat'AU STATUT_INFO |
701 |
$val_dt['tax_statut_info'] = 'Déclaré'; |
702 |
// |
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 |
// Correspond à la nouvelle ligne CERFA v7 dans le DENSI imposition 1.2.3 |
719 |
if (isset($val_dt['tax_su_non_habit_surf2']) === true |
720 |
&& 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 |
// |
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 |
&& 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 |
// |
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 |
// 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 |
if (isset($val_dt[$field]) === false |
742 |
|| (isset($val_dt[$field]) === true |
743 |
&& ($val_dt[$field] === null |
744 |
|| $val_dt[$field] === ''))) { |
745 |
// |
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 |
return $val_dt; |
791 |
} |
792 |
|
793 |
/** |
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 |
protected function get_external_uid($fk_idx, string $fk_idx_2) { |
820 |
$inst_external_uid = $this->f->get_inst__by_other_idx(array( |
821 |
"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 |
return $inst_external_uid->getVal('external_uid'); |
828 |
} |
829 |
|
830 |
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 |
$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 |
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 |
)); |
856 |
$val_demandeur[$demandeur['demandeur']] = $inst_demandeur->get_json_data(); |
857 |
$val_demandeur[$demandeur['demandeur']]['petitionnaire_principal'] = $demandeur['petitionnaire_principal']; |
858 |
} |
859 |
return $val_demandeur; |
860 |
} |
861 |
|
862 |
protected function get_architecte_data($architecte = null) { |
863 |
$val_architecte = null; |
864 |
if ($architecte !== null |
865 |
&& $architecte !== '') { |
866 |
// |
867 |
$inst_architecte = $this->f->get_inst__om_dbform(array( |
868 |
"obj" => "architecte", |
869 |
"idx" => $architecte, |
870 |
)); |
871 |
$val_architecte = $inst_architecte->get_json_data(); |
872 |
} |
873 |
return $val_architecte; |
874 |
} |
875 |
|
876 |
protected function get_instruction_data(string $dossier, $type = 'decision', $extra_params = array()) { |
877 |
$val_instruction = null; |
878 |
$instruction_with_doc = null; |
879 |
$inst_di = $this->f->get_inst__om_dbform(array( |
880 |
"obj" => "dossier", |
881 |
"idx" => $dossier, |
882 |
)); |
883 |
$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 |
// XXX Permet de récupérer l'instruction par son identifiant |
891 |
if ($type === 'with-id') { |
892 |
$idx = $extra_params['with-id']; |
893 |
} |
894 |
$inst_instruction = $this->f->get_inst__om_dbform(array( |
895 |
"obj" => "instruction", |
896 |
"idx" => $idx, |
897 |
)); |
898 |
if (count($inst_instruction->val) > 0) { |
899 |
$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 |
$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 |
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 |
} |
928 |
} |
929 |
if ($instruction_with_doc !== null) { |
930 |
// |
931 |
$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 |
} |
933 |
} |
934 |
return $val_instruction; |
935 |
} |
936 |
|
937 |
protected function sort_instruction_data(array $values, array $res) { |
938 |
$fields = array( |
939 |
"date_evenement", |
940 |
"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 |
"lettretype", |
950 |
); |
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 |
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 |
$val_dn = $inst_dn->get_json_data(); |
975 |
$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 |
// Correspond à la nomenclature Plat'AU NATURE_PIECE |
977 |
$val_dn['nature'] = $val_dn['document_numerise_nature_libelle']; |
978 |
return $val_dn; |
979 |
} |
980 |
|
981 |
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 |
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 |
if ($ad !== null) { |
1008 |
$inst_ad = $this->f->get_inst__om_dbform(array( |
1009 |
"obj" => "avis_decision", |
1010 |
"idx" => $ad, |
1011 |
)); |
1012 |
$val_ad = $inst_ad->get_json_data(); |
1013 |
$val_ad['txAvis'] = "Voir document joint"; |
1014 |
if (isset($val_ad['tacite']) === true |
1015 |
&& $val_ad['tacite'] === 't') { |
1016 |
// |
1017 |
$val_ad['txAvis'] = "Sans objet"; |
1018 |
} |
1019 |
} |
1020 |
return $val_ad; |
1021 |
} |
1022 |
|
1023 |
protected function get_signataire_arrete_data(string $sa) { |
1024 |
$inst_sa = $this->f->get_inst__om_dbform(array( |
1025 |
"obj" => "signataire_arrete", |
1026 |
"idx" => $sa, |
1027 |
)); |
1028 |
$val_sa = array_combine($inst_sa->champs, $inst_sa->val); |
1029 |
foreach ($val_sa as $key => $value) { |
1030 |
$val_sa[$key] = strip_tags($value); |
1031 |
} |
1032 |
return $val_sa; |
1033 |
} |
1034 |
|
1035 |
// XXX WIP |
1036 |
protected function get_consultation_data(string $consultation) { |
1037 |
$val_consultation = array(); |
1038 |
$inst_consultation = $this->f->get_inst__om_dbform(array( |
1039 |
"obj" => "consultation", |
1040 |
"idx" => $consultation, |
1041 |
)); |
1042 |
$val_consultation = $inst_consultation->get_json_data(); |
1043 |
if (isset($val_consultation['fichier']) === true |
1044 |
&& $val_consultation['fichier'] !== '') { |
1045 |
// |
1046 |
$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')); |
1047 |
} |
1048 |
if (isset($val_consultation['om_fichier_consultation']) === true |
1049 |
&& $val_consultation['om_fichier_consultation'] !== '') { |
1050 |
// |
1051 |
$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')); |
1052 |
} |
1053 |
return $val_consultation; |
1054 |
} |
1055 |
|
1056 |
// XXX WIP |
1057 |
protected function get_service_data(string $service) { |
1058 |
$val_service = array(); |
1059 |
$inst_service = $this->f->get_inst__om_dbform(array( |
1060 |
"obj" => "service", |
1061 |
"idx" => $service, |
1062 |
)); |
1063 |
$val_service = $inst_service->get_json_data(); |
1064 |
return $val_service; |
1065 |
} |
1066 |
|
1067 |
protected function view_form_json($in_field = false) { |
1068 |
// |
1069 |
if ($this->f->get_submitted_post_value('valid') === null) { |
1070 |
// Liste des valeurs à afficher |
1071 |
$val = array(); |
1072 |
// |
1073 |
$val_task = array_combine($this->champs, $this->val); |
1074 |
foreach ($val_task as $key => $value) { |
1075 |
$val_task[$key] = strip_tags($value); |
1076 |
} |
1077 |
$val_task['timestamp_log'] = json_decode($val_task['timestamp_log'], true); |
1078 |
$val['task'] = $val_task; |
1079 |
// |
1080 |
if ($this->getVal('type') === 'creation_DA') { |
1081 |
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id')); |
1082 |
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation'); |
1083 |
$val['dossier_autorisation_parcelle'] = $this->get_parcelles_data('dossier_autorisation', $val['dossier_autorisation']['dossier_autorisation']); |
1084 |
$val_external_uid = array(); |
1085 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier_autorisation']['dossier_autorisation'], 'dossier_autorisation'); |
1086 |
$val['external_uids'] = $val_external_uid; |
1087 |
} |
1088 |
// |
1089 |
if ($this->getVal('type') === 'creation_DI' |
1090 |
|| $this->getVal('type') === 'modification_DI' |
1091 |
|| $this->getVal('type') === 'depot_DI') { |
1092 |
// |
1093 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
1094 |
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_instruction'); |
1095 |
$val['demandeur'] = $this->get_demandeurs_data($val['dossier']['dossier']); |
1096 |
$architecte = isset($val['donnees_techniques']['architecte']) === true ? $val['donnees_techniques']['architecte'] : null; |
1097 |
$val['architecte'] = $this->get_architecte_data($architecte); |
1098 |
$val['dossier_parcelle'] = $this->get_parcelles_data('dossier', $val['dossier']['dossier']); |
1099 |
$val_external_uid = array(); |
1100 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1101 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1102 |
$val['external_uids'] = $val_external_uid; |
1103 |
} |
1104 |
// |
1105 |
if ($this->getVal('type') === 'qualification_DI') { |
1106 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
1107 |
$val_external_uid = array(); |
1108 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1109 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1110 |
$val['external_uids'] = $val_external_uid; |
1111 |
} |
1112 |
// |
1113 |
if ($this->getVal('type') === 'ajout_piece') { |
1114 |
$val['document_numerise'] = $this->get_document_numerise_data($this->getVal('object_id')); |
1115 |
$val['dossier'] = $this->get_dossier_data($val['document_numerise']['dossier']); |
1116 |
$val_external_uid = array(); |
1117 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1118 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1119 |
$val_external_uid['document_numerise'] = $this->get_external_uid($val['document_numerise']['document_numerise'], 'document_numerise'); |
1120 |
$val['external_uids'] = $val_external_uid; |
1121 |
} |
1122 |
// |
1123 |
if ($this->getVal('type') === 'decision_DI') { |
1124 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1125 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1126 |
$val_external_uid = array(); |
1127 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1128 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1129 |
$val['external_uids'] = $val_external_uid; |
1130 |
} |
1131 |
// |
1132 |
if ($this->getVal('type') === 'incompletude_DI') { |
1133 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1134 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1135 |
$val_external_uid = array(); |
1136 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1137 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1138 |
$val['external_uids'] = $val_external_uid; |
1139 |
} |
1140 |
// |
1141 |
if ($this->getVal('type') === 'completude_DI') { |
1142 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1143 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1144 |
$val_external_uid = array(); |
1145 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1146 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1147 |
$val['external_uids'] = $val_external_uid; |
1148 |
} |
1149 |
// |
1150 |
if ($this->getVal('type') === 'pec_metier_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_external_uid = array(); |
1154 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1155 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1156 |
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
1157 |
$val['external_uids'] = $val_external_uid; |
1158 |
} |
1159 |
// |
1160 |
if ($this->getVal('type') === 'avis_consultation') { |
1161 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1162 |
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
1163 |
$val['avis_decision'] = $this->get_avis_decision_data($this->getVal('dossier')); |
1164 |
if (isset($val['instruction']['signataire_arrete']) === true) { |
1165 |
$val['signataire_arrete'] = $this->get_signataire_arrete_data($val['instruction']['signataire_arrete']); |
1166 |
} |
1167 |
$val_external_uid = array(); |
1168 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1169 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1170 |
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
1171 |
$val['external_uids'] = $val_external_uid; |
1172 |
} |
1173 |
// XXX WIP |
1174 |
if ($this->getVal('type') === 'creation_consultation') { |
1175 |
// |
1176 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1177 |
$val['consultation'] = $this->get_consultation_data($this->getVal('object_id')); |
1178 |
$val['service'] = $this->get_service_data($val['consultation']['service']); |
1179 |
$val_external_uid = array(); |
1180 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1181 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1182 |
$val['external_uids'] = $val_external_uid; |
1183 |
} |
1184 |
|
1185 |
if ($in_field === true) { |
1186 |
return json_encode($val, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
1187 |
} else { |
1188 |
// Liste des valeurs affichée en JSON |
1189 |
printf(json_encode($val, JSON_UNESCAPED_SLASHES)); |
1190 |
} |
1191 |
} |
1192 |
} |
1193 |
|
1194 |
function post_update_task() { |
1195 |
// Mise à jour des valeurs |
1196 |
|
1197 |
// Modification de l'état de la tâche |
1198 |
if ($this->f->get_submitted_post_value('state') !== null) { |
1199 |
$params = array( |
1200 |
'val' => array( |
1201 |
'state' => $this->f->get_submitted_post_value('state') |
1202 |
), |
1203 |
); |
1204 |
$update = $this->update_task($params); |
1205 |
$message_class = "valid"; |
1206 |
$message = $this->msg; |
1207 |
if ($update === false) { |
1208 |
$this->addToLog($this->msg, DEBUG_MODE); |
1209 |
$message_class = "error"; |
1210 |
$message = sprintf( |
1211 |
'%s %s', |
1212 |
__('Impossible de mettre à jour la tâche.'), |
1213 |
__('Veuillez contacter votre administrateur.') |
1214 |
); |
1215 |
} |
1216 |
$this->f->displayMessage($message_class, $message); |
1217 |
} |
1218 |
|
1219 |
// Sauvegarde de l'uid externe retourné |
1220 |
if ($this->f->get_submitted_post_value('external_uid') !== null) { |
1221 |
// |
1222 |
$objects = $this->get_objects_by_task_type($this->getVal('type'), $this->getVal('stream')); |
1223 |
foreach ($objects as $object) { |
1224 |
$inst_lien = $this->f->get_inst__om_dbform(array( |
1225 |
"obj" => "lien_id_interne_uid_externe", |
1226 |
"idx" => ']', |
1227 |
)); |
1228 |
if ($inst_lien->is_exists($object, $this->getVal('object_id'), $this->f->get_submitted_post_value('external_uid'), $this->getVal('dossier')) === false) { |
1229 |
$valF = array( |
1230 |
'lien_id_interne_uid_externe' => '', |
1231 |
'object' => $object, |
1232 |
'object_id' => $this->getVal('object_id'), |
1233 |
'external_uid' => $this->f->get_submitted_post_value('external_uid'), |
1234 |
'dossier' => $this->getVal('dossier'), |
1235 |
); |
1236 |
$add = $inst_lien->ajouter($valF); |
1237 |
$message_class = "valid"; |
1238 |
$message = $inst_lien->msg; |
1239 |
if ($add === false) { |
1240 |
$this->addToLog($inst_lien->msg, DEBUG_MODE); |
1241 |
$message_class = "error"; |
1242 |
$message = sprintf( |
1243 |
'%s %s', |
1244 |
__("Impossible de mettre à jour le lien entre l'identifiant interne et l'identifiant de l'application externe."), |
1245 |
__('Veuillez contacter votre administrateur.') |
1246 |
); |
1247 |
} |
1248 |
$this->f->displayMessage($message_class, $message); |
1249 |
} |
1250 |
} |
1251 |
} |
1252 |
} |
1253 |
|
1254 |
function post_add_task() { |
1255 |
// TODO Tester de remplacer la ligne de json_payload par un $_POST |
1256 |
$result = $this->add_task(array( |
1257 |
'val' => array( |
1258 |
'stream' => 'input', |
1259 |
'json_payload' => html_entity_decode($this->f->get_submitted_post_value('json_payload')), |
1260 |
'type' => $this->f->get_submitted_post_value('type'), |
1261 |
) |
1262 |
)); |
1263 |
$message = sprintf( |
1264 |
__("Tâche %s ajoutée avec succès"), |
1265 |
$this->getVal($this->clePrimaire)). |
1266 |
'<br/><br/>'. |
1267 |
$this->msg; |
1268 |
$message_class = "valid"; |
1269 |
if ($result === false){ |
1270 |
$this->addToLog($this->msg, DEBUG_MODE); |
1271 |
$message_class = "error"; |
1272 |
$message = sprintf( |
1273 |
'%s %s', |
1274 |
__('Impossible d\'ajouter la tâche.'), |
1275 |
__('Veuillez contacter votre administrateur.') |
1276 |
); |
1277 |
} |
1278 |
$this->f->displayMessage($message_class, $message); |
1279 |
} |
1280 |
|
1281 |
function setLayout(&$form, $maj) { |
1282 |
|
1283 |
// Récupération du mode de l'action |
1284 |
$crud = $this->get_action_crud($maj); |
1285 |
|
1286 |
// MODE different de CREER |
1287 |
if ($maj != 0 || $crud != 'create') { |
1288 |
$form->setBloc('json_payload', 'D', '', 'col_6'); |
1289 |
$form->setFieldset('json_payload', 'DF', __("json_payload"), "collapsible, startClosed"); |
1290 |
$form->setBloc('json_payload', 'F'); |
1291 |
} |
1292 |
$form->setBloc('timestamp_log', 'DF', '', 'col_9'); |
1293 |
} |
1294 |
|
1295 |
/** |
1296 |
* [get_objects_by_task_type description] |
1297 |
* @param [type] $type [description] |
1298 |
* @return [type] [description] |
1299 |
*/ |
1300 |
function get_objects_by_task_type($type, $stream = 'all') { |
1301 |
$objects = array(); |
1302 |
if (in_array($type, array('creation_DA', )) === true) { |
1303 |
$objects = array('dossier_autorisation', ); |
1304 |
} |
1305 |
if (in_array($type, array('creation_DI', 'depot_DI', 'notification_DI', 'qualification_DI', )) === true) { |
1306 |
$objects = array('dossier', ); |
1307 |
} |
1308 |
if (in_array($type, array('create_DI_for_consultation', )) === true) { |
1309 |
$objects = array('dossier', 'dossier_consultation', ); |
1310 |
} |
1311 |
if (in_array($type, array('decision_DI', 'incompletude_DI', 'completude_DI', )) === true) { |
1312 |
$objects = array('instruction', ); |
1313 |
} |
1314 |
if (in_array($type, array('pec_metier_consultation', )) === true |
1315 |
&& $stream === 'output') { |
1316 |
$objects = array('pec_dossier_consultation', ); |
1317 |
} |
1318 |
if (in_array($type, array('avis_consultation', )) === true |
1319 |
&& $stream === 'output') { |
1320 |
$objects = array('avis_dossier_consultation', ); |
1321 |
} |
1322 |
if (in_array($type, array('ajout_piece', 'add_piece', )) === true) { |
1323 |
$objects = array('piece', ); |
1324 |
} |
1325 |
if (in_array($type, array('creation_consultation', )) === true) { |
1326 |
$objects = array('consultation', ); |
1327 |
} |
1328 |
if (in_array($type, array('pec_metier_consultation', )) === true |
1329 |
&& $stream === 'input') { |
1330 |
$objects = array('pec_metier_consultation', ); |
1331 |
} |
1332 |
if (in_array($type, array('avis_consultation', )) === true |
1333 |
&& $stream === 'input') { |
1334 |
$objects = array('avis_consultation', ); |
1335 |
} |
1336 |
return $objects; |
1337 |
} |
1338 |
|
1339 |
} |