1 |
<?php |
<?php |
2 |
//$Id$ |
//$Id$ |
3 |
//gen openMairie le 14/04/2020 14:11 |
//gen openMairie le 14/04/2020 14:11 |
4 |
|
|
5 |
require_once "../gen/obj/task.class.php"; |
require_once "../gen/obj/task.class.php"; |
6 |
|
|
7 |
class task extends task_gen { |
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 |
|
const STATUS_CANCELED = 'canceled'; |
17 |
|
|
18 |
|
/** |
19 |
|
* 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 |
|
'modification_DA', |
34 |
|
'create_DI', |
35 |
|
'notification_recepisse', |
36 |
|
'notification_instruction', |
37 |
|
'notification_decision', |
38 |
|
); |
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 |
|
'create_message', |
48 |
|
'notification_recepisse', |
49 |
|
'notification_instruction', |
50 |
|
'notification_decision', |
51 |
|
); |
52 |
|
|
53 |
|
/** |
54 |
|
* Catégorie de la tâche |
55 |
|
*/ |
56 |
|
var $category = 'platau'; |
57 |
|
|
58 |
/** |
/** |
59 |
* Définition des actions disponibles sur la classe. |
* Définition des actions disponibles sur la classe. |
60 |
* |
* |
64 |
parent::init_class_actions(); |
parent::init_class_actions(); |
65 |
// |
// |
66 |
$this->class_actions[998] = array( |
$this->class_actions[998] = array( |
67 |
"identifier" => "view_json", |
"identifier" => "json_data", |
68 |
"view" => "view_json", |
"view" => "view_json_data", |
69 |
"permission_suffix" => "consulter", |
"permission_suffix" => "consulter", |
70 |
); |
); |
71 |
|
$this->class_actions[997] = array( |
72 |
|
"identifier" => "json_data", |
73 |
|
"view" => "post_update_task", |
74 |
|
"permission_suffix" => "modifier", |
75 |
|
); |
76 |
|
$this->class_actions[996] = array( |
77 |
|
"identifier" => "json_data", |
78 |
|
"view" => "post_add_task", |
79 |
|
"permission_suffix" => "ajouter", |
80 |
|
); |
81 |
|
} |
82 |
|
|
83 |
|
public function setvalF($val = array()) { |
84 |
|
|
85 |
|
// // 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 |
|
|
114 |
|
parent::setvalF($val); |
115 |
|
|
116 |
|
// 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 |
|
// 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 |
|
} |
128 |
|
|
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 |
|
$existing = $this->f->findObjectById('task', $id); |
137 |
|
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 |
|
|
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 |
|
} |
155 |
|
|
156 |
|
/** |
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 |
|
"stream", |
168 |
|
"json_payload", |
169 |
|
"timestamp_log", |
170 |
|
"category", |
171 |
|
); |
172 |
|
} |
173 |
|
|
174 |
|
function setType(&$form, $maj) { |
175 |
|
parent::setType($form, $maj); |
176 |
|
|
177 |
|
// Récupération du mode de l'action |
178 |
|
$crud = $this->get_action_crud($maj); |
179 |
|
|
180 |
|
// ALL |
181 |
|
$form->setType("category", "hidden"); |
182 |
|
|
183 |
|
// MODE CREER |
184 |
|
if ($maj == 0 || $crud == 'create') { |
185 |
|
$form->setType("state", "select"); |
186 |
|
$form->setType("stream", "select"); |
187 |
|
$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 |
|
$form->setType("json_payload", "jsonprettyprint"); |
194 |
|
} |
195 |
|
// MODE CONSULTER |
196 |
|
if ($maj == 3 || $crud == 'read') { |
197 |
|
$form->setType('dossier', 'link'); |
198 |
|
$form->setType('json_payload', 'jsonprettyprint'); |
199 |
|
} |
200 |
|
|
201 |
|
} |
202 |
|
|
203 |
|
/** |
204 |
|
* |
205 |
|
*/ |
206 |
|
function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) { |
207 |
|
if($maj < 2) { |
208 |
|
|
209 |
|
$contenu = array(); |
210 |
|
foreach(array('DRAFT', 'NEW', 'PENDING', 'DONE', 'ERROR', 'DEBUG', 'ARCHIVED', 'CANCELED') as $key) { |
211 |
|
$const_name = 'STATUS_'.$key; |
212 |
|
$const_value = constant("self::$const_name"); |
213 |
|
$contenu[0][] = $const_value; |
214 |
|
$contenu[1][] = __($const_value); |
215 |
|
} |
216 |
|
|
217 |
|
$form->setSelect("state", $contenu); |
218 |
|
|
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 |
|
} |
227 |
|
|
228 |
|
if ($maj == 3) { |
229 |
|
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 |
|
|
235 |
|
if($form->val['type'] == "creation_DA" |
236 |
|
|| $form->val['type'] == "modification_DA"){ |
237 |
|
// |
238 |
|
$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 |
|
} |
250 |
|
} |
251 |
|
} |
252 |
|
|
253 |
|
/** |
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 |
|
if ($this->getVal('stream') == "output") { |
262 |
|
$form->setVal('json_payload', $this->view_form_json(true)); |
263 |
|
} else { |
264 |
|
$form->setVal('json_payload', htmlentities($this->getVal('json_payload'))); |
265 |
|
} |
266 |
|
} |
267 |
|
|
268 |
|
function setLib(&$form, $maj) { |
269 |
|
parent::setLib($form, $maj); |
270 |
|
|
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 |
|
} |
279 |
|
|
280 |
|
public function verifier($val = array(), &$dnu1 = null, $dnu2 = null) { |
281 |
|
$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 |
|
// 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 |
|
} |
330 |
|
|
331 |
|
// une tâche entrante doit avoir une payload avec les clés requises |
332 |
|
if ($this->correct && (isset($this->valF['stream']) === false || |
333 |
|
$this->valF['stream'] == 'input')) { |
334 |
|
|
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 |
|
$paths = array(); |
340 |
|
if ($this->valF['category'] === 'platau') { |
341 |
|
$paths = array( |
342 |
|
'external_uids/dossier' |
343 |
|
); |
344 |
|
} |
345 |
|
|
346 |
|
// tâche de type création de DI/DA |
347 |
|
if (isset($this->valF['type']) !== false && $this->valF['type'] == 'create_DI_for_consultation') { |
348 |
|
|
349 |
|
$paths = array_merge($paths, array( |
350 |
|
'dossier/dossier', |
351 |
|
'dossier/dossier_autorisation_type_detaille_code', |
352 |
|
'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 |
|
if (! isset($json_payload['external_uids']['acteur']) && |
363 |
|
! 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 |
|
sprintf('<span class="bold">%s</span>', 'external_uids/acteur'), |
368 |
|
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 |
|
} |
409 |
|
|
410 |
|
/** |
411 |
|
* [task_exists description] |
412 |
|
* @param string $type [description] |
413 |
|
* @param string $object_id [description] |
414 |
|
* @param bool $is_not_done [description] |
415 |
|
* @return [type] [description] |
416 |
|
*/ |
417 |
|
public function task_exists(string $type, string $object_id, string $dossier = null, bool $is_not_done = true) { |
418 |
|
$query = sprintf(' |
419 |
|
SELECT task |
420 |
|
FROM %1$stask |
421 |
|
WHERE %2$s |
422 |
|
type = \'%3$s\' |
423 |
|
AND (object_id = \'%4$s\' |
424 |
|
%5$s) |
425 |
|
', |
426 |
|
DB_PREFIXE, |
427 |
|
$is_not_done == true ? 'state != \''.self::STATUS_DONE.'\' AND' : '', |
428 |
|
$type, |
429 |
|
$object_id, |
430 |
|
$dossier !== null ? sprintf('OR dossier = \'%s\'', $dossier) : '' |
431 |
|
); |
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 |
|
/** |
440 |
|
* 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 |
|
|
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 |
|
} |
464 |
|
|
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 |
|
} |
483 |
|
|
484 |
|
/** |
485 |
|
* TRIGGER - triggermodifierapres. |
486 |
|
* |
487 |
|
* @param string $id |
488 |
|
* @param null &$dnu1 @deprecated Ne pas utiliser. |
489 |
|
* @param array $val Tableau des valeurs brutes. |
490 |
|
* @param null $dnu2 @deprecated Ne pas utiliser. |
491 |
|
* |
492 |
|
* @return boolean |
493 |
|
*/ |
494 |
|
public function triggermodifierapres($id, &$dnu1 = null, $val = array(), $dnu2 = null) { |
495 |
|
parent::triggermodifierapres($id, $dnu1, $val, $dnu2); |
496 |
|
|
497 |
|
// Suivi des notificiations |
498 |
|
if (isset($val['category']) === true |
499 |
|
&& $val['category'] === 'portal' |
500 |
|
&& isset($val['type']) === true |
501 |
|
&& ($val['type'] === 'notification_recepisse' |
502 |
|
|| $val['type'] === 'notification_instruction' |
503 |
|
|| $val['type'] === 'notification_decision')) { |
504 |
|
// |
505 |
|
if (isset($this->valF['state']) === true |
506 |
|
&& $this->valF['state'] !== $this->getVal('state')) { |
507 |
|
// |
508 |
|
$inst_in = $this->f->get_inst__om_dbform(array( |
509 |
|
"obj" => "instruction_notification", |
510 |
|
"idx" => $val['object_id'], |
511 |
|
)); |
512 |
|
$valF = array(); |
513 |
|
foreach ($inst_in->champs as $champ) { |
514 |
|
$valF[$champ] = $inst_in->getVal($champ); |
515 |
|
} |
516 |
|
// Pas de date sur le suivi des notifications depuis un portail |
517 |
|
$valF['date_envoi'] = null; |
518 |
|
$valF['date_premier_acces'] = null; |
519 |
|
if ($this->valF['state'] === self::STATUS_DONE) { |
520 |
|
$valF['statut'] = __("envoyé"); |
521 |
|
$valF['commentaire'] = __("Notification traitée"); |
522 |
|
} |
523 |
|
if ($this->valF['state'] === self::STATUS_ERROR) { |
524 |
|
$valF['statut'] = __("échec"); |
525 |
|
$valF['commentaire'] = __("Le traitement de la notification a échoué"); |
526 |
|
} |
527 |
|
$inst_in->setParameter('maj', 1); |
528 |
|
$update = $inst_in->modifier($valF); |
529 |
|
if ($update === false) { |
530 |
|
$this->addToLog(__METHOD__."(): ".$inst_in->msg, DEBUG_MODE); |
531 |
|
return false; |
532 |
|
} |
533 |
|
} |
534 |
|
} |
535 |
|
|
536 |
|
// |
537 |
|
return true; |
538 |
} |
} |
539 |
|
|
540 |
/** |
/** |
546 |
*/ |
*/ |
547 |
public function add_task($params = array()) { |
public function add_task($params = array()) { |
548 |
$this->begin_treatment(__METHOD__); |
$this->begin_treatment(__METHOD__); |
549 |
|
|
550 |
|
// Vérifie si la task doit être ajoutée en fonction du mode de l'application, |
551 |
|
// seulement pour les tasks output |
552 |
|
$task_types_si = self::TASK_TYPE_SI; |
553 |
|
$task_types_sc = self::TASK_TYPE_SC; |
554 |
|
$stream = isset($params['val']['stream']) === true ? $params['val']['stream'] : 'output'; |
555 |
|
if ($stream === 'output' |
556 |
|
&& isset($params['val']['type']) === true |
557 |
|
&& $this->f->is_option_mode_service_consulte_enabled() === true |
558 |
|
&& in_array($params['val']['type'], $task_types_sc) === false) { |
559 |
|
// |
560 |
|
return $this->end_treatment(__METHOD__, true); |
561 |
|
} |
562 |
|
if ($stream === 'output' |
563 |
|
&& isset($params['val']['type']) === true |
564 |
|
&& $this->f->is_option_mode_service_consulte_enabled() === false |
565 |
|
&& in_array($params['val']['type'], $task_types_si) === false) { |
566 |
|
// |
567 |
|
return $this->end_treatment(__METHOD__, true); |
568 |
|
} |
569 |
|
|
570 |
|
// |
571 |
$timestamp_log = json_encode(array( |
$timestamp_log = json_encode(array( |
572 |
'creation_date' => date('Y-m-d H:i:s'), |
'creation_date' => date('Y-m-d H:i:s'), |
573 |
)); |
)); |
574 |
|
|
575 |
|
// |
576 |
|
$category = isset($params['val']['category']) === true ? $params['val']['category'] : $this->category; |
577 |
|
|
578 |
|
// Si la tâche est de type ajout_piece et de stream input alors on ajoute le fichier |
579 |
|
// et on ajoute l'uid dans le champ json_payload avant l'ajout de la tâche |
580 |
|
if (isset($params['val']['type']) |
581 |
|
&& ($params['val']['type'] == "add_piece" || $params['val']['type'] == "avis_consultation") |
582 |
|
&& isset($params['val']['stream']) |
583 |
|
&& $params['val']['stream'] == "input" ) { |
584 |
|
// |
585 |
|
$json_payload = json_decode($params['val']['json_payload'], true); |
586 |
|
if (json_last_error() !== JSON_ERROR_NONE) { |
587 |
|
$this->addToMessage(__("Le contenu JSON de la tâche n'est pas valide.")); |
588 |
|
return $this->end_treatment(__METHOD__, false); |
589 |
|
} |
590 |
|
if (isset($json_payload['document_numerise']) === true |
591 |
|
&& empty($json_payload['document_numerise']) === false) { |
592 |
|
// |
593 |
|
$document_numerise = $json_payload['document_numerise']; |
594 |
|
$file_content = base64_decode($document_numerise["file_content"]); |
595 |
|
if ($file_content === false){ |
596 |
|
$this->addToMessage(__("Le contenu du fichier lié à la tâche n'a pas pu etre recupere.")); |
597 |
|
return $this->end_treatment(__METHOD__, false); |
598 |
|
} |
599 |
|
$metadata = array( |
600 |
|
"filename" => $document_numerise['nom_fichier'], |
601 |
|
"size" => strlen($file_content), |
602 |
|
"mimetype" => $document_numerise['file_content_type'], |
603 |
|
"date_creation" => isset($document_numerise['date_creation']) === true ? $document_numerise['date_creation'] : date("Y-m-d"), |
604 |
|
); |
605 |
|
$uid_fichier = $this->f->storage->create($file_content, $metadata, "from_content", "task.uid_fichier"); |
606 |
|
if ($uid_fichier === OP_FAILURE) { |
607 |
|
$this->addToMessage(__("Erreur lors de la creation du fichier lié à la tâche.")); |
608 |
|
return $this->end_treatment(__METHOD__, false); |
609 |
|
} |
610 |
|
$json_payload["document_numerise"]["uid"] = $uid_fichier; |
611 |
|
// Le fichier a été ajouté nous n'avons plus besoin du champ file_content dans la payload |
612 |
|
unset($json_payload["document_numerise"]["file_content"]); |
613 |
|
$params['val']['json_payload'] = json_encode($json_payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
614 |
|
} |
615 |
|
} |
616 |
|
|
617 |
// Mise à jour du DI |
// Mise à jour du DI |
618 |
$valF = array( |
$valF = array( |
619 |
'task' => '', |
'task' => '', |
620 |
'type' => $params['val']['type'], |
'type' => $params['val']['type'], |
621 |
'timestamp_log' => $timestamp_log, |
'timestamp_log' => $timestamp_log, |
622 |
'state' => 'draft', |
'state' => isset($params['val']['state']) === true ? $params['val']['state'] : self::STATUS_NEW, |
623 |
'id' => $params['val']['id'], |
'object_id' => isset($params['val']['object_id']) ? $params['val']['object_id'] : '', |
624 |
|
'dossier' => isset($params['val']['dossier']) ? $params['val']['dossier'] : '', |
625 |
|
'stream' => $stream, |
626 |
|
'json_payload' => isset($params['val']['json_payload']) === true ? $params['val']['json_payload'] : '{}', |
627 |
|
'category' => $category, |
628 |
); |
); |
629 |
|
|
630 |
|
// tâche sortante |
631 |
|
if ($valF["stream"] == "output" |
632 |
|
&& $valF['type'] !== 'notification_recepisse' |
633 |
|
&& $valF['type'] !== 'notification_instruction' |
634 |
|
&& $valF['type'] !== 'notification_decision') { |
635 |
|
|
636 |
|
// TODO expliquer ce code |
637 |
|
$task_exists = $this->task_exists($valF['type'], $valF['object_id'], $valF['dossier']); |
638 |
|
if ($valF['type'] === 'modification_DI' && $task_exists === false) { |
639 |
|
$task_exists = $this->task_exists('creation_DI', $valF['object_id']); |
640 |
|
} |
641 |
|
if ($valF['type'] === 'modification_DA' && $task_exists === false) { |
642 |
|
$task_exists = $this->task_exists('creation_DA', $valF['object_id']); |
643 |
|
} |
644 |
|
if ($valF['type'] === 'ajout_piece') { |
645 |
|
$task_exists = $this->task_exists('ajout_piece', $valF['object_id']); |
646 |
|
} |
647 |
|
if ($valF['type'] === 'creation_consultation') { |
648 |
|
$task_exists = $this->task_exists('creation_consultation', $valF['object_id']); |
649 |
|
} |
650 |
|
if ($task_exists !== false) { |
651 |
|
$inst_task = $this->f->get_inst__om_dbform(array( |
652 |
|
"obj" => "task", |
653 |
|
"idx" => $task_exists, |
654 |
|
)); |
655 |
|
$update_state = $inst_task->getVal('state'); |
656 |
|
if (isset($params['update_val']['state']) === true) { |
657 |
|
$update_state = $params['update_val']['state']; |
658 |
|
} |
659 |
|
$update_params = array( |
660 |
|
'val' => array( |
661 |
|
'state' => $update_state, |
662 |
|
), |
663 |
|
); |
664 |
|
return $inst_task->update_task($update_params); |
665 |
|
} |
666 |
|
} |
667 |
$add = $this->ajouter($valF); |
$add = $this->ajouter($valF); |
668 |
|
$this->addToLog(__METHOD__."(): retour de l'ajout de tâche: ".var_export($add, true), VERBOSE_MODE); |
669 |
if ($add === false) { |
if ($add === false) { |
670 |
$this->addToLog($this->msg, DEBUG_MODE); |
$this->addToLog(__METHOD__."(): ".$this->msg, DEBUG_MODE); |
671 |
return $this->end_treatment(__METHOD__, false); |
return $this->end_treatment(__METHOD__, false); |
672 |
} |
} |
673 |
return $this->end_treatment(__METHOD__, true); |
return $this->end_treatment(__METHOD__, true); |
684 |
$this->begin_treatment(__METHOD__); |
$this->begin_treatment(__METHOD__); |
685 |
$timestamp_log = $this->get_timestamp_log(); |
$timestamp_log = $this->get_timestamp_log(); |
686 |
if ($timestamp_log === false) { |
if ($timestamp_log === false) { |
687 |
$this->addToLog(__('XXX'), DEBUG_MODE); |
$this->addToLog(__METHOD__."(): erreur timestamp log", DEBUG_MODE); |
688 |
return $this->end_treatment(__METHOD__, false); |
return $this->end_treatment(__METHOD__, false); |
689 |
} |
} |
690 |
array_push($timestamp_log, array( |
array_push($timestamp_log, array( |
698 |
'type' => $this->getVal('type'), |
'type' => $this->getVal('type'), |
699 |
'timestamp_log' => $timestamp_log, |
'timestamp_log' => $timestamp_log, |
700 |
'state' => $params['val']['state'], |
'state' => $params['val']['state'], |
701 |
'id' => $this->getVal('id'), |
'object_id' => isset($params['object_id']) == true && $this->getVal('type') == 'create_DI' ? $params['object_id'] : $this->getVal('object_id'), |
702 |
|
'stream' => $this->getVal('stream'), |
703 |
|
'dossier' => $this->getVal('dossier'), |
704 |
|
'json_payload' => $this->getVal('json_payload'), |
705 |
|
'category' => $this->getVal('category'), |
706 |
); |
); |
707 |
$update = $this->modifier($valF); |
$update = $this->modifier($valF); |
708 |
if ($update === false) { |
if ($update === false) { |
715 |
/** |
/** |
716 |
* Récupère le journal d'horodatage dans le champ timestamp_log de |
* Récupère le journal d'horodatage dans le champ timestamp_log de |
717 |
* l'enregistrement instancié. |
* l'enregistrement instancié. |
718 |
* |
* |
719 |
* @param array $params Tableau des paramètres |
* @param array $params Tableau des paramètres |
720 |
* @return array sinon false en cas d'erreur |
* @return array sinon false en cas d'erreur |
721 |
*/ |
*/ |
731 |
} |
} |
732 |
|
|
733 |
/** |
/** |
734 |
* VIEW - view_json |
* VIEW - view_json_data |
735 |
* Affiche l'enregistrement dans le format JSON. |
* Affiche l'enregistrement dans le format JSON. |
736 |
* |
* |
737 |
* @return void |
* @return void |
738 |
*/ |
*/ |
739 |
public function view_json() { |
public function view_json_data() { |
740 |
$this->checkAccessibility(); |
$this->checkAccessibility(); |
741 |
$val = array_combine($this->champs, $this->val); |
$this->f->disableLog(); |
742 |
printf(json_encode($val)); |
if ($this->getParameter('idx') !== ']' |
743 |
if ($this->f->get_submitted_post_value('valid') === 'true' |
&& $this->getParameter('idx') !== '0') { |
|
&& $this->f->get_submitted_post_value('state') !== null) { |
|
744 |
// |
// |
745 |
|
$this->view_form_json(); |
746 |
|
} |
747 |
|
else { |
748 |
|
$this->view_tab_json(); |
749 |
|
} |
750 |
|
} |
751 |
|
|
752 |
|
protected function view_tab_json() { |
753 |
|
$where = ''; |
754 |
|
if ($this->f->get_submitted_get_value('state') !== null |
755 |
|
&& $this->f->get_submitted_get_value('state') !== '') { |
756 |
|
// |
757 |
|
$where_or_and = 'WHERE'; |
758 |
|
if ($where !== '') { |
759 |
|
$where_or_and = 'AND'; |
760 |
|
} |
761 |
|
$where .= sprintf(' %s state = \'%s\' ', $where_or_and, $this->f->get_submitted_get_value('state')); |
762 |
|
} |
763 |
|
if ($this->f->get_submitted_get_value('category') !== null |
764 |
|
&& $this->f->get_submitted_get_value('category') !== '') { |
765 |
|
// |
766 |
|
$where_or_and = 'WHERE'; |
767 |
|
if ($where !== '') { |
768 |
|
$where_or_and = 'AND'; |
769 |
|
} |
770 |
|
$where .= sprintf(' %s category = \'%s\' ', $where_or_and, $this->f->get_submitted_get_value('category')); |
771 |
|
} |
772 |
|
$query = sprintf(' |
773 |
|
SELECT |
774 |
|
* |
775 |
|
FROM %1$stask |
776 |
|
%2$s |
777 |
|
ORDER BY task ASC |
778 |
|
', |
779 |
|
DB_PREFIXE, |
780 |
|
$where |
781 |
|
); |
782 |
|
$res = $this->f->get_all_results_from_db_query($query, true); |
783 |
|
if ($res['code'] === 'KO') { |
784 |
|
return false; |
785 |
|
} |
786 |
|
$list_tasks = array(); |
787 |
|
foreach ($res['result'] as $task) { |
788 |
|
$task['timestamp_log'] = json_decode($task['timestamp_log'], true); |
789 |
|
$task['dossier'] = $task['dossier']; |
790 |
|
if ($task['type'] === 'ajout_piece') { |
791 |
|
$val_dn = $this->get_document_numerise_data($task['object_id']); |
792 |
|
} |
793 |
|
if ($task['stream'] === 'output') { |
794 |
|
$task['external_uids'] = $this->get_all_external_uids($task['dossier']); |
795 |
|
} |
796 |
|
$list_tasks[$task['task']] = $task; |
797 |
|
} |
798 |
|
printf(json_encode($list_tasks)); |
799 |
|
} |
800 |
|
|
801 |
|
protected function get_dossier_data(string $dossier) { |
802 |
|
$val_di = array(); |
803 |
|
$inst_di = $this->f->get_inst__om_dbform(array( |
804 |
|
"obj" => "dossier", |
805 |
|
"idx" => $dossier, |
806 |
|
)); |
807 |
|
$val_di = $inst_di->get_json_data(); |
808 |
|
if ($val_di['dossier_instruction_type_code'] === 'T') { |
809 |
|
$val_di['date_decision_transfert'] = $val_di['date_decision']; |
810 |
|
} |
811 |
|
unset($val_di['initial_dt']); |
812 |
|
unset($val_di['log_instructions']); |
813 |
|
return $val_di; |
814 |
|
} |
815 |
|
|
816 |
|
protected function get_dossier_autorisation_data(string $da) { |
817 |
|
$val_da = array(); |
818 |
|
$inst_da = $this->f->get_inst__om_dbform(array( |
819 |
|
"obj" => "dossier_autorisation", |
820 |
|
"idx" => $da, |
821 |
|
)); |
822 |
|
$val_da = $inst_da->get_json_data(); |
823 |
|
return $val_da; |
824 |
|
} |
825 |
|
|
826 |
|
protected function get_donnees_techniques_data(string $fk_idx, string $fk_field) { |
827 |
|
$val_dt = array(); |
828 |
|
$inst_dt = $this->f->get_inst__by_other_idx(array( |
829 |
|
"obj" => "donnees_techniques", |
830 |
|
"fk_field" => $fk_field, |
831 |
|
"fk_idx" => $fk_idx, |
832 |
|
)); |
833 |
|
$val_dt = array( |
834 |
|
'donnees_techniques' => $inst_dt->getVal($inst_dt->clePrimaire), |
835 |
|
'cerfa' => $inst_dt->getVal('cerfa'), |
836 |
|
); |
837 |
|
$val_dt = array_merge($val_dt, $inst_dt->get_donnees_techniques_applicables()); |
838 |
|
if (isset($val_dt['am_exist_date']) === true) { |
839 |
|
$val_dt['am_exist_date_num'] = ''; |
840 |
|
if (is_numeric($val_dt['am_exist_date']) === true) { |
841 |
|
$val_dt['am_exist_date_num'] = $val_dt['am_exist_date']; |
842 |
|
} |
843 |
|
} |
844 |
|
// Correspond à la nomenclature de Plat'AU STATUT_INFO |
845 |
|
$val_dt['tax_statut_info'] = 'Déclaré'; |
846 |
|
// |
847 |
|
if ($inst_dt->is_tab_surf_ssdest_enabled() === true) { |
848 |
|
$fields_tab_surf_dest = $inst_dt->get_fields_tab_surf_dest(); |
849 |
|
foreach ($fields_tab_surf_dest as $field) { |
850 |
|
if (isset($val_dt[$field]) === true) { |
851 |
|
unset($val_dt[$field]); |
852 |
|
} |
853 |
|
} |
854 |
|
} else { |
855 |
|
$fields_tab_surf_ssdest = $inst_dt->get_fields_tab_surf_ssdest(); |
856 |
|
foreach ($fields_tab_surf_ssdest as $field) { |
857 |
|
if (isset($val_dt[$field]) === true) { |
858 |
|
unset($val_dt[$field]); |
859 |
|
} |
860 |
|
} |
861 |
|
} |
862 |
|
// Correspond à la nouvelle ligne CERFA v7 dans le DENSI imposition 1.2.3 |
863 |
|
if (isset($val_dt['tax_su_non_habit_surf2']) === true |
864 |
|
&& isset($val_dt['tax_su_non_habit_surf3']) === true |
865 |
|
&& (($val_dt['tax_su_non_habit_surf2'] !== null |
866 |
|
&& $val_dt['tax_su_non_habit_surf2'] !== '') |
867 |
|
|| ($val_dt['tax_su_non_habit_surf3'] !== null |
868 |
|
&& $val_dt['tax_su_non_habit_surf3'] !== ''))) { |
869 |
|
// |
870 |
|
$val_dt['tax_su_non_habit_surf8'] = intval($val_dt['tax_su_non_habit_surf2']) + intval($val_dt['tax_su_non_habit_surf3']); |
871 |
|
} |
872 |
|
if (isset($val_dt['tax_su_non_habit_surf_stat2']) === true |
873 |
|
&& isset($val_dt['tax_su_non_habit_surf_stat3']) === true |
874 |
|
&& (($val_dt['tax_su_non_habit_surf_stat2'] !== null |
875 |
|
&& $val_dt['tax_su_non_habit_surf_stat2'] !== '') |
876 |
|
|| ($val_dt['tax_su_non_habit_surf_stat3'] !== null |
877 |
|
&& $val_dt['tax_su_non_habit_surf_stat3'] !== ''))) { |
878 |
|
// |
879 |
|
$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']); |
880 |
|
} |
881 |
|
// Cas particulier d'un projet réduit à l'extension d'une habitation existante |
882 |
|
$particular_case = false; |
883 |
|
$fields_tab_crea_loc_hab = $inst_dt->get_fields_tab_crea_loc_hab(); |
884 |
|
foreach ($fields_tab_crea_loc_hab as $field) { |
885 |
|
if (isset($val_dt[$field]) === false |
886 |
|
|| (isset($val_dt[$field]) === true |
887 |
|
&& ($val_dt[$field] === null |
888 |
|
|| $val_dt[$field] === ''))) { |
889 |
|
// |
890 |
|
$particular_case = true; |
891 |
|
} |
892 |
|
} |
893 |
|
if ($particular_case === true) { |
894 |
|
if (isset($val_dt['tax_ext_pret']) === true |
895 |
|
&& $val_dt['tax_ext_pret'] === 'f') { |
896 |
|
// |
897 |
|
$val_dt['tax_su_princ_surf1'] = $val_dt['tax_surf_tot_cstr']; |
898 |
|
$val_dt['tax_su_princ_surf_stat1'] = $val_dt['tax_surf_loc_stat']; |
899 |
|
} |
900 |
|
if (isset($val_dt['tax_ext_pret']) === true |
901 |
|
&& $val_dt['tax_ext_pret'] === 't') { |
902 |
|
// |
903 |
|
if (isset($val_dt['tax_ext_desc']) === true) { |
904 |
|
if (preg_match('/[pP].*[lL].*[aA].*[iI]/', $val_dt['tax_ext_desc']) === 1 |
905 |
|
|| preg_match('/[lL].*[lL].*[tT].*[sS]/', $val_dt['tax_ext_desc']) === 1) { |
906 |
|
// |
907 |
|
$val_dt['tax_su_princ_surf2'] = $val_dt['tax_surf_tot_cstr']; |
908 |
|
$val_dt['tax_su_princ_surf_stat2'] = $val_dt['tax_surf_loc_stat']; |
909 |
|
} |
910 |
|
// if (preg_match('/[pP].*[tT].*[zZ]/', $val_dt['tax_ext_desc']) === 1) { |
911 |
|
// $val_dt['tax_su_princ_surf4'] = $val_dt['tax_surf_tot_cstr']; |
912 |
|
// $val_dt['tax_su_princ_surf_stat4'] = $val_dt['tax_surf_loc_stat']; |
913 |
|
// } |
914 |
|
// if (preg_match('/[pP].*[lL].*[uU].*[sS]/', $val_dt['tax_ext_desc']) === 1 |
915 |
|
// || preg_match('/[lL].*[eE].*[sS]/', $val_dt['tax_ext_desc']) === 1 |
916 |
|
// || preg_match('/[pP].*[sS].*[lL].*[aA]/', $val_dt['tax_ext_desc']) === 1 |
917 |
|
// || preg_match('/[pP].*[lL].*[sS]/', $val_dt['tax_ext_desc']) === 1 |
918 |
|
// || preg_match('/[lL].*[lL].*[sS]/', $val_dt['tax_ext_desc']) === 1) { |
919 |
|
// // |
920 |
|
// $val_dt['tax_su_princ_surf3'] = $val_dt['tax_surf_tot_cstr']; |
921 |
|
// $val_dt['tax_su_princ_surf_stat3'] = $val_dt['tax_surf_loc_stat']; |
922 |
|
// } |
923 |
|
} |
924 |
|
} |
925 |
|
} |
926 |
|
// Cas particulier de la surface taxable démolie |
927 |
|
if (isset($val_dt['tax_surf_tot_demo']) === true |
928 |
|
&& isset($val_dt['tax_surf_tax_demo']) === true |
929 |
|
&& ($val_dt['tax_surf_tot_demo'] === null |
930 |
|
|| $val_dt['tax_surf_tot_demo'] === '')) { |
931 |
|
// |
932 |
|
$val_dt['tax_surf_tot_demo'] = $val_dt['tax_surf_tax_demo']; |
933 |
|
} |
934 |
|
return $val_dt; |
935 |
|
} |
936 |
|
|
937 |
|
/** |
938 |
|
* Récupère la liste des objets distincts existants dans la table des liens |
939 |
|
* entre identifiants internes et identifiants externes. |
940 |
|
* |
941 |
|
* @return array |
942 |
|
*/ |
943 |
|
protected function get_list_distinct_objects_external_link() { |
944 |
|
$query = sprintf(' |
945 |
|
SELECT |
946 |
|
DISTINCT(object) |
947 |
|
FROM %1$slien_id_interne_uid_externe |
948 |
|
ORDER BY object ASC |
949 |
|
', |
950 |
|
DB_PREFIXE |
951 |
|
); |
952 |
|
$res = $this->f->get_all_results_from_db_query($query, true); |
953 |
|
if ($res['code'] === 'KO') { |
954 |
|
return array(); |
955 |
|
} |
956 |
|
$result = array(); |
957 |
|
foreach ($res['result'] as $object) { |
958 |
|
$result[] = $object['object']; |
959 |
|
} |
960 |
|
return $result; |
961 |
|
} |
962 |
|
|
963 |
|
protected function get_external_uid($fk_idx, string $fk_idx_2) { |
964 |
|
$inst_external_uid = $this->f->get_inst__by_other_idx(array( |
965 |
|
"obj" => "lien_id_interne_uid_externe", |
966 |
|
"fk_field" => 'object_id', |
967 |
|
"fk_idx" => $fk_idx, |
968 |
|
"fk_field_2" => 'object', |
969 |
|
"fk_idx_2" => $fk_idx_2, |
970 |
|
)); |
971 |
|
return $inst_external_uid->getVal('external_uid'); |
972 |
|
} |
973 |
|
|
974 |
|
protected function get_all_external_uids($fk_idx, $link_objects = array()) { |
975 |
|
if (count($link_objects) == 0) { |
976 |
|
$link_objects = $this->get_list_distinct_objects_external_link(); |
977 |
|
} |
978 |
|
$val_external_uid = array(); |
979 |
|
foreach ($link_objects as $link_object) { |
980 |
|
$external_uid = $this->get_external_uid($fk_idx, $link_object); |
981 |
|
if ($external_uid !== '' && $external_uid !== null) { |
982 |
|
$val_external_uid[$link_object] = $external_uid; |
983 |
|
} |
984 |
|
} |
985 |
|
return $val_external_uid; |
986 |
|
} |
987 |
|
|
988 |
|
protected function get_demandeurs_data(string $dossier) { |
989 |
|
$val_demandeur = array(); |
990 |
|
$inst_di = $this->f->get_inst__om_dbform(array( |
991 |
|
"obj" => "dossier", |
992 |
|
"idx" => $dossier, |
993 |
|
)); |
994 |
|
$list_demandeurs = $inst_di->get_demandeurs(); |
995 |
|
foreach ($list_demandeurs as $demandeur) { |
996 |
|
$inst_demandeur = $this->f->get_inst__om_dbform(array( |
997 |
|
"obj" => "demandeur", |
998 |
|
"idx" => $demandeur['demandeur'], |
999 |
|
)); |
1000 |
|
$val_demandeur[$demandeur['demandeur']] = $inst_demandeur->get_json_data(); |
1001 |
|
$val_demandeur[$demandeur['demandeur']]['petitionnaire_principal'] = $demandeur['petitionnaire_principal']; |
1002 |
|
} |
1003 |
|
return $val_demandeur; |
1004 |
|
} |
1005 |
|
|
1006 |
|
protected function get_architecte_data($architecte = null) { |
1007 |
|
$val_architecte = null; |
1008 |
|
if ($architecte !== null |
1009 |
|
&& $architecte !== '') { |
1010 |
|
// |
1011 |
|
$inst_architecte = $this->f->get_inst__om_dbform(array( |
1012 |
|
"obj" => "architecte", |
1013 |
|
"idx" => $architecte, |
1014 |
|
)); |
1015 |
|
$val_architecte = $inst_architecte->get_json_data(); |
1016 |
|
} |
1017 |
|
return $val_architecte; |
1018 |
|
} |
1019 |
|
|
1020 |
|
protected function get_instruction_data(string $dossier, $type = 'decision', $extra_params = array()) { |
1021 |
|
$val_instruction = null; |
1022 |
|
$instruction_with_doc = null; |
1023 |
|
$inst_di = $this->f->get_inst__om_dbform(array( |
1024 |
|
"obj" => "dossier", |
1025 |
|
"idx" => $dossier, |
1026 |
|
)); |
1027 |
|
$idx = null; |
1028 |
|
if ($type === 'decision') { |
1029 |
|
$idx = $inst_di->get_last_instruction_decision(); |
1030 |
|
} |
1031 |
|
if ($type === 'incompletude') { |
1032 |
|
$idx = $inst_di->get_last_instruction_incompletude(); |
1033 |
|
} |
1034 |
|
// XXX Permet de récupérer l'instruction par son identifiant |
1035 |
|
if ($type === 'with-id') { |
1036 |
|
$idx = $extra_params['with-id']; |
1037 |
|
} |
1038 |
|
$inst_instruction = $this->f->get_inst__om_dbform(array( |
1039 |
|
"obj" => "instruction", |
1040 |
|
"idx" => $idx, |
1041 |
|
)); |
1042 |
|
if (count($inst_instruction->val) > 0) { |
1043 |
|
$val_instruction = array(); |
1044 |
|
$instruction_data = $inst_instruction->get_json_data(); |
1045 |
|
$val_instruction = $this->sort_instruction_data($instruction_data, $val_instruction); |
1046 |
|
if ($instruction_data['om_fichier_instruction'] !== null |
1047 |
|
&& $instruction_data['om_fichier_instruction'] !== '') { |
1048 |
|
// |
1049 |
|
$instruction_with_doc = $inst_instruction->getVal($inst_instruction->clePrimaire); |
1050 |
|
} |
1051 |
|
$inst_ev = $this->f->get_inst__om_dbform(array( |
1052 |
|
"obj" => "evenement", |
1053 |
|
"idx" => $inst_instruction->getVal('evenement'), |
1054 |
|
)); |
1055 |
|
if ($inst_ev->getVal('retour') === 't') { |
1056 |
|
$instructions_related = $inst_instruction->get_related_instructions(); |
1057 |
|
foreach ($instructions_related as $instruction) { |
1058 |
|
if ($instruction !== null && $instruction !== '') { |
1059 |
|
$inst_related_instruction = $this->f->get_inst__om_dbform(array( |
1060 |
|
"obj" => "instruction", |
1061 |
|
"idx" => $instruction, |
1062 |
|
)); |
1063 |
|
$instruction_data = $inst_related_instruction->get_json_data(); |
1064 |
|
$val_instruction = $this->sort_instruction_data($instruction_data, $val_instruction); |
1065 |
|
if ($instruction_data['om_fichier_instruction'] !== null |
1066 |
|
&& $instruction_data['om_fichier_instruction'] !== '') { |
1067 |
|
// |
1068 |
|
$instruction_with_doc = $inst_related_instruction->getVal($inst_related_instruction->clePrimaire); |
1069 |
|
} |
1070 |
|
} |
1071 |
|
} |
1072 |
|
} |
1073 |
|
if ($instruction_with_doc !== null) { |
1074 |
|
// |
1075 |
|
$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); |
1076 |
|
} |
1077 |
|
} |
1078 |
|
return $val_instruction; |
1079 |
|
} |
1080 |
|
|
1081 |
|
/** |
1082 |
|
* Récupère les informations |
1083 |
|
*/ |
1084 |
|
protected function get_instruction_notification_data($category, $type = '', $extra_params = array()) { |
1085 |
|
$val_in = array(); |
1086 |
|
|
1087 |
|
$idx = null; |
1088 |
|
if ($type === 'with-id') { |
1089 |
|
$idx = $extra_params['with-id']; |
1090 |
|
} |
1091 |
|
|
1092 |
|
// récupére les données à intégrer à la payload |
1093 |
|
$inst_in = $this->f->get_inst__om_dbform(array( |
1094 |
|
"obj" => "instruction_notification", |
1095 |
|
"idx" => $idx, |
1096 |
|
)); |
1097 |
|
$val_in = $inst_in->get_json_data(); |
1098 |
|
|
1099 |
|
// Récupération du message et du titre |
1100 |
|
$inst_instruction = $this->f->get_inst__om_dbform(array( |
1101 |
|
"obj" => "instruction", |
1102 |
|
"idx" => $inst_in->getVal('instruction'), |
1103 |
|
)); |
1104 |
|
$collectivite_id = $inst_instruction->get_dossier_instruction_om_collectivite($inst_instruction->getVal('dossier')); |
1105 |
|
$phrase_type_notification = array(); |
1106 |
|
$phrase_type_notification = $this->f->get_notification_parametre_courriel_type($collectivite_id); |
1107 |
|
// |
1108 |
|
$val_in['parametre_courriel_type_titre'] = $phrase_type_notification['parametre_courriel_type_titre']; |
1109 |
|
$val_in['parametre_courriel_type_message'] = $phrase_type_notification['parametre_courriel_type_message']; |
1110 |
|
|
1111 |
|
return $val_in; |
1112 |
|
} |
1113 |
|
|
1114 |
|
protected function sort_instruction_data(array $values, array $res) { |
1115 |
|
$fields = array( |
1116 |
|
"date_evenement", |
1117 |
|
"date_envoi_signature", |
1118 |
|
"date_retour_signature", |
1119 |
|
"date_envoi_rar", |
1120 |
|
"date_retour_rar", |
1121 |
|
"date_envoi_controle_legalite", |
1122 |
|
"date_retour_controle_legalite", |
1123 |
|
"signataire_arrete", |
1124 |
|
"om_fichier_instruction", |
1125 |
|
"tacite", |
1126 |
|
"lettretype", |
1127 |
|
"commentaire" |
1128 |
|
); |
1129 |
|
foreach ($values as $key => $value) { |
1130 |
|
if (in_array($key, $fields) === true) { |
1131 |
|
if (array_key_exists($key, $res) === false |
1132 |
|
&& $value !== null |
1133 |
|
&& $value !== '') { |
1134 |
|
// |
1135 |
|
$res[$key] = $value; |
1136 |
|
} elseif ($key === 'tacite' |
1137 |
|
&& $value === 't') { |
1138 |
|
// |
1139 |
|
$res[$key] = $value; |
1140 |
|
} |
1141 |
|
} |
1142 |
|
} |
1143 |
|
return $res; |
1144 |
|
} |
1145 |
|
|
1146 |
|
protected function get_document_numerise_data(string $dn) { |
1147 |
|
$val_dn = array(); |
1148 |
|
$inst_dn = $this->f->get_inst__om_dbform(array( |
1149 |
|
"obj" => "document_numerise", |
1150 |
|
"idx" => $dn, |
1151 |
|
)); |
1152 |
|
$val_dn = $inst_dn->get_json_data(); |
1153 |
|
$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')); |
1154 |
|
// Correspond à la nomenclature Plat'AU NATURE_PIECE |
1155 |
|
$val_dn['nature'] = $val_dn['document_numerise_nature_libelle']; |
1156 |
|
return $val_dn; |
1157 |
|
} |
1158 |
|
|
1159 |
|
protected function get_parcelles_data(string $object, string $idx) { |
1160 |
|
$val_dp = array(); |
1161 |
|
$inst_di = $this->f->get_inst__om_dbform(array( |
1162 |
|
"obj" => $object, |
1163 |
|
"idx" => $idx, |
1164 |
|
)); |
1165 |
|
$list_parcelles = $inst_di->get_parcelles(); |
1166 |
|
$no_ordre = 1; |
1167 |
|
foreach ($list_parcelles as $parcelle) { |
1168 |
|
$val_dp[$parcelle[$object.'_parcelle']] = array( |
1169 |
|
$object.'_parcelle' => $parcelle[$object.'_parcelle'], |
1170 |
|
'libelle' => $parcelle['libelle'], |
1171 |
|
'no_ordre' => $no_ordre, |
1172 |
|
); |
1173 |
|
$no_ordre++; |
1174 |
|
} |
1175 |
|
return $val_dp; |
1176 |
|
} |
1177 |
|
|
1178 |
|
protected function get_avis_decision_data(string $dossier) { |
1179 |
|
$inst_di = $this->f->get_inst__om_dbform(array( |
1180 |
|
"obj" => "dossier", |
1181 |
|
"idx" => $dossier, |
1182 |
|
)); |
1183 |
|
$ad = $inst_di->getVal('avis_decision'); |
1184 |
|
$val_ad = array(); |
1185 |
|
if ($ad !== null) { |
1186 |
|
$inst_ad = $this->f->get_inst__om_dbform(array( |
1187 |
|
"obj" => "avis_decision", |
1188 |
|
"idx" => $ad, |
1189 |
|
)); |
1190 |
|
$val_ad = $inst_ad->get_json_data(); |
1191 |
|
$val_ad['txAvis'] = "Voir document joint"; |
1192 |
|
if (isset($val_ad['tacite']) === true |
1193 |
|
&& $val_ad['tacite'] === 't') { |
1194 |
|
// |
1195 |
|
$val_ad['txAvis'] = "Sans objet"; |
1196 |
|
} |
1197 |
|
} |
1198 |
|
return $val_ad; |
1199 |
|
} |
1200 |
|
|
1201 |
|
protected function get_signataire_arrete_data(string $sa) { |
1202 |
|
$inst_sa = $this->f->get_inst__om_dbform(array( |
1203 |
|
"obj" => "signataire_arrete", |
1204 |
|
"idx" => $sa, |
1205 |
|
)); |
1206 |
|
$val_sa = array_combine($inst_sa->champs, $inst_sa->val); |
1207 |
|
foreach ($val_sa as $key => $value) { |
1208 |
|
$val_sa[$key] = strip_tags($value); |
1209 |
|
} |
1210 |
|
return $val_sa; |
1211 |
|
} |
1212 |
|
|
1213 |
|
// XXX WIP |
1214 |
|
protected function get_consultation_data(string $consultation) { |
1215 |
|
$val_consultation = array(); |
1216 |
|
$inst_consultation = $this->f->get_inst__om_dbform(array( |
1217 |
|
"obj" => "consultation", |
1218 |
|
"idx" => $consultation, |
1219 |
|
)); |
1220 |
|
$val_consultation = $inst_consultation->get_json_data(); |
1221 |
|
if (isset($val_consultation['fichier']) === true |
1222 |
|
&& $val_consultation['fichier'] !== '') { |
1223 |
|
// |
1224 |
|
$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')); |
1225 |
|
} |
1226 |
|
if (isset($val_consultation['om_fichier_consultation']) === true |
1227 |
|
&& $val_consultation['om_fichier_consultation'] !== '') { |
1228 |
|
// |
1229 |
|
$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')); |
1230 |
|
} |
1231 |
|
return $val_consultation; |
1232 |
|
} |
1233 |
|
|
1234 |
|
// XXX WIP |
1235 |
|
protected function get_service_data(string $service) { |
1236 |
|
$val_service = array(); |
1237 |
|
$inst_service = $this->f->get_inst__om_dbform(array( |
1238 |
|
"obj" => "service", |
1239 |
|
"idx" => $service, |
1240 |
|
)); |
1241 |
|
$val_service = $inst_service->get_json_data(); |
1242 |
|
return $val_service; |
1243 |
|
} |
1244 |
|
|
1245 |
|
protected function view_form_json($in_field = false) { |
1246 |
|
// |
1247 |
|
if ($this->f->get_submitted_post_value('valid') === null |
1248 |
|
&& $this->getVal('state') !== self::STATUS_CANCELED) { |
1249 |
|
// Liste des valeurs à afficher |
1250 |
|
$val = array(); |
1251 |
|
// |
1252 |
|
$val_task = array_combine($this->champs, $this->val); |
1253 |
|
foreach ($val_task as $key => $value) { |
1254 |
|
$val_task[$key] = strip_tags($value); |
1255 |
|
} |
1256 |
|
$val_task['timestamp_log'] = json_decode($val_task['timestamp_log'], true); |
1257 |
|
$val['task'] = $val_task; |
1258 |
|
// |
1259 |
|
if ($this->getVal('type') === 'creation_DA' |
1260 |
|
|| $this->getVal('type') === 'modification_DA') { |
1261 |
|
// |
1262 |
|
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id')); |
1263 |
|
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation'); |
1264 |
|
$val['dossier_autorisation_parcelle'] = $this->get_parcelles_data('dossier_autorisation', $val['dossier_autorisation']['dossier_autorisation']); |
1265 |
|
$val_external_uid = array(); |
1266 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier_autorisation']['dossier_autorisation'], 'dossier_autorisation'); |
1267 |
|
$val['external_uids'] = $val_external_uid; |
1268 |
|
} |
1269 |
|
// |
1270 |
|
if ($this->getVal('type') === 'creation_DI' |
1271 |
|
|| $this->getVal('type') === 'modification_DI' |
1272 |
|
|| $this->getVal('type') === 'depot_DI') { |
1273 |
|
// |
1274 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
1275 |
|
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_instruction'); |
1276 |
|
$val['demandeur'] = $this->get_demandeurs_data($val['dossier']['dossier']); |
1277 |
|
$architecte = isset($val['donnees_techniques']['architecte']) === true ? $val['donnees_techniques']['architecte'] : null; |
1278 |
|
$val['architecte'] = $this->get_architecte_data($architecte); |
1279 |
|
$val['dossier_parcelle'] = $this->get_parcelles_data('dossier', $val['dossier']['dossier']); |
1280 |
|
$val_external_uid = array(); |
1281 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1282 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1283 |
|
$val['external_uids'] = $val_external_uid; |
1284 |
|
} |
1285 |
|
// |
1286 |
|
if ($this->getVal('type') === 'qualification_DI') { |
1287 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1288 |
|
$val_external_uid = array(); |
1289 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1290 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1291 |
|
$val['external_uids'] = $val_external_uid; |
1292 |
|
} |
1293 |
|
// |
1294 |
|
if ($this->getVal('type') === 'ajout_piece') { |
1295 |
|
$val['document_numerise'] = $this->get_document_numerise_data($this->getVal('object_id')); |
1296 |
|
$val['dossier'] = $this->get_dossier_data($val['document_numerise']['dossier']); |
1297 |
|
$val_external_uid = array(); |
1298 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1299 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1300 |
|
$val_external_uid['document_numerise'] = $this->get_external_uid($val['document_numerise']['document_numerise'], 'document_numerise'); |
1301 |
|
$val['external_uids'] = $val_external_uid; |
1302 |
|
} |
1303 |
|
// |
1304 |
|
if ($this->getVal('type') === 'decision_DI') { |
1305 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1306 |
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1307 |
|
$val_external_uid = array(); |
1308 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1309 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1310 |
|
$val['external_uids'] = $val_external_uid; |
1311 |
|
} |
1312 |
|
// |
1313 |
|
if ($this->getVal('type') === 'incompletude_DI') { |
1314 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1315 |
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1316 |
|
$val_external_uid = array(); |
1317 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1318 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1319 |
|
$val['external_uids'] = $val_external_uid; |
1320 |
|
} |
1321 |
|
// |
1322 |
|
if ($this->getVal('type') === 'completude_DI') { |
1323 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1324 |
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1325 |
|
$val_external_uid = array(); |
1326 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1327 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1328 |
|
$val['external_uids'] = $val_external_uid; |
1329 |
|
} |
1330 |
|
// |
1331 |
|
if ($this->getVal('type') === 'pec_metier_consultation') { |
1332 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1333 |
|
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
1334 |
|
$val_external_uid = array(); |
1335 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1336 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1337 |
|
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
1338 |
|
$val['external_uids'] = $val_external_uid; |
1339 |
|
} |
1340 |
|
// |
1341 |
|
if ($this->getVal('type') === 'avis_consultation') { |
1342 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1343 |
|
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
1344 |
|
$val['avis_decision'] = $this->get_avis_decision_data($this->getVal('dossier')); |
1345 |
|
if (isset($val['instruction']['signataire_arrete']) === true) { |
1346 |
|
$val['signataire_arrete'] = $this->get_signataire_arrete_data($val['instruction']['signataire_arrete']); |
1347 |
|
} |
1348 |
|
$val_external_uid = array(); |
1349 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1350 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1351 |
|
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
1352 |
|
$val['external_uids'] = $val_external_uid; |
1353 |
|
} |
1354 |
|
// XXX WIP |
1355 |
|
if ($this->getVal('type') === 'creation_consultation') { |
1356 |
|
// |
1357 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1358 |
|
$val['consultation'] = $this->get_consultation_data($this->getVal('object_id')); |
1359 |
|
$val['service'] = $this->get_service_data($val['consultation']['service']); |
1360 |
|
$val_external_uid = array(); |
1361 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1362 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1363 |
|
$val['external_uids'] = $val_external_uid; |
1364 |
|
} |
1365 |
|
// |
1366 |
|
if ($this->getVal('type') === 'notification_instruction' |
1367 |
|
|| $this->getVal('type') === 'notification_recepisse' |
1368 |
|
|| $this->getVal('type') === 'notification_decision') { |
1369 |
|
// |
1370 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1371 |
|
$val['demandeur'] = $this->get_demandeurs_data($this->getVal('dossier')); |
1372 |
|
$val['instruction_notification'] = $this->get_instruction_notification_data($this->getVal('category'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
1373 |
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $val['instruction_notification']['instruction'])); |
1374 |
|
$val_external_uid = array(); |
1375 |
|
$val_external_uid['demande'] = $this->get_external_uid($val['dossier']['dossier'], 'demande'); |
1376 |
|
$val['external_uids'] = $val_external_uid; |
1377 |
|
} |
1378 |
|
|
1379 |
|
if ($in_field === true) { |
1380 |
|
return json_encode($val, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
1381 |
|
} else { |
1382 |
|
// Liste des valeurs affichée en JSON |
1383 |
|
printf(json_encode($val, JSON_UNESCAPED_SLASHES)); |
1384 |
|
} |
1385 |
|
} |
1386 |
|
} |
1387 |
|
|
1388 |
|
function post_update_task() { |
1389 |
|
// Mise à jour des valeurs |
1390 |
|
|
1391 |
|
// Modification de l'état de la tâche |
1392 |
|
if ($this->f->get_submitted_post_value('state') !== null) { |
1393 |
$params = array( |
$params = array( |
1394 |
'val' => array( |
'val' => array( |
1395 |
'state' => $this->f->get_submitted_post_value('state') |
'state' => $this->f->get_submitted_post_value('state') |
1409 |
} |
} |
1410 |
$this->f->displayMessage($message_class, $message); |
$this->f->displayMessage($message_class, $message); |
1411 |
} |
} |
1412 |
|
|
1413 |
|
// Sauvegarde de l'uid externe retourné |
1414 |
|
if ($this->f->get_submitted_post_value('external_uid') !== null) { |
1415 |
|
// |
1416 |
|
$objects = $this->get_objects_by_task_type($this->getVal('type'), $this->getVal('stream')); |
1417 |
|
foreach ($objects as $object) { |
1418 |
|
$inst_lien = $this->f->get_inst__om_dbform(array( |
1419 |
|
"obj" => "lien_id_interne_uid_externe", |
1420 |
|
"idx" => ']', |
1421 |
|
)); |
1422 |
|
if ($inst_lien->is_exists($object, $this->getVal('object_id'), $this->f->get_submitted_post_value('external_uid'), $this->getVal('dossier')) === false) { |
1423 |
|
$valF = array( |
1424 |
|
'lien_id_interne_uid_externe' => '', |
1425 |
|
'object' => $object, |
1426 |
|
'object_id' => $this->getVal('object_id'), |
1427 |
|
'external_uid' => $this->f->get_submitted_post_value('external_uid'), |
1428 |
|
'dossier' => $this->getVal('dossier'), |
1429 |
|
'category' => $this->getVal('category'), |
1430 |
|
); |
1431 |
|
$add = $inst_lien->ajouter($valF); |
1432 |
|
$message_class = "valid"; |
1433 |
|
$message = $inst_lien->msg; |
1434 |
|
if ($add === false) { |
1435 |
|
$this->addToLog($inst_lien->msg, DEBUG_MODE); |
1436 |
|
$message_class = "error"; |
1437 |
|
$message = sprintf( |
1438 |
|
'%s %s', |
1439 |
|
__("Impossible de mettre à jour le lien entre l'identifiant interne et l'identifiant de l'application externe."), |
1440 |
|
__('Veuillez contacter votre administrateur.') |
1441 |
|
); |
1442 |
|
} |
1443 |
|
$this->f->displayMessage($message_class, $message); |
1444 |
|
} |
1445 |
|
} |
1446 |
|
} |
1447 |
} |
} |
1448 |
|
|
1449 |
|
function post_add_task() { |
1450 |
|
// TODO Tester de remplacer la ligne de json_payload par un $_POST |
1451 |
|
$result = $this->add_task(array( |
1452 |
|
'val' => array( |
1453 |
|
'stream' => 'input', |
1454 |
|
'json_payload' => html_entity_decode($this->f->get_submitted_post_value('json_payload')), |
1455 |
|
'type' => $this->f->get_submitted_post_value('type'), |
1456 |
|
'category' => $this->f->get_submitted_post_value('category'), |
1457 |
|
) |
1458 |
|
)); |
1459 |
|
$message = sprintf( |
1460 |
|
__("Tâche %s ajoutée avec succès"), |
1461 |
|
$this->getVal($this->clePrimaire)). |
1462 |
|
'<br/><br/>'. |
1463 |
|
$this->msg; |
1464 |
|
$message_class = "valid"; |
1465 |
|
if ($result === false){ |
1466 |
|
$this->addToLog($this->msg, DEBUG_MODE); |
1467 |
|
$message_class = "error"; |
1468 |
|
$message = sprintf( |
1469 |
|
'%s %s', |
1470 |
|
__('Impossible d\'ajouter la tâche.'), |
1471 |
|
__('Veuillez contacter votre administrateur.') |
1472 |
|
); |
1473 |
|
} |
1474 |
|
$this->f->displayMessage($message_class, $message); |
1475 |
|
} |
1476 |
|
|
1477 |
|
function setLayout(&$form, $maj) { |
1478 |
|
|
1479 |
|
// Récupération du mode de l'action |
1480 |
|
$crud = $this->get_action_crud($maj); |
1481 |
|
|
1482 |
|
// MODE different de CREER |
1483 |
|
if ($maj != 0 || $crud != 'create') { |
1484 |
|
$form->setBloc('json_payload', 'D', '', 'col_6'); |
1485 |
|
$form->setFieldset('json_payload', 'DF', __("json_payload"), "collapsible, startClosed"); |
1486 |
|
$form->setBloc('json_payload', 'F'); |
1487 |
|
} |
1488 |
|
$form->setBloc('timestamp_log', 'DF', '', 'col_9'); |
1489 |
|
} |
1490 |
|
|
1491 |
|
/** |
1492 |
|
* [get_objects_by_task_type description] |
1493 |
|
* @param [type] $type [description] |
1494 |
|
* @return [type] [description] |
1495 |
|
*/ |
1496 |
|
function get_objects_by_task_type($type, $stream = 'all') { |
1497 |
|
$objects = array(); |
1498 |
|
if (in_array($type, array('creation_DA', 'modification_DA', )) === true) { |
1499 |
|
$objects = array('dossier_autorisation', ); |
1500 |
|
} |
1501 |
|
if (in_array($type, array('creation_DI', 'depot_DI', 'notification_DI', 'qualification_DI', )) === true) { |
1502 |
|
$objects = array('dossier', ); |
1503 |
|
} |
1504 |
|
if (in_array($type, array('create_DI_for_consultation', )) === true) { |
1505 |
|
$objects = array('dossier', 'dossier_consultation', ); |
1506 |
|
} |
1507 |
|
if (in_array($type, array('create_DI', )) === true |
1508 |
|
&& $stream === 'input') { |
1509 |
|
$objects = array('dossier', 'dossier_autorisation', 'demande', ); |
1510 |
|
} |
1511 |
|
if (in_array($type, array('decision_DI', 'incompletude_DI', 'completude_DI', )) === true) { |
1512 |
|
$objects = array('instruction', ); |
1513 |
|
} |
1514 |
|
if (in_array($type, array('pec_metier_consultation', )) === true |
1515 |
|
&& $stream === 'output') { |
1516 |
|
$objects = array('pec_dossier_consultation', ); |
1517 |
|
} |
1518 |
|
if (in_array($type, array('avis_consultation', )) === true |
1519 |
|
&& $stream === 'output') { |
1520 |
|
$objects = array('avis_dossier_consultation', ); |
1521 |
|
} |
1522 |
|
if (in_array($type, array('ajout_piece', 'add_piece', )) === true) { |
1523 |
|
$objects = array('piece', ); |
1524 |
|
} |
1525 |
|
if (in_array($type, array('creation_consultation', )) === true) { |
1526 |
|
$objects = array('consultation', ); |
1527 |
|
} |
1528 |
|
if (in_array($type, array('pec_metier_consultation', )) === true |
1529 |
|
&& $stream === 'input') { |
1530 |
|
$objects = array('pec_metier_consultation', ); |
1531 |
|
} |
1532 |
|
if (in_array($type, array('avis_consultation', )) === true |
1533 |
|
&& $stream === 'input') { |
1534 |
|
$objects = array('avis_consultation', ); |
1535 |
|
} |
1536 |
|
if (in_array($type, array('create_message', )) === true |
1537 |
|
&& $stream === 'input') { |
1538 |
|
$objects = array('dossier_message', ); |
1539 |
|
} |
1540 |
|
if (in_array($type, array('notification_recepisse', 'notification_instruction', 'notification_decision' )) === true) { |
1541 |
|
$objects = array('instruction_notification', ); |
1542 |
|
} |
1543 |
|
return $objects; |
1544 |
|
} |
1545 |
|
|
1546 |
} |
} |