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 |
|
'envoi_CL', |
36 |
|
'notification_recepisse', |
37 |
|
'notification_instruction', |
38 |
|
'notification_decision', |
39 |
|
'notification_service_consulte', |
40 |
|
'notification_tiers_consulte', |
41 |
|
'notification_depot_demat', |
42 |
|
'notification_commune', |
43 |
|
'notification_signataire', |
44 |
|
'lettre_incompletude', |
45 |
|
'lettre_majoration' |
46 |
|
); |
47 |
|
|
48 |
|
/** |
49 |
|
* Liste des types de tâche concernant les services consultés |
50 |
|
*/ |
51 |
|
const TASK_TYPE_SC = array( |
52 |
|
'create_DI_for_consultation', |
53 |
|
'avis_consultation', |
54 |
|
'pec_metier_consultation', |
55 |
|
'create_message', |
56 |
|
'notification_recepisse', |
57 |
|
'notification_instruction', |
58 |
|
'notification_decision', |
59 |
|
'notification_service_consulte', |
60 |
|
'notification_tiers_consulte', |
61 |
|
'notification_depot_demat', |
62 |
|
'prescription', |
63 |
|
); |
64 |
|
|
65 |
|
/** |
66 |
|
* Liste des types de tâche pouvant avoir des documents associés |
67 |
|
*/ |
68 |
|
const TASK_WITH_DOCUMENT = array( |
69 |
|
'add_piece', |
70 |
|
'avis_consultation', |
71 |
|
'pec_metier_consultation' |
72 |
|
); |
73 |
|
|
74 |
|
/** |
75 |
|
* Préfixe pour identifier les codes de suivi |
76 |
|
* @var string |
77 |
|
*/ |
78 |
|
const CS_PREFIX = 'code-suivi://'; |
79 |
|
|
80 |
|
/** |
81 |
|
* Catégorie de la tâche |
82 |
|
*/ |
83 |
|
var $category = PLATAU; |
84 |
|
|
85 |
/** |
/** |
86 |
* Définition des actions disponibles sur la classe. |
* Définition des actions disponibles sur la classe. |
87 |
* |
* |
95 |
"view" => "view_json_data", |
"view" => "view_json_data", |
96 |
"permission_suffix" => "consulter", |
"permission_suffix" => "consulter", |
97 |
); |
); |
98 |
|
$this->class_actions[997] = array( |
99 |
|
"identifier" => "json_data", |
100 |
|
"view" => "post_update_task", |
101 |
|
"permission_suffix" => "modifier", |
102 |
|
); |
103 |
|
$this->class_actions[996] = array( |
104 |
|
"identifier" => "json_data", |
105 |
|
"view" => "post_add_task", |
106 |
|
"permission_suffix" => "ajouter", |
107 |
|
); |
108 |
|
} |
109 |
|
|
110 |
|
public function setvalF($val = array()) { |
111 |
|
|
112 |
|
// // les guillets doubles sont remplacés automatiquement par des simples |
113 |
|
// // dans core/om_formulaire.clasS.php::recupererPostvar() |
114 |
|
// // voir le ticket https://dev.atreal.fr/projets/openmairie/tracker/209 |
115 |
|
// // ceci est un hack sale temporaire en attendant résolution du ticket |
116 |
|
// foreach(array('json_payload', 'timestamp_log') as $key) { |
117 |
|
// if (isset($val[$key]) && ! empty($val[$key]) && |
118 |
|
// isset($_POST[$key]) && ! empty($_POST[$key])) { |
119 |
|
// $submited_payload = $_POST[$key]; |
120 |
|
// if (! empty($submited_payload)) { |
121 |
|
// $new_payload = str_replace("'", '"', $val[$key]); |
122 |
|
// if ($new_payload == $submited_payload || |
123 |
|
// strpos($submited_payload, '"') === false) { |
124 |
|
// $val[$key] = $new_payload; |
125 |
|
// } |
126 |
|
// else { |
127 |
|
// $error_msg = sprintf( |
128 |
|
// __("La convertion des guillemets de la payload JSON '%s' ". |
129 |
|
// "n'est pas idempotente (courante: %s, postée: %s, convertie: %s)"), |
130 |
|
// $key, var_export($val[$key], true), var_export($submited_payload, true), |
131 |
|
// var_export($new_payload, true)); |
132 |
|
// $this->correct = false; |
133 |
|
// $this->addToMessage($error_msg); |
134 |
|
// $this->addToLog(__METHOD__."() erreur : $error_msg", DEBUG_MODE); |
135 |
|
// return false; |
136 |
|
// } |
137 |
|
// } |
138 |
|
// } |
139 |
|
// } |
140 |
|
|
141 |
|
parent::setvalF($val); |
142 |
|
|
143 |
|
// XXX Ancien code : permet de ne pas avoir d'erreru lors de la modification d'une task |
144 |
|
if (array_key_exists('timestamp_log', $val) === true) { |
145 |
|
$this->valF['timestamp_log'] = str_replace("'", '"', $val['timestamp_log']); |
146 |
|
} |
147 |
|
|
148 |
|
// récupération de l'ID de l'objet existant |
149 |
|
$id = property_exists($this, 'id') ? $this->id : null; |
150 |
|
if(isset($val[$this->clePrimaire])) { |
151 |
|
$id = $val[$this->clePrimaire]; |
152 |
|
} elseif(isset($this->valF[$this->clePrimaire])) { |
153 |
|
$id = $this->valF[$this->clePrimaire]; |
154 |
|
} |
155 |
|
|
156 |
|
// MODE MODIFIER |
157 |
|
if (! empty($id)) { |
158 |
|
|
159 |
|
// si aucune payload n'est fourni (devrait toujours être le cas) |
160 |
|
if (! isset($val['json_payload']) || empty($val['json_payload'])) { |
161 |
|
|
162 |
|
// récupère l'objet existant |
163 |
|
$existing = $this->f->findObjectById('task', $id); |
164 |
|
if (! empty($existing)) { |
165 |
|
|
166 |
|
// récupère la payload de l'objet |
167 |
|
$val['json_payload'] = $existing->getVal('json_payload'); |
168 |
|
$this->valF['json_payload'] = $existing->getVal('json_payload'); |
169 |
|
$this->f->addToLog(__METHOD__."() récupère la payload de la tâche existante ". |
170 |
|
"'$id': ".$existing->getVal('json_payload'), EXTRA_VERBOSE_MODE); |
171 |
|
} |
172 |
|
} |
173 |
|
} |
174 |
|
|
175 |
|
if (array_key_exists('category', $val) === false |
176 |
|
|| $this->valF['category'] === '' |
177 |
|
|| $this->valF['category'] === null) { |
178 |
|
// |
179 |
|
$this->valF['category'] = $this->category; |
180 |
|
} |
181 |
|
|
182 |
|
// Si last_modification_time est vide, la valeur est remplacée par NULL |
183 |
|
// pour eviter d'avoir une erreur de base de données car le champ est au format time. |
184 |
|
if ($val['last_modification_time'] == "") { |
185 |
|
$this->valF['last_modification_time'] = NULL; |
186 |
|
} else { |
187 |
|
$this->valF['last_modification_time'] = $val['last_modification_time']; |
188 |
|
} |
189 |
|
|
190 |
|
// Si creation_time est vide, la valeur est remplacée par NULL |
191 |
|
// pour eviter d'avoir une erreur de base de données car le champ est au format time. |
192 |
|
if ($val['creation_time'] == "") { |
193 |
|
$this->valF['creation_time'] = NULL; |
194 |
|
} else { |
195 |
|
$this->valF['creation_time'] = $val['creation_time']; |
196 |
|
} |
197 |
|
} |
198 |
|
|
199 |
|
/** |
200 |
|
* |
201 |
|
* @return array |
202 |
|
*/ |
203 |
|
function get_var_sql_forminc__champs() { |
204 |
|
return array( |
205 |
|
"task", |
206 |
|
"type", |
207 |
|
"state", |
208 |
|
"object_id", |
209 |
|
"dossier", |
210 |
|
"stream", |
211 |
|
"creation_date", |
212 |
|
"creation_time", |
213 |
|
"CONCAT_WS(' ', to_char(task.creation_date, 'DD/MM/YYYY'), task.creation_time) AS date_creation", |
214 |
|
'last_modification_date', |
215 |
|
'last_modification_time', |
216 |
|
"CONCAT_WS(' ', to_char(task.last_modification_date, 'DD/MM/YYYY'), task.last_modification_time) AS date_modification", |
217 |
|
"comment", |
218 |
|
"json_payload", |
219 |
|
"timestamp_log", |
220 |
|
"timestamp_log AS timestamp_log_hidden", |
221 |
|
"category", |
222 |
|
); |
223 |
|
} |
224 |
|
|
225 |
|
function setType(&$form, $maj) { |
226 |
|
parent::setType($form, $maj); |
227 |
|
|
228 |
|
// Récupération du mode de l'action |
229 |
|
$crud = $this->get_action_crud($maj); |
230 |
|
|
231 |
|
// ALL |
232 |
|
$form->setType("category", "hidden"); |
233 |
|
$form->setType("timestamp_log_hidden", "hidden"); |
234 |
|
|
235 |
|
// MODE CREER |
236 |
|
if ($maj == 0 || $crud == 'create') { |
237 |
|
$form->setType("type", "select"); |
238 |
|
$form->setType("state", "select"); |
239 |
|
$form->setType("stream", "select"); |
240 |
|
$form->setType("json_payload", "textarea"); |
241 |
|
} |
242 |
|
// MODE MODIFIER |
243 |
|
if ($maj == 1 || $crud == 'update') { |
244 |
|
$form->setType("task", "hiddenstatic"); |
245 |
|
$form->setType("state", "select"); |
246 |
|
$form->setType("stream", "hiddenstatic"); |
247 |
|
$form->setType("json_payload", "jsonprettyprint"); |
248 |
|
$form->setType("timestamp_log", "jsontotab"); |
249 |
|
$form->setType("type", "hiddenstatic"); |
250 |
|
$form->setType("creation_date", "hidden"); |
251 |
|
$form->setType("creation_time", "hidden"); |
252 |
|
$form->setType("object_id", "hiddenstatic"); |
253 |
|
$form->setType("dossier", "hiddenstatic"); |
254 |
|
$form->setType("date_creation", "hiddenstatic"); |
255 |
|
$form->setType("last_modification_date", "hidden"); |
256 |
|
$form->setType("last_modification_time", "hidden"); |
257 |
|
$form->setType("date_modification", "static"); |
258 |
|
} |
259 |
|
// MODE CONSULTER |
260 |
|
if ($maj == 3 || $crud == 'read') { |
261 |
|
$form->setType("state", "selecthiddenstatic"); |
262 |
|
$form->setType("stream", "selecthiddenstatic"); |
263 |
|
$form->setType('dossier', 'link'); |
264 |
|
$form->setType('json_payload', 'jsonprettyprint'); |
265 |
|
$form->setType("type", "selecthiddenstatic"); |
266 |
|
$form->setType("creation_date", "hidden"); |
267 |
|
$form->setType("creation_time", "hidden"); |
268 |
|
$form->setType("date_creation", "static"); |
269 |
|
$form->setType("last_modification_date", "hidden"); |
270 |
|
$form->setType("last_modification_time", "hidden"); |
271 |
|
$form->setType("date_modification", "static"); |
272 |
|
$form->setType("timestamp_log", "jsontotab"); |
273 |
|
} |
274 |
|
} |
275 |
|
|
276 |
|
function stateTranslation ($currentState) { |
277 |
|
switch ($currentState){ |
278 |
|
case "draft": |
279 |
|
return __('brouillon'); |
280 |
|
break; |
281 |
|
case "new": |
282 |
|
return __('à traiter'); |
283 |
|
break; |
284 |
|
case "pending": |
285 |
|
return __('en cours'); |
286 |
|
break; |
287 |
|
case "done": |
288 |
|
return __('terminé'); |
289 |
|
break; |
290 |
|
case "archived": |
291 |
|
return __('archivé'); |
292 |
|
break; |
293 |
|
case "error": |
294 |
|
return __('erreur'); |
295 |
|
break; |
296 |
|
case "debug": |
297 |
|
return __('debug'); |
298 |
|
break; |
299 |
|
case "canceled": |
300 |
|
return __('annulé'); |
301 |
|
break; |
302 |
|
} |
303 |
|
} |
304 |
|
/** |
305 |
|
* |
306 |
|
*/ |
307 |
|
function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) { |
308 |
|
if($maj <= 3) { |
309 |
|
$contenu = array(); |
310 |
|
foreach(array('DRAFT', 'NEW', 'PENDING', 'DONE', 'ERROR', 'DEBUG', 'ARCHIVED', 'CANCELED') as $key) { |
311 |
|
$const_name = 'STATUS_'.$key; |
312 |
|
$const_value = constant("self::$const_name"); |
313 |
|
$contenu[0][] = $const_value; |
314 |
|
|
315 |
|
|
316 |
|
$contenu[1][] = $this->stateTranslation($const_value); |
317 |
|
|
318 |
|
} |
319 |
|
|
320 |
|
$form->setSelect("state", $contenu); |
321 |
|
|
322 |
|
$contenu_stream =array(); |
323 |
|
$contenu_stream[0][0]="input"; |
324 |
|
$contenu_stream[1][0]=__('input'); |
325 |
|
$contenu_stream[0][1]="output"; |
326 |
|
$contenu_stream[1][1]=__('output'); |
327 |
|
$form->setSelect("stream", $contenu_stream); |
328 |
|
|
329 |
|
$tab_type = array_unique(array_merge(self::TASK_TYPE_SI, self::TASK_TYPE_SC)); |
330 |
|
|
331 |
|
foreach ($tab_type as $type) { |
332 |
|
|
333 |
|
$contenu_type[0][] = $type; |
334 |
|
|
335 |
|
switch ($type) { |
336 |
|
case "creation_DA": |
337 |
|
$value_type = __('Création DA'); |
338 |
|
break; |
339 |
|
case "create_DI": |
340 |
|
$value_type = __('Création demande'); |
341 |
|
break; |
342 |
|
case "creation_DI": |
343 |
|
$value_type = __('Création DI'); |
344 |
|
break; |
345 |
|
case "modification_DA": |
346 |
|
$value_type = __('Modification DA'); |
347 |
|
break; |
348 |
|
case "modification_DI": |
349 |
|
$value_type = __('Modification DI'); |
350 |
|
break; |
351 |
|
case "ajout_piece": |
352 |
|
$value_type = __('Ajout pièce (sortant)'); |
353 |
|
break; |
354 |
|
case "add_piece": |
355 |
|
$value_type = __('Ajout pièce (entrant)'); |
356 |
|
break; |
357 |
|
case "depot_DI": |
358 |
|
$value_type = __('Dépôt DI'); |
359 |
|
break; |
360 |
|
case "qualification_DI": |
361 |
|
$value_type = __('Qualification DI'); |
362 |
|
break; |
363 |
|
case "creation_consultation": |
364 |
|
$value_type = __('Création consultation'); |
365 |
|
break; |
366 |
|
case "decision_DI": |
367 |
|
$value_type = __('Décision DI'); |
368 |
|
break; |
369 |
|
case "envoi_CL": |
370 |
|
$value_type = __('Envoi contrôle de légalité'); |
371 |
|
break; |
372 |
|
case "pec_metier_consultation": |
373 |
|
$value_type = __('PeC consultation'); |
374 |
|
break; |
375 |
|
case "avis_consultation": |
376 |
|
$value_type = __('Avis'); |
377 |
|
break; |
378 |
|
case "prescription": |
379 |
|
$value_type = __('Prescription'); |
380 |
|
break; |
381 |
|
case "create_DI_for_consultation": |
382 |
|
$value_type = __('Création DI pour consultation'); |
383 |
|
break; |
384 |
|
case "create_message": |
385 |
|
$value_type = __('Message'); |
386 |
|
break; |
387 |
|
case "notification_recepisse": |
388 |
|
$value_type = __('Notification récépissé'); |
389 |
|
break; |
390 |
|
case "notification_instruction": |
391 |
|
$value_type = __('Notification instruction'); |
392 |
|
break; |
393 |
|
case "notification_decision": |
394 |
|
$value_type = __('Notification décision'); |
395 |
|
break; |
396 |
|
case "notification_service_consulte": |
397 |
|
$value_type = __('Notification service consulté'); |
398 |
|
break; |
399 |
|
case "notification_tiers_consulte": |
400 |
|
$value_type = __('Notification tiers consulté'); |
401 |
|
break; |
402 |
|
case "notification_signataire": |
403 |
|
$value_type = __('Notification signataire'); |
404 |
|
break; |
405 |
|
case "completude_DI": |
406 |
|
$value_type = __('complétude DI'); |
407 |
|
break; |
408 |
|
case "incompletude_DI": |
409 |
|
$value_type = __('incomplétude DI'); |
410 |
|
break; |
411 |
|
case "lettre_incompletude": |
412 |
|
$value_type = __('Lettre au pétitionnaire d\'incompletude'); |
413 |
|
break; |
414 |
|
case "lettre_majoration": |
415 |
|
$value_type = __('Lettre au pétitionnaire de majoration'); |
416 |
|
break; |
417 |
|
} |
418 |
|
|
419 |
|
$contenu_type[1][] = $value_type; |
420 |
|
} |
421 |
|
|
422 |
|
$form->setselect('type', $contenu_type); |
423 |
|
} |
424 |
|
|
425 |
|
if ($maj == 3) { |
426 |
|
// Récupération du numéro du dossier si il n'est pas renseigné dans la tâche |
427 |
|
if ($form->val['dossier'] == '' || $form->val['dossier'] == null) { |
428 |
|
// Récupération de la payload de la taĉhe. |
429 |
|
// Si la tâche est une tâche input la payload est associée à la tâche. |
430 |
|
// Si la tâche est une tâche en output la payload est "calculé" à l'ouverture |
431 |
|
// du formulaire. |
432 |
|
if ($this->getVal('stream') == 'input') { |
433 |
|
$json_payload = json_decode($this->getVal('json_payload'), true); |
434 |
|
} else { |
435 |
|
$json_payload = json_decode($form->val['json_payload'], true); |
436 |
|
} |
437 |
|
// A partir de la payload de la tâche ont récupère les externals uid |
438 |
|
// Si un external uid de DI (dossier) existe ont le récupère et on stocke le numéro |
439 |
|
// pour l'afficher sur le formulaire. |
440 |
|
// Si l'external UID du DI n'existe pas on récupère celui du DA |
441 |
|
$external_uid = ''; |
442 |
|
if (array_key_exists('external_uids', $json_payload) |
443 |
|
&& array_key_exists('dossier', $json_payload['external_uids']) |
444 |
|
) { |
445 |
|
$external_uid = $json_payload['external_uids']['dossier']; |
446 |
|
} elseif (array_key_exists('external_uids', $json_payload) |
447 |
|
&& array_key_exists('demande', $json_payload['external_uids'])) { |
448 |
|
$external_uid = $json_payload['external_uids']['demande']; |
449 |
|
} |
450 |
|
// Recherche l'external uid dans la base de données pour récupèrer le numéro de |
451 |
|
// DI / DA correspondant. On stocke le numéro de dossier dans la propriété val |
452 |
|
// du formulaire pour pouvoir l'afficher |
453 |
|
if ($external_uid != '') { |
454 |
|
$qres = $this->f->get_one_result_from_db_query( |
455 |
|
sprintf( |
456 |
|
'SELECT |
457 |
|
lien_id_interne_uid_externe.dossier |
458 |
|
FROM |
459 |
|
%1$slien_id_interne_uid_externe |
460 |
|
WHERE |
461 |
|
lien_id_interne_uid_externe.external_uid = \'%2$s\'', |
462 |
|
DB_PREFIXE, |
463 |
|
$this->f->db->escapeSimple($external_uid) |
464 |
|
), |
465 |
|
array( |
466 |
|
"origin" => __METHOD__, |
467 |
|
) |
468 |
|
); |
469 |
|
if (! empty($qres["result"])) { |
470 |
|
$form->val['dossier'] = $qres["result"]; |
471 |
|
} |
472 |
|
} |
473 |
|
} |
474 |
|
|
475 |
|
// Vérifie si le numéro de dossier associé à la tâche existe dans la base. |
476 |
|
// Si c'est le cas ce numéro sera lié au dossier (DI ou DA) correspondant |
477 |
|
// TODO : vérifier la liste des tâches lié à des DA |
478 |
|
$obj_link = ''; |
479 |
|
if ($form->val['type'] == "creation_DA" || $form->val['type'] == "modification_DA") { |
480 |
|
// Vérification que le numéro de DA affiché dans le formulaire existe |
481 |
|
$qres = $this->f->get_one_result_from_db_query( |
482 |
|
sprintf( |
483 |
|
'SELECT |
484 |
|
dossier_autorisation.dossier_autorisation |
485 |
|
FROM |
486 |
|
%1$sdossier_autorisation |
487 |
|
WHERE |
488 |
|
dossier_autorisation.dossier_autorisation = \'%2$s\'', |
489 |
|
DB_PREFIXE, |
490 |
|
$this->f->db->escapeSimple($form->val['dossier']) |
491 |
|
), |
492 |
|
array( |
493 |
|
"origin" => __METHOD__, |
494 |
|
) |
495 |
|
); |
496 |
|
// Si on a un résultat c'est que le dossier existe, il faut afficher le lien |
497 |
|
if (! empty($qres["result"])) { |
498 |
|
$obj_link = 'dossier_autorisation'; |
499 |
|
} |
500 |
|
} else { |
501 |
|
// Vérification que le numéro de DI affiché dans le formulaire existe |
502 |
|
$qres = $this->f->get_one_result_from_db_query( |
503 |
|
sprintf( |
504 |
|
'SELECT |
505 |
|
dossier.dossier |
506 |
|
FROM |
507 |
|
%1$sdossier |
508 |
|
WHERE |
509 |
|
dossier.dossier = \'%2$s\'', |
510 |
|
DB_PREFIXE, |
511 |
|
$this->f->db->escapeSimple($form->val['dossier']) |
512 |
|
), |
513 |
|
array( |
514 |
|
"origin" => __METHOD__, |
515 |
|
) |
516 |
|
); |
517 |
|
// Si on a un résultat c'est que le dossier existe, il faut afficher le lien |
518 |
|
if (! empty($qres["result"])) { |
519 |
|
$obj_link = 'dossier_instruction'; |
520 |
|
} |
521 |
|
} |
522 |
|
// Pour afficher le lien vers un dossier ont utilise un champ de type "link". |
523 |
|
// Pour paramétrer ce champs on a besoin de savoir : |
524 |
|
// - quel objet est visé par le lien |
525 |
|
// - le label (libellé) du lien |
526 |
|
// - l'identifiant de l'objet qui sera utilisé dans le lien |
527 |
|
// - le titre associé au lien |
528 |
|
// Pour cela on remplit le champs comme un select et les valeurs du select |
529 |
|
// contiennent les informations nécessaire à l'affichage du champs. |
530 |
|
$params = array( |
531 |
|
'obj' => $obj_link, |
532 |
|
'libelle' => $form->val['dossier'], |
533 |
|
'title' => "Consulter le dossier", |
534 |
|
'idx' => $form->val['dossier'] |
535 |
|
); |
536 |
|
$form->setSelect("dossier", $params); |
537 |
|
} |
538 |
|
} |
539 |
|
|
540 |
|
/** |
541 |
|
* SETTER_FORM - setVal (setVal). |
542 |
|
* |
543 |
|
* @return void |
544 |
|
*/ |
545 |
|
function setVal(&$form, $maj, $validation, &$dnu1 = null, $dnu2 = null) { |
546 |
|
// parent::setVal($form, $maj, $validation); |
547 |
|
// |
548 |
|
if ($this->getVal('stream') == "output" |
549 |
|
&& ($this->getVal('state') !== self::STATUS_DONE |
550 |
|
|| $this->getVal('json_payload') === "{}")) { |
551 |
|
// |
552 |
|
$form->setVal('json_payload', $this->view_form_json(true)); |
553 |
|
} else { |
554 |
|
$form->setVal('json_payload', json_encode(json_decode($this->getVal('json_payload'), true), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); |
555 |
|
} |
556 |
|
// Gestion du contenu de l'historique |
557 |
|
if ($this->getVal('timestamp_log') !== '' |
558 |
|
&& $this->getVal('timestamp_log') !== null) { |
559 |
|
// |
560 |
|
$form->setVal('timestamp_log', $this->getVal('timestamp_log')); |
561 |
|
} |
562 |
|
} |
563 |
|
|
564 |
|
function setLib(&$form, $maj) { |
565 |
|
parent::setLib($form, $maj); |
566 |
|
|
567 |
|
// Récupération du mode de l'action |
568 |
|
$crud = $this->get_action_crud($maj); |
569 |
|
|
570 |
|
$form->setLib('date_creation', __("Date de création")); |
571 |
|
$form->setLib('date_modification', __("Date de dernière modification")); |
572 |
|
$form->setLib('comment', __("commentaire")); |
573 |
|
|
574 |
|
// MODE different de CREER |
575 |
|
if ($maj != 0 || $crud != 'create') { |
576 |
|
$form->setLib('json_payload', ''); |
577 |
|
$form->setLib("task", __("identifiant")); |
578 |
|
$form->setLib("Task_portal", __("task_portal")); |
579 |
|
$form->setLib("type", __("type")); |
580 |
|
$form->setLib("object_id", __("Réf. interne")); |
581 |
|
$form->setLib("stream", __("flux")); |
582 |
|
$form->setLib("timestamp_log", __("Historique")); |
583 |
|
} |
584 |
|
} |
585 |
|
|
586 |
|
public function verifier($val = array(), &$dnu1 = null, $dnu2 = null) { |
587 |
|
$ret = parent::verifier($val, $dnu1, $dnu2); |
588 |
|
|
589 |
|
// une tâche entrante doit avoir un type et une payload non-vide |
590 |
|
if (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') { |
591 |
|
if (isset($this->valF['type']) === false) { |
592 |
|
$this->correct = false; |
593 |
|
$this->addToMessage(sprintf( |
594 |
|
__("Le champ %s est obligatoire pour une tâche entrante."), |
595 |
|
sprintf('<span class="bold">%s</span>', $this->getLibFromField('type')) |
596 |
|
)); |
597 |
|
$this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE); |
598 |
|
} |
599 |
|
if (isset($this->valF['json_payload']) === false) { |
600 |
|
$this->correct = false; |
601 |
|
$this->addToMessage(sprintf( |
602 |
|
__("Le champ %s est obligatoire pour une tâche entrante."), |
603 |
|
sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload')) |
604 |
|
)); |
605 |
|
$this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE); |
606 |
|
} |
607 |
|
} |
608 |
|
|
609 |
|
// les JSONs doivent être décodables |
610 |
|
foreach(array('json_payload', 'timestamp_log') as $key) { |
611 |
|
if (isset($this->valF[$key]) && ! empty($this->valF[$key]) && ( |
612 |
|
is_array(json_decode($this->valF[$key], true)) === false |
613 |
|
|| json_last_error() !== JSON_ERROR_NONE)) { |
614 |
|
$this->correct = false; |
615 |
|
$champ_text = sprintf('<span class="bold">%s</span>', $this->getLibFromField($key)); |
616 |
|
$this->addToMessage(sprintf( |
617 |
|
__("Le champ %s doit être dans un format JSON valide (erreur: %s).". |
618 |
|
"<p>%s valF:</br><pre>%s</pre></p>". |
619 |
|
"<p>%s val:</br><pre>%s</pre></p>". |
620 |
|
"<p>%s POST:</br><pre>%s</pre></p>". |
621 |
|
"<p>%s submitted POST value:</br><pre>%s</pre></p>"), |
622 |
|
$champ_text, |
623 |
|
json_last_error() !== JSON_ERROR_NONE ? json_last_error_msg() : __('invalide'), |
624 |
|
$champ_text, |
625 |
|
$this->valF[$key], |
626 |
|
$champ_text, |
627 |
|
$val[$key], |
628 |
|
$champ_text, |
629 |
|
isset($_POST[$key]) ? $_POST[$key] : '', |
630 |
|
$champ_text, |
631 |
|
$this->f->get_submitted_post_value($key) |
632 |
|
)); |
633 |
|
$this->addToLog(__METHOD__.'(): erreur JSON: '.$this->msg, DEBUG_MODE); |
634 |
|
} |
635 |
|
} |
636 |
|
|
637 |
|
// une tâche entrante doit avoir une payload avec les clés requises |
638 |
|
if ($this->correct && (isset($this->valF['stream']) === false || |
639 |
|
$this->valF['stream'] == 'input')) { |
640 |
|
|
641 |
|
// décode la payload JSON |
642 |
|
// TODO : COMMENTER |
643 |
|
$json_payload = json_decode($this->valF['json_payload'], true); |
644 |
|
|
645 |
|
// défini une liste de chemin de clés requises |
646 |
|
$paths = array(); |
647 |
|
if ($this->valF['category'] === PLATAU) { |
648 |
|
$paths = array( |
649 |
|
'external_uids/dossier' |
650 |
|
); |
651 |
|
} |
652 |
|
|
653 |
|
// tâche de type création de DI/DA |
654 |
|
if (isset($this->valF['type']) !== false && $this->valF['type'] == 'create_DI_for_consultation') { |
655 |
|
|
656 |
|
$paths = array_merge($paths, array( |
657 |
|
'dossier/dossier', |
658 |
|
'dossier/dossier_autorisation_type_detaille_code', |
659 |
|
'dossier/date_demande', |
660 |
|
'dossier/depot_electronique', |
661 |
|
)); |
662 |
|
|
663 |
|
// si l'option commune est activée (mode MC) |
664 |
|
if ($this->f->is_option_dossier_commune_enabled()) { |
665 |
|
$paths[] = 'dossier/insee'; |
666 |
|
} |
667 |
|
|
668 |
|
// présence d'un moyen d'identifier la collectivité/le service |
669 |
|
if (! isset($json_payload['external_uids']['acteur']) && |
670 |
|
! isset($json_payload['dossier']['om_collectivite'])) { |
671 |
|
$this->correct = false; |
672 |
|
$this->addToMessage(sprintf( |
673 |
|
__("L'une des clés %s ou %s est obligatoire dans le contenu du champ %s pour une tâche entrante."), |
674 |
|
sprintf('<span class="bold">%s</span>', 'external_uids/acteur'), |
675 |
|
sprintf('<span class="bold">%s</span>', 'dossier/om_collectivite'), |
676 |
|
sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload')) |
677 |
|
)); |
678 |
|
$this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE); |
679 |
|
} |
680 |
|
} |
681 |
|
|
682 |
|
// pas d'erreur déjà trouvée |
683 |
|
if($this->correct) { |
684 |
|
|
685 |
|
// pour chaque chemin |
686 |
|
foreach($paths as $path) { |
687 |
|
|
688 |
|
// décompose le chemin |
689 |
|
$tokens = explode('/', $path); |
690 |
|
$cur_depth = $json_payload; |
691 |
|
|
692 |
|
// descend au et à mesure dans l'arborescence du chemin |
693 |
|
foreach($tokens as $token) { |
694 |
|
|
695 |
|
// en vérifiant que chaque élément du chemin est défini et non-nul |
696 |
|
if (isset($cur_depth[$token]) === false) { |
697 |
|
|
698 |
|
// sinon on produit une erreur |
699 |
|
$this->correct = false; |
700 |
|
$this->addToMessage(sprintf( |
701 |
|
__("La clé %s est obligatoire dans le contenu du champ %s pour une tâche entrante."), |
702 |
|
sprintf('<span class="bold">%s</span>', $path), |
703 |
|
sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload')) |
704 |
|
)); |
705 |
|
$this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE); |
706 |
|
break 2; |
707 |
|
} |
708 |
|
$cur_depth = $cur_depth[$token]; |
709 |
|
} |
710 |
|
} |
711 |
|
} |
712 |
|
} |
713 |
|
|
714 |
|
return $ret && $this->correct; |
715 |
|
} |
716 |
|
|
717 |
|
/** |
718 |
|
* [task_exists description] |
719 |
|
* @param string $type [description] |
720 |
|
* @param string $object_id [description] |
721 |
|
* @param bool $is_not_done [description] |
722 |
|
* @return [type] [description] |
723 |
|
*/ |
724 |
|
public function task_exists(string $type, string $object_id, string $dossier = null, bool $is_not_done = true) { |
725 |
|
$qres = $this->f->get_one_result_from_db_query( |
726 |
|
sprintf( |
727 |
|
'SELECT |
728 |
|
task |
729 |
|
FROM |
730 |
|
%1$stask |
731 |
|
WHERE |
732 |
|
%2$s |
733 |
|
type = \'%3$s\' |
734 |
|
AND ( |
735 |
|
object_id = \'%4$s\' |
736 |
|
%5$s |
737 |
|
) |
738 |
|
AND state != \'%6$s\'', |
739 |
|
DB_PREFIXE, |
740 |
|
$is_not_done == true ? 'state != \''.self::STATUS_DONE.'\' AND' : '', |
741 |
|
$type, |
742 |
|
$object_id, |
743 |
|
$dossier !== null ? sprintf('OR dossier = \'%s\'', $dossier) : '', |
744 |
|
self::STATUS_CANCELED |
745 |
|
), |
746 |
|
array( |
747 |
|
"origin" => __METHOD__, |
748 |
|
) |
749 |
|
); |
750 |
|
if ($qres["result"] !== null && $qres["result"] !== "") { |
751 |
|
return $qres["result"]; |
752 |
|
} |
753 |
|
return false; |
754 |
} |
} |
755 |
|
|
756 |
protected function task_exists(string $type, string $object_id) { |
/** |
757 |
|
* Permet la recherche multi-critères des tasks. |
758 |
|
* |
759 |
|
* @param array $search_values Chaque entrée du tableau est une ligne dans le WHERE |
760 |
|
* @return mixed Retourne le résultat de la requête ou false |
761 |
|
*/ |
762 |
|
public function task_exists_multi_search(array $search_values) { |
763 |
$query = sprintf(' |
$query = sprintf(' |
764 |
SELECT task |
SELECT * |
765 |
FROM %1$stask |
FROM %1$stask |
766 |
WHERE state != \'%2$s\' |
%2$s |
767 |
AND type = \'%3$s\' |
%3$s |
768 |
AND object_id = \'%4$s\' |
ORDER BY task ASC |
769 |
', |
', |
770 |
DB_PREFIXE, |
DB_PREFIXE, |
771 |
'done', |
empty($search_values) === false ? ' WHERE ' : '', |
772 |
$type, |
implode(' AND ', $search_values) |
|
$object_id |
|
773 |
); |
); |
774 |
$res = $this->f->get_one_result_from_db_query($query); |
$res = $this->f->get_all_results_from_db_query( |
775 |
if ($res['result'] !== null && $res['result'] !== '') { |
$query, |
776 |
|
array( |
777 |
|
"origin" => __METHOD__, |
778 |
|
) |
779 |
|
); |
780 |
|
if (count($res['result']) > 0) { |
781 |
return $res['result']; |
return $res['result']; |
782 |
} |
} |
783 |
return false; |
return false; |
784 |
} |
} |
785 |
|
|
786 |
/** |
/** |
787 |
|
* TRIGGER - triggerajouter. |
788 |
|
* |
789 |
|
* @param string $id |
790 |
|
* @param null &$dnu1 @deprecated Ne pas utiliser. |
791 |
|
* @param array $val Tableau des valeurs brutes. |
792 |
|
* @param null $dnu2 @deprecated Ne pas utiliser. |
793 |
|
* |
794 |
|
* @return boolean |
795 |
|
*/ |
796 |
|
function triggerajouter($id, &$dnu1 = null, $val = array(), $dnu2 = null) { |
797 |
|
|
798 |
|
// tâche entrante |
799 |
|
if (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') { |
800 |
|
|
801 |
|
// décode la paylod JSON pour extraire les données métiers à ajouter |
802 |
|
// en tant que métadonnées de la tâche |
803 |
|
$json_payload = json_decode($this->valF['json_payload'], true); |
804 |
|
|
805 |
|
// si la tâche possède déjà une clé dossier |
806 |
|
if (isset($json_payload['dossier']['dossier']) && |
807 |
|
! empty($json_payload['dossier']['dossier'])) { |
808 |
|
$this->valF["dossier"] = $json_payload['dossier']['dossier']; |
809 |
|
} |
810 |
|
} |
811 |
|
|
812 |
|
// gestion d'une tache de type notification et de category mail |
813 |
|
if (isset($val['type']) |
814 |
|
&& (($val['type'] === 'notification_instruction' || $val['type'] === 'notification_decision') |
815 |
|
&& isset($val['category']) |
816 |
|
&& $val['category'] === 'mail') |
817 |
|
|| $val['type'] === 'notification_service_consulte' |
818 |
|
|| $val['type'] === 'notification_tiers_consulte' |
819 |
|
|| $val['type'] === 'notification_depot_demat' |
820 |
|
|| $val['type'] === 'notification_commune' |
821 |
|
|| $val['type'] === 'notification_signataire' |
822 |
|
) { |
823 |
|
// Récupère la payload de la tache |
824 |
|
$data = array(); |
825 |
|
$data['instruction_notification'] = $this->get_instruction_notification_data( |
826 |
|
$this->valF['category'], |
827 |
|
'with-id', |
828 |
|
array('with-id' => $this->valF['object_id']) |
829 |
|
); |
830 |
|
$data['dossier'] = $this->get_dossier_data($this->valF['dossier']); |
831 |
|
|
832 |
|
// Récupère l'instance de la notification |
833 |
|
$inst_notif = $this->f->get_inst__om_dbform(array( |
834 |
|
"obj" => "instruction_notification", |
835 |
|
"idx" => $val['object_id'], |
836 |
|
)); |
837 |
|
// Envoi le mail et met à jour le suivi |
838 |
|
$envoiMail = $inst_notif->send_mail_notification($data, $val['type']); |
839 |
|
// Passage de la tache à done si elle a réussi et à error |
840 |
|
// si l'envoi a échoué |
841 |
|
$this->valF['state'] = 'done'; |
842 |
|
if ($envoiMail === false) { |
843 |
|
$this->valF['state'] = 'error'; |
844 |
|
} |
845 |
|
} |
846 |
|
} |
847 |
|
|
848 |
|
/** |
849 |
|
* TRIGGER - triggermodifier. |
850 |
|
* |
851 |
|
* @param string $id |
852 |
|
* @param null &$dnu1 @deprecated Ne pas utiliser. |
853 |
|
* @param array $val Tableau des valeurs brutes. |
854 |
|
* @param null $dnu2 @deprecated Ne pas utiliser. |
855 |
|
* |
856 |
|
* @return boolean |
857 |
|
*/ |
858 |
|
function triggermodifier($id, &$dnu1 = null, $val = array(), $dnu2 = null) { |
859 |
|
parent::triggermodifier($id, $dnu1, $val, $dnu2); |
860 |
|
$this->addToLog(__METHOD__."(): start", EXTRA_VERBOSE_MODE); |
861 |
|
|
862 |
|
// Mise à jour des valeurs, notamment du timestamp_log en fonction de plusieurs critères |
863 |
|
$values = array( |
864 |
|
'state' => $this->valF['state'], |
865 |
|
'object_id' => $this->valF['object_id'], |
866 |
|
'comment' => $this->valF['comment'], |
867 |
|
); |
868 |
|
$new_values = $this->set_values_for_update($values); |
869 |
|
if ($new_values === false) { |
870 |
|
$this->addToLog(__METHOD__."(): erreur timestamp log", DEBUG_MODE); |
871 |
|
return false; |
872 |
|
} |
873 |
|
|
874 |
|
// Mise à jour des valeurs |
875 |
|
$this->valF['timestamp_log'] = $new_values['timestamp_log']; |
876 |
|
$this->valF['state'] = $new_values['state']; |
877 |
|
$this->valF['object_id'] = $new_values['object_id']; |
878 |
|
$this->valF['last_modification_date'] = date('Y-m-d'); |
879 |
|
$this->valF['last_modification_time'] = date('H:i:s'); |
880 |
|
if ($val['stream'] === 'output') { |
881 |
|
// Lorsque la task passe d'un état qui n'est pas "done" à l'état "done" |
882 |
|
if ($this->getVal("state") !== self::STATUS_DONE |
883 |
|
&& $this->valF['state'] === self::STATUS_DONE) { |
884 |
|
// |
885 |
|
$this->valF['json_payload'] = $this->view_form_json(true); |
886 |
|
} |
887 |
|
// Lorsque la task passe d'un état "done" à un état qui n'est pas "done" |
888 |
|
if ($this->getVal("state") === self::STATUS_DONE |
889 |
|
&& $this->valF['state'] !== self::STATUS_DONE) { |
890 |
|
// |
891 |
|
$this->valF['json_payload'] = "{}"; |
892 |
|
} |
893 |
|
} |
894 |
|
|
895 |
|
return true; |
896 |
|
} |
897 |
|
|
898 |
|
|
899 |
|
/** |
900 |
|
* Applique nouvelle valeur après traitement. |
901 |
|
* |
902 |
|
* @param array $params Tableau des valeurs en entrées |
903 |
|
* @return array Tableau des valeurs en sorties |
904 |
|
*/ |
905 |
|
public function set_values_for_update($params = array()) { |
906 |
|
|
907 |
|
// Récupération du timestamp_log existant |
908 |
|
$timestamp_log = $this->get_timestamp_log(); |
909 |
|
if ($timestamp_log === false) { |
910 |
|
return false; |
911 |
|
} |
912 |
|
|
913 |
|
// Vérification des object_id précédent en cas de tentative d'appliquer |
914 |
|
// l'état CANCELED sur la tâche |
915 |
|
if (isset($params['state']) === true |
916 |
|
&& $params['state'] === self::STATUS_CANCELED) { |
917 |
|
// Récupération du journal d'activité de la tâche sous forme de tableau |
918 |
|
// trié par ordre décroissant |
919 |
|
$log = $timestamp_log; |
920 |
|
krsort($log); |
921 |
|
// Pour chaque entrée dans le journal d'activité de la tâche : |
922 |
|
// - vérification de la présence de l'object_id précédent |
923 |
|
// - vérification que l'object_id précédent existe toujours dans la base de données |
924 |
|
// - l'object_id est mise à jour avec la valeur de l'object_id précédent |
925 |
|
// - le state n'est pas modifié |
926 |
|
// - sortie du traitement dès que le premier object_id précédent existant est trouvé |
927 |
|
// - si aucun object_id précédent existant n'est trouvé alors ni le state, ni l'object_id n'est modifiés |
928 |
|
foreach ($log as $key => $value) { |
929 |
|
// |
930 |
|
if (isset($value['prev_object_id']) === true |
931 |
|
&& $this->getVal('object_id') !== $value['prev_object_id']) { |
932 |
|
// Récupère la liste des tables potentielles pour un type de tâche |
933 |
|
$tables = $this->get_tables_by_task_type($this->getVal('type'), $this->getVal('stream')); |
934 |
|
foreach ($tables as $table) { |
935 |
|
// Vérifie s'il y a un ou aucun résultat |
936 |
|
$qres = $this->f->get_one_result_from_db_query( |
937 |
|
sprintf( |
938 |
|
'SELECT |
939 |
|
COUNT(%2$s) |
940 |
|
FROM |
941 |
|
%1$s%2$s |
942 |
|
WHERE |
943 |
|
%2$s::CHARACTER VARYING = \'%3$s\'', |
944 |
|
DB_PREFIXE, |
945 |
|
$table, |
946 |
|
$value['prev_object_id'] |
947 |
|
), |
948 |
|
array( |
949 |
|
"origin" => __METHOD__, |
950 |
|
"force_return" => true, |
951 |
|
) |
952 |
|
); |
953 |
|
if ($qres["code"] !== "OK") { |
954 |
|
return $this->end_treatment(__METHOD__, false); |
955 |
|
} |
956 |
|
// Affectation des valeurs et sortie de la boucle |
957 |
|
if ($qres["result"] == '1') { |
958 |
|
$params['object_id'] = $value['prev_object_id']; |
959 |
|
$params['state'] = $this->getVal('state'); |
960 |
|
break; |
961 |
|
} |
962 |
|
} |
963 |
|
// Sortie de la boucle si les valeurs sont affectées |
964 |
|
if ($params['object_id'] !== null |
965 |
|
&& $params['object_id'] === $value['prev_object_id']) { |
966 |
|
// |
967 |
|
break; |
968 |
|
} |
969 |
|
} |
970 |
|
} |
971 |
|
} |
972 |
|
|
973 |
|
// Mise à jour du journal d'activité de la tâche |
974 |
|
array_push($timestamp_log, array( |
975 |
|
'modification_date' => date('Y-m-d H:i:s'), |
976 |
|
'object_id' => $params['object_id'] !== null ? $params['object_id'] : $this->getVal('object_id'), |
977 |
|
'prev_object_id' => $this->getVal('object_id'), |
978 |
|
'state' => $params['state'], |
979 |
|
'prev_state' => $this->getVal('state'), |
980 |
|
'comment' => isset($params['comment']) ? $params['comment'] : $this->getVal('comment'), |
981 |
|
)); |
982 |
|
// |
983 |
|
$timestamp_log = json_encode($timestamp_log); |
984 |
|
|
985 |
|
|
986 |
|
// Les nouvelles valeurs après vérification des critères |
987 |
|
$result = array( |
988 |
|
'timestamp_log' => $timestamp_log, |
989 |
|
'object_id' => $params['object_id'], |
990 |
|
'state' => $params['state'], |
991 |
|
'comment' => $params['comment'], |
992 |
|
); |
993 |
|
return $result; |
994 |
|
} |
995 |
|
|
996 |
|
|
997 |
|
/** |
998 |
|
* TRIGGER - triggermodifierapres. |
999 |
|
* |
1000 |
|
* @param string $id |
1001 |
|
* @param null &$dnu1 @deprecated Ne pas utiliser. |
1002 |
|
* @param array $val Tableau des valeurs brutes. |
1003 |
|
* @param null $dnu2 @deprecated Ne pas utiliser. |
1004 |
|
* |
1005 |
|
* @return boolean |
1006 |
|
*/ |
1007 |
|
public function triggermodifierapres($id, &$dnu1 = null, $val = array(), $dnu2 = null) { |
1008 |
|
parent::triggermodifierapres($id, $dnu1, $val, $dnu2); |
1009 |
|
|
1010 |
|
// Suivi des notificiations |
1011 |
|
// En cas de changement de l'état de la tâche de notification, alors |
1012 |
|
// le suivi des dates de la notification et de l'instruction, est effectué |
1013 |
|
if (isset($val['category']) === true |
1014 |
|
&& $val['category'] === PORTAL |
1015 |
|
&& isset($val['type']) === true |
1016 |
|
&& ($val['type'] === 'notification_recepisse' |
1017 |
|
|| $val['type'] === 'notification_instruction' |
1018 |
|
|| $val['type'] === 'notification_decision' |
1019 |
|
|| $val['type'] === 'notification_service_consulte' |
1020 |
|
|| $val['type'] === 'notification_tiers_consulte')) { |
1021 |
|
// |
1022 |
|
if (isset($this->valF['state']) === true |
1023 |
|
&& $this->valF['state'] !== $this->getVal('state') |
1024 |
|
&& $this->valF['state'] !== self::STATUS_CANCELED) { |
1025 |
|
// |
1026 |
|
$inst_in = $this->f->get_inst__om_dbform(array( |
1027 |
|
"obj" => "instruction_notification", |
1028 |
|
"idx" => $val['object_id'], |
1029 |
|
)); |
1030 |
|
$valF_in = array(); |
1031 |
|
foreach ($inst_in->champs as $champ) { |
1032 |
|
$valF_in[$champ] = $inst_in->getVal($champ); |
1033 |
|
} |
1034 |
|
// Par défaut la date d'envoi et la date de premier accès sur |
1035 |
|
// la notification ne sont pas renseignées |
1036 |
|
$valF_in['date_envoi'] = null; |
1037 |
|
$valF_in['date_premier_acces'] = null; |
1038 |
|
// Lorsque la tâche est correctement traitée |
1039 |
|
if ($this->valF['state'] === self::STATUS_DONE) { |
1040 |
|
// |
1041 |
|
$valF_in['statut'] = __("envoyé"); |
1042 |
|
$valF_in['commentaire'] = __("Notification traitée"); |
1043 |
|
$valF_in['date_envoi'] = date('d/m/Y H:i:s'); |
1044 |
|
// Si l'instruction possède un document lié, alors ses dates |
1045 |
|
// de suivi sont mises à jour |
1046 |
|
$inst_instruction = $this->f->get_inst__om_dbform(array( |
1047 |
|
"obj" => "instruction", |
1048 |
|
"idx" => $inst_in->getVal('instruction'), |
1049 |
|
)); |
1050 |
|
if ($inst_instruction->has_an_edition() === true) { |
1051 |
|
$valF_instruction = array(); |
1052 |
|
foreach ($inst_instruction->champs as $champ) { |
1053 |
|
$valF_instruction[$champ] = $inst_instruction->getVal($champ); |
1054 |
|
} |
1055 |
|
$valF_instruction['date_envoi_rar'] = date('d/m/Y'); |
1056 |
|
$valF_instruction['date_retour_rar'] = date('d/m/Y', strtotime('now + 1 day')); |
1057 |
|
// Action spécifique pour identifier que la modification |
1058 |
|
// est une notification de demandeur |
1059 |
|
$inst_instruction->setParameter('maj', 175); |
1060 |
|
$update_instruction = $inst_instruction->modifier($valF_instruction); |
1061 |
|
if ($update_instruction === false) { |
1062 |
|
$this->addToLog(__METHOD__."(): ".$inst_instruction->msg, DEBUG_MODE); |
1063 |
|
return false; |
1064 |
|
} |
1065 |
|
} |
1066 |
|
} |
1067 |
|
// En cas d'erreur lors du traitement de la task |
1068 |
|
if ($this->valF['state'] === self::STATUS_ERROR) { |
1069 |
|
$valF_in['statut'] = __("échec"); |
1070 |
|
$valF_in['commentaire'] = __("Le traitement de la notification a échoué"); |
1071 |
|
} |
1072 |
|
// Met à jour la notification |
1073 |
|
$inst_in->setParameter('maj', 1); |
1074 |
|
$update_in = $inst_in->modifier($valF_in); |
1075 |
|
if ($update_in === false) { |
1076 |
|
$this->addToLog(__METHOD__."(): ".$inst_in->msg, DEBUG_MODE); |
1077 |
|
return false; |
1078 |
|
} |
1079 |
|
} |
1080 |
|
} |
1081 |
|
|
1082 |
|
// Envoi au contrôle de légalité |
1083 |
|
// En cas de changement de l'état de la tâche envoi_CL, alors le suivi |
1084 |
|
// des dates de l'instruction est effectué |
1085 |
|
if ($val['type'] === 'envoi_CL' |
1086 |
|
&& isset($this->valF['state']) === true |
1087 |
|
&& $this->valF['state'] === self::STATUS_DONE) { |
1088 |
|
// |
1089 |
|
$inst_instruction = $this->f->get_inst__om_dbform(array( |
1090 |
|
"obj" => "instruction", |
1091 |
|
"idx" => $this->getVal('object_id'), |
1092 |
|
)); |
1093 |
|
if ($inst_instruction->has_an_edition() === true) { |
1094 |
|
$valF_instruction = array(); |
1095 |
|
foreach ($inst_instruction->champs as $champ) { |
1096 |
|
$valF_instruction[$champ] = $inst_instruction->getVal($champ); |
1097 |
|
} |
1098 |
|
} |
1099 |
|
$valF_instruction['date_envoi_controle_legalite'] = date("Y-m-d"); |
1100 |
|
$inst_instruction->setParameter('maj', 1); |
1101 |
|
$update_instruction = $inst_instruction->modifier($valF_instruction); |
1102 |
|
if ($update_instruction === false) { |
1103 |
|
$this->addToLog(__METHOD__."(): ".$inst_instruction->msg, DEBUG_MODE); |
1104 |
|
return false; |
1105 |
|
} |
1106 |
|
} |
1107 |
|
|
1108 |
|
// |
1109 |
|
return true; |
1110 |
|
} |
1111 |
|
|
1112 |
|
/** |
1113 |
* TREATMENT - add_task |
* TREATMENT - add_task |
1114 |
* Ajoute un enregistrement. |
* Ajoute un enregistrement. |
1115 |
* |
* |
1118 |
*/ |
*/ |
1119 |
public function add_task($params = array()) { |
public function add_task($params = array()) { |
1120 |
$this->begin_treatment(__METHOD__); |
$this->begin_treatment(__METHOD__); |
1121 |
$timestamp_log = json_encode(array( |
|
1122 |
'creation_date' => date('Y-m-d H:i:s'), |
// Vérifie si la task doit être ajoutée en fonction du mode de l'application, |
1123 |
)); |
// seulement pour les tasks output |
1124 |
// Mise à jour du DI |
$task_types_si = self::TASK_TYPE_SI; |
1125 |
|
$task_types_sc = self::TASK_TYPE_SC; |
1126 |
|
$stream = isset($params['val']['stream']) === true ? $params['val']['stream'] : 'output'; |
1127 |
|
if ($stream === 'output' |
1128 |
|
&& isset($params['val']['type']) === true |
1129 |
|
&& $this->f->is_option_mode_service_consulte_enabled() === true |
1130 |
|
&& in_array($params['val']['type'], $task_types_sc) === false) { |
1131 |
|
// |
1132 |
|
return $this->end_treatment(__METHOD__, true); |
1133 |
|
} |
1134 |
|
if ($stream === 'output' |
1135 |
|
&& isset($params['val']['type']) === true |
1136 |
|
&& $this->f->is_option_mode_service_consulte_enabled() === false |
1137 |
|
&& in_array($params['val']['type'], $task_types_si) === false) { |
1138 |
|
// |
1139 |
|
return $this->end_treatment(__METHOD__, true); |
1140 |
|
} |
1141 |
|
|
1142 |
|
// |
1143 |
|
$timestamp_log = json_encode(array()); |
1144 |
|
|
1145 |
|
// |
1146 |
|
$category = isset($params['val']['category']) === true ? $params['val']['category'] : $this->category; |
1147 |
|
|
1148 |
|
// Si la tâche est de type ajout_piece et de stream input alors on ajoute le fichier |
1149 |
|
// et on ajoute l'uid dans le champ json_payload avant l'ajout de la tâche |
1150 |
|
if (isset($params['val']['type']) |
1151 |
|
&& in_array($params['val']['type'], self::TASK_WITH_DOCUMENT) |
1152 |
|
&& isset($params['val']['stream']) |
1153 |
|
&& $params['val']['stream'] == "input" ) { |
1154 |
|
// |
1155 |
|
$json_payload = json_decode($params['val']['json_payload'], true); |
1156 |
|
if (json_last_error() !== JSON_ERROR_NONE) { |
1157 |
|
$this->addToMessage(__("Le contenu JSON de la tâche n'est pas valide.")); |
1158 |
|
return $this->end_treatment(__METHOD__, false); |
1159 |
|
} |
1160 |
|
if (isset($json_payload['document_numerise']["file_content"]) === true |
1161 |
|
&& empty($json_payload['document_numerise']["file_content"]) === false) { |
1162 |
|
// |
1163 |
|
if (! $this->f->storage->is_service_available()) { |
1164 |
|
$err_msg = __("Service de stockage des documents indisponible"); |
1165 |
|
$this->addToLog(__METHOD__."(): $err_msg", DEBUG_MODE); |
1166 |
|
$this->addToMessage($err_msg); |
1167 |
|
return $this->end_treatment(__METHOD__, false); |
1168 |
|
} |
1169 |
|
// |
1170 |
|
$document_numerise = $json_payload['document_numerise']; |
1171 |
|
$file_content = base64_decode($document_numerise["file_content"]); |
1172 |
|
if ($file_content === false){ |
1173 |
|
$this->addToMessage(__("Le contenu du fichier lié à la tâche n'a pas pu etre recupere.")); |
1174 |
|
return $this->end_treatment(__METHOD__, false); |
1175 |
|
} |
1176 |
|
$metadata = array( |
1177 |
|
"filename" => $document_numerise['nom_fichier'], |
1178 |
|
"size" => strlen($file_content), |
1179 |
|
"mimetype" => $document_numerise['file_content_type'], |
1180 |
|
"date_creation" => isset($document_numerise['date_creation']) === true ? $document_numerise['date_creation'] : date("Y-m-d"), |
1181 |
|
); |
1182 |
|
$uid_fichier = $this->f->storage->create($file_content, $metadata, "from_content", "task.uid_fichier"); |
1183 |
|
if ($uid_fichier === OP_FAILURE) { |
1184 |
|
$this->addToMessage(__("Erreur lors de la creation du fichier lié à la tâche.")); |
1185 |
|
return $this->end_treatment(__METHOD__, false); |
1186 |
|
} |
1187 |
|
$json_payload["document_numerise"]["uid"] = $uid_fichier; |
1188 |
|
// Le fichier a été ajouté nous n'avons plus besoin du champ file_content dans la payload |
1189 |
|
unset($json_payload["document_numerise"]["file_content"]); |
1190 |
|
$params['val']['json_payload'] = json_encode($json_payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
1191 |
|
} |
1192 |
|
} |
1193 |
|
|
1194 |
|
// Valeurs de la tâche |
1195 |
$valF = array( |
$valF = array( |
1196 |
'task' => '', |
'task' => '', |
1197 |
'type' => $params['val']['type'], |
'type' => $params['val']['type'], |
1198 |
'timestamp_log' => $timestamp_log, |
'timestamp_log' => $timestamp_log, |
1199 |
'state' => isset($params['val']['state']) === true ? $params['val']['state'] : 'new', |
'state' => isset($params['val']['state']) === true ? $params['val']['state'] : self::STATUS_NEW, |
1200 |
'object_id' => $params['val']['object_id'], |
'object_id' => isset($params['val']['object_id']) ? $params['val']['object_id'] : '', |
1201 |
|
'dossier' => isset($params['val']['dossier']) ? $params['val']['dossier'] : '', |
1202 |
|
'stream' => $stream, |
1203 |
|
'json_payload' => isset($params['val']['json_payload']) === true ? $params['val']['json_payload'] : '{}', |
1204 |
|
'category' => $category, |
1205 |
|
'creation_date' => date('Y-m-d'), |
1206 |
|
'creation_time' => date('H:i:s'), |
1207 |
|
'last_modification_date' => null, |
1208 |
|
'last_modification_time' => null, |
1209 |
|
'comment' => null, |
1210 |
); |
); |
1211 |
$task_exists = $this->task_exists($valF['type'], $valF['object_id']); |
|
1212 |
if ($valF['type'] === 'modification_DI' && $task_exists === false) { |
// Gestion de la mise à jour des tâches sortantes |
1213 |
$task_exists = $this->task_exists('creation_DI', $valF['object_id']); |
$typeNonConcerne = array( |
1214 |
} |
'notification_recepisse', |
1215 |
if ($task_exists !== false) { |
'notification_instruction', |
1216 |
$inst_task = $this->f->get_inst__om_dbform(array( |
'notification_decision', |
1217 |
"obj" => "task", |
'notification_service_consulte', |
1218 |
"idx" => $task_exists, |
'notification_tiers_consulte', |
1219 |
)); |
'notification_signataire' |
1220 |
$update_state = $inst_task->getVal('state'); |
); |
1221 |
if (isset($params['update_val']['state']) === true) { |
if ($valF["stream"] == "output" |
1222 |
$update_state = $params['update_val']['state']; |
&& ! in_array($valF['type'], $typeNonConcerne)) { |
1223 |
} |
// Vérification de l'existance d'une tâche pour l'objet concerné |
1224 |
$update_params = array( |
// La vérification diffère en fonction de certains types de tâche |
1225 |
'val' => array( |
$search_values_common = array( |
1226 |
'state' => $update_state, |
sprintf('state != \'%s\'', self::STATUS_CANCELED), |
1227 |
), |
sprintf('state != \'%s\'', self::STATUS_DONE), |
1228 |
|
); |
1229 |
|
$search_values_others = array( |
1230 |
|
sprintf('type = \'%s\'', $valF['type']), |
1231 |
|
sprintf('(object_id = \'%s\' OR dossier = \'%s\')', $valF['object_id'], $valF['dossier']), |
1232 |
); |
); |
1233 |
return $inst_task->update_task($update_params); |
$search_values_specifics = array( |
1234 |
|
sprintf('object_id = \'%s\'', $valF['object_id']), |
1235 |
|
); |
1236 |
|
|
1237 |
|
// Recherche multi-critères sur les tâches |
1238 |
|
// Si l'object id/dossier à des tâches de type $valF['type'] qui lui est associé |
1239 |
|
// Et que ces tâches ont des statut différents de canceled et done |
1240 |
|
// Alors on récupère ces tâches |
1241 |
|
// Sinon return false |
1242 |
|
$task_exists = $this->task_exists_multi_search(array_merge($search_values_common, $search_values_others)); |
1243 |
|
|
1244 |
|
// S'il n'existe pas de tâche de type 'modification DI' pour l'object id/dossier |
1245 |
|
if ($valF['type'] === 'modification_DI' && $task_exists === false) { |
1246 |
|
// On se réfère à la tâche de type 'creation DI' de l'object id |
1247 |
|
$task_exists = $this->task_exists_multi_search(array_merge($search_values_common, $search_values_specifics, array("type = 'creation_DI'"))); |
1248 |
|
} |
1249 |
|
// S'il n'existe pas de tâche de type 'modification DA' pour l'object id/dossier |
1250 |
|
if ($valF['type'] === 'modification_DA' && $task_exists === false) { |
1251 |
|
// On se réfère à la tâche de type 'creation DA' de l'object id |
1252 |
|
$task_exists = $this->task_exists_multi_search(array_merge($search_values_common, $search_values_specifics, array("type = 'creation_DA'"))); |
1253 |
|
} |
1254 |
|
if ($valF['type'] === 'ajout_piece') { |
1255 |
|
// On se réfère à la tâche de type 'ajout piece' de l'object id |
1256 |
|
$task_exists = $this->task_exists_multi_search(array_merge($search_values_common, $search_values_specifics, array("type = 'ajout_piece'"))); |
1257 |
|
} |
1258 |
|
if ($valF['type'] === 'creation_consultation') { |
1259 |
|
// On se réfère à la tâche de type 'creation consultation' de l'object id |
1260 |
|
$task_exists = $this->task_exists_multi_search(array_merge($search_values_common, $search_values_specifics, array("type = 'creation_consultation'"))); |
1261 |
|
} |
1262 |
|
// S'il existe une tâche pour l'objet concerné, pas d'ajout de nouvelle |
1263 |
|
// tâche mais mise à jour de l'existante |
1264 |
|
if ($task_exists !== false) { |
1265 |
|
// Plusieurs tâches pourraient exister, elles sont contôler par ordre croissant |
1266 |
|
foreach ($task_exists as $task) { |
1267 |
|
$inst_task = $this->f->get_inst__om_dbform(array( |
1268 |
|
"obj" => "task", |
1269 |
|
"idx" => $task['task'], |
1270 |
|
)); |
1271 |
|
$update_state = $inst_task->getVal('state'); |
1272 |
|
if (isset($params['update_val']['state']) === true) { |
1273 |
|
$update_state = $params['update_val']['state']; |
1274 |
|
} |
1275 |
|
$object_id = $inst_task->getVal('object_id'); |
1276 |
|
if (!empty($valF['object_id'])) { |
1277 |
|
$object_id = $valF['object_id']; |
1278 |
|
} |
1279 |
|
// Pour être mise à jour, la tâche existante ne doit pas être en cours de traitement |
1280 |
|
$task_pending = $inst_task->getVal('state') === self::STATUS_PENDING |
1281 |
|
&& $update_state === self::STATUS_PENDING |
1282 |
|
&& $inst_task->getVal('object_id') !== $object_id; |
1283 |
|
if ($task_pending === false) { |
1284 |
|
$update_params = array( |
1285 |
|
'val' => array( |
1286 |
|
'state' => $update_state, |
1287 |
|
), |
1288 |
|
'object_id' => $object_id, |
1289 |
|
); |
1290 |
|
return $inst_task->update_task($update_params); |
1291 |
|
} |
1292 |
|
} |
1293 |
|
} |
1294 |
} |
} |
1295 |
$add = $this->ajouter($valF); |
$add = $this->ajouter($valF); |
1296 |
|
$this->addToLog(__METHOD__."(): retour de l'ajout de tâche: ".var_export($add, true), VERBOSE_MODE); |
1297 |
if ($add === false) { |
if ($add === false) { |
1298 |
$this->addToLog($this->msg, DEBUG_MODE); |
$this->addToLog(__METHOD__."(): ".$this->msg, DEBUG_MODE); |
1299 |
return $this->end_treatment(__METHOD__, false); |
return $this->end_treatment(__METHOD__, false); |
1300 |
} |
} |
1301 |
return $this->end_treatment(__METHOD__, true); |
return $this->end_treatment(__METHOD__, true); |
1310 |
*/ |
*/ |
1311 |
public function update_task($params = array()) { |
public function update_task($params = array()) { |
1312 |
$this->begin_treatment(__METHOD__); |
$this->begin_treatment(__METHOD__); |
1313 |
$timestamp_log = $this->get_timestamp_log(); |
|
1314 |
if ($timestamp_log === false) { |
// Mise à jour de la tâche |
|
$this->addToLog(__('XXX'), DEBUG_MODE); |
|
|
return $this->end_treatment(__METHOD__, false); |
|
|
} |
|
|
array_push($timestamp_log, array( |
|
|
'modification_date' => date('Y-m-d H:i:s'), |
|
|
'state' => $params['val']['state'], |
|
|
'prev_state' => $this->getVal('state'), |
|
|
)); |
|
|
$timestamp_log = json_encode($timestamp_log); |
|
1315 |
$valF = array( |
$valF = array( |
1316 |
'task' => $this->getVal($this->clePrimaire), |
'task' => $this->getVal($this->clePrimaire), |
1317 |
'type' => $this->getVal('type'), |
'type' => $this->getVal('type'), |
1318 |
'timestamp_log' => $timestamp_log, |
'timestamp_log' => '[]', |
1319 |
'state' => $params['val']['state'], |
'state' => $params['val']['state'], |
1320 |
'object_id' => $this->getVal('object_id'), |
'object_id' => isset($params['object_id']) == true ? $params['object_id'] : $this->getVal('object_id'), |
1321 |
|
'stream' => $this->getVal('stream'), |
1322 |
|
'dossier' => $this->getVal('dossier'), |
1323 |
|
'json_payload' => $this->getVal('json_payload'), |
1324 |
|
'category' => $this->getVal('category'), |
1325 |
|
'creation_date' => $this->getVal('creation_date'), |
1326 |
|
'creation_time' => $this->getVal('creation_time'), |
1327 |
|
'last_modification_date' => date('Y-m-d'), |
1328 |
|
'last_modification_time' => date('H:i:s'), |
1329 |
|
'comment' => isset($params['comment']) == true ? $params['comment'] : $this->getVal('comment'), |
1330 |
); |
); |
1331 |
$update = $this->modifier($valF); |
$update = $this->modifier($valF); |
1332 |
if ($update === false) { |
if ($update === false) { |
1339 |
/** |
/** |
1340 |
* 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 |
1341 |
* l'enregistrement instancié. |
* l'enregistrement instancié. |
1342 |
* |
* |
1343 |
* @param array $params Tableau des paramètres |
* @param array $params Tableau des paramètres |
1344 |
* @return array sinon false en cas d'erreur |
* @return array sinon false en cas d'erreur |
1345 |
*/ |
*/ |
1375 |
|
|
1376 |
protected function view_tab_json() { |
protected function view_tab_json() { |
1377 |
$where = ''; |
$where = ''; |
1378 |
if ($this->f->get_submitted_get_value('state') !== null |
$category = null; |
1379 |
&& $this->f->get_submitted_get_value('state') !== '') { |
// Liste des paramètres possibles pour la recherche des tâches |
1380 |
|
$params = array( |
1381 |
|
'task', |
1382 |
|
'type', |
1383 |
|
'state', |
1384 |
|
'object_id', |
1385 |
|
'dossier', |
1386 |
|
'stream', |
1387 |
|
'category', |
1388 |
|
'lien_id_interne_uid_externe', |
1389 |
|
'object', |
1390 |
|
'external_uid', |
1391 |
|
); |
1392 |
|
// Pour chaque paramètre possible, vérification de son existance et de sa |
1393 |
|
// valeur pour compléter la requête de recherche |
1394 |
|
foreach ($params as $param) { |
1395 |
// |
// |
1396 |
$where = sprintf(' WHERE state = \'%s\' ', $this->f->get_submitted_get_value('state')); |
if ($this->f->get_submitted_get_value($param) !== null |
1397 |
|
&& $this->f->get_submitted_get_value($param) !== '') { |
1398 |
|
// Condition spécifique au champ 'category' |
1399 |
|
if ($param === 'category') { |
1400 |
|
$category = $this->f->get_submitted_get_value('category'); |
1401 |
|
} |
1402 |
|
// |
1403 |
|
$where_or_and = 'WHERE'; |
1404 |
|
if ($where !== '') { |
1405 |
|
$where_or_and = 'AND'; |
1406 |
|
} |
1407 |
|
$table = 'task'; |
1408 |
|
if ($param === 'lien_id_interne_uid_externe' |
1409 |
|
|| $param === 'object' |
1410 |
|
|| $param === 'external_uid') { |
1411 |
|
// |
1412 |
|
$table = 'lien_id_interne_uid_externe'; |
1413 |
|
} |
1414 |
|
$where .= sprintf(' %s %s.%s = \'%s\' ', $where_or_and, $table, $param, $this->f->get_submitted_get_value($param)); |
1415 |
|
} |
1416 |
} |
} |
1417 |
|
// |
1418 |
$query = sprintf(' |
$query = sprintf(' |
1419 |
SELECT |
SELECT |
1420 |
* |
task.* |
1421 |
FROM %1$stask |
FROM %1$stask |
1422 |
|
LEFT JOIN %1$slien_id_interne_uid_externe |
1423 |
|
ON task.object_id = lien_id_interne_uid_externe.object_id |
1424 |
|
AND task.category = lien_id_interne_uid_externe.category |
1425 |
%2$s |
%2$s |
1426 |
|
ORDER BY task ASC |
1427 |
', |
', |
1428 |
DB_PREFIXE, |
DB_PREFIXE, |
1429 |
$where |
$where |
1430 |
); |
); |
1431 |
$res = $this->f->get_all_results_from_db_query($query, true); |
$res = $this->f->get_all_results_from_db_query( |
1432 |
|
$query, |
1433 |
|
array( |
1434 |
|
"origin" => __METHOD__, |
1435 |
|
"force_return" => true, |
1436 |
|
) |
1437 |
|
); |
1438 |
if ($res['code'] === 'KO') { |
if ($res['code'] === 'KO') { |
1439 |
return false; |
return false; |
1440 |
} |
} |
1441 |
$list_tasks = array(); |
$list_tasks = array(); |
1442 |
foreach ($res['result'] as $task) { |
foreach ($res['result'] as $task) { |
1443 |
$task['timestamp_log'] = json_decode($task['timestamp_log'], true); |
unset($task['timestamp_log']); |
1444 |
|
unset($task['json_payload']); |
1445 |
|
if ($task['type'] === 'ajout_piece') { |
1446 |
|
$val_dn = $this->get_document_numerise_data($task['object_id']); |
1447 |
|
} |
1448 |
|
if ($task['stream'] === 'output') { |
1449 |
|
$task['external_uids'] = array_merge( |
1450 |
|
$this->get_all_external_uids($task['dossier'], array(), $category !== null ? $category : $task['category']), |
1451 |
|
$this->get_all_external_uids($task['object_id'], array(), $category !== null ? $category : $task['category']) |
1452 |
|
); |
1453 |
|
} |
1454 |
$list_tasks[$task['task']] = $task; |
$list_tasks[$task['task']] = $task; |
1455 |
} |
} |
1456 |
printf(json_encode($list_tasks)); |
echo(json_encode($list_tasks)); |
1457 |
} |
} |
1458 |
|
|
1459 |
protected function get_dossier_data(string $dossier) { |
protected function get_dossier_data(string $dossier) { |
1462 |
"obj" => "dossier", |
"obj" => "dossier", |
1463 |
"idx" => $dossier, |
"idx" => $dossier, |
1464 |
)); |
)); |
1465 |
|
if (empty($inst_di->val) === true) { |
1466 |
|
return $val_di; |
1467 |
|
} |
1468 |
$val_di = $inst_di->get_json_data(); |
$val_di = $inst_di->get_json_data(); |
1469 |
if ($val_di['dossier_instruction_type_code'] === 'T') { |
if ($val_di['dossier_instruction_type_code'] === 'T') { |
1470 |
$val_di['date_decision_transfert'] = $val_di['date_decision']; |
$val_di['date_decision_transfert'] = $val_di['date_decision']; |
1555 |
if (isset($val_dt['tax_ext_pret']) === true |
if (isset($val_dt['tax_ext_pret']) === true |
1556 |
&& $val_dt['tax_ext_pret'] === 'f') { |
&& $val_dt['tax_ext_pret'] === 'f') { |
1557 |
// |
// |
1558 |
$val_dt['tax_su_princ_surf1'] = $val_dt['tax_surf_tot_cstr']; |
$val_dt['tax_su_princ_surf1'] = isset($val_dt['tax_surf_tot_cstr']) === true ? $val_dt['tax_surf_tot_cstr'] : ''; |
1559 |
$val_dt['tax_su_princ_surf_stat1'] = $val_dt['tax_surf_loc_stat']; |
$val_dt['tax_su_princ_surf_stat1'] = isset($val_dt['tax_surf_loc_stat']) === true ? $val_dt['tax_surf_loc_stat'] : ''; |
1560 |
} |
} |
1561 |
if (isset($val_dt['tax_ext_pret']) === true |
if (isset($val_dt['tax_ext_pret']) === true |
1562 |
&& $val_dt['tax_ext_pret'] === 't') { |
&& $val_dt['tax_ext_pret'] === 't') { |
1565 |
if (preg_match('/[pP].*[lL].*[aA].*[iI]/', $val_dt['tax_ext_desc']) === 1 |
if (preg_match('/[pP].*[lL].*[aA].*[iI]/', $val_dt['tax_ext_desc']) === 1 |
1566 |
|| preg_match('/[lL].*[lL].*[tT].*[sS]/', $val_dt['tax_ext_desc']) === 1) { |
|| preg_match('/[lL].*[lL].*[tT].*[sS]/', $val_dt['tax_ext_desc']) === 1) { |
1567 |
// |
// |
1568 |
$val_dt['tax_su_princ_surf2'] = $val_dt['tax_surf_tot_cstr']; |
$val_dt['tax_su_princ_surf2'] = isset($val_dt['tax_surf_tot_cstr']) === true ? $val_dt['tax_surf_tot_cstr'] : ''; |
1569 |
$val_dt['tax_su_princ_surf_stat2'] = $val_dt['tax_surf_loc_stat']; |
$val_dt['tax_su_princ_surf_stat2'] = isset($val_dt['tax_surf_loc_stat']) === true ? $val_dt['tax_surf_loc_stat'] : ''; |
1570 |
} |
} |
1571 |
// if (preg_match('/[pP].*[tT].*[zZ]/', $val_dt['tax_ext_desc']) === 1) { |
// if (preg_match('/[pP].*[tT].*[zZ]/', $val_dt['tax_ext_desc']) === 1) { |
1572 |
// $val_dt['tax_su_princ_surf4'] = $val_dt['tax_surf_tot_cstr']; |
// $val_dt['tax_su_princ_surf4'] = $val_dt['tax_surf_tot_cstr']; |
1595 |
return $val_dt; |
return $val_dt; |
1596 |
} |
} |
1597 |
|
|
1598 |
protected function get_external_uid($fk_idx, string $fk_idx_2) { |
/** |
1599 |
|
* Récupère la liste des objets distincts existants dans la table des liens |
1600 |
|
* entre identifiants internes et identifiants externes. |
1601 |
|
* |
1602 |
|
* @return array |
1603 |
|
*/ |
1604 |
|
protected function get_list_distinct_objects_external_link() { |
1605 |
|
$query = sprintf(' |
1606 |
|
SELECT |
1607 |
|
DISTINCT(object) |
1608 |
|
FROM %1$slien_id_interne_uid_externe |
1609 |
|
ORDER BY object ASC |
1610 |
|
', |
1611 |
|
DB_PREFIXE |
1612 |
|
); |
1613 |
|
$res = $this->f->get_all_results_from_db_query( |
1614 |
|
$query, |
1615 |
|
array( |
1616 |
|
"origin" => __METHOD__, |
1617 |
|
"force_return" => true, |
1618 |
|
) |
1619 |
|
); |
1620 |
|
if ($res['code'] === 'KO') { |
1621 |
|
return array(); |
1622 |
|
} |
1623 |
|
$result = array(); |
1624 |
|
foreach ($res['result'] as $object) { |
1625 |
|
$result[] = $object['object']; |
1626 |
|
} |
1627 |
|
return $result; |
1628 |
|
} |
1629 |
|
|
1630 |
|
protected function get_external_uid($fk_idx, string $fk_idx_2, $fk_idx_3 = PLATAU, $order_asc_desc = 'DESC') { |
1631 |
$inst_external_uid = $this->f->get_inst__by_other_idx(array( |
$inst_external_uid = $this->f->get_inst__by_other_idx(array( |
1632 |
"obj" => "lien_id_interne_uid_externe", |
"obj" => "lien_id_interne_uid_externe", |
1633 |
"fk_field" => 'object_id', |
"fk_field" => 'object_id', |
1634 |
"fk_idx" => $fk_idx, |
"fk_idx" => $fk_idx, |
1635 |
"fk_field_2" => 'object', |
"fk_field_2" => 'object', |
1636 |
"fk_idx_2" => $fk_idx_2, |
"fk_idx_2" => $fk_idx_2, |
1637 |
|
"fk_field_3" => 'category', |
1638 |
|
"fk_idx_3" => $fk_idx_3, |
1639 |
|
"order_field" => 'lien_id_interne_uid_externe', |
1640 |
|
"order_asc_desc" => $order_asc_desc, |
1641 |
)); |
)); |
1642 |
return $inst_external_uid->getVal('external_uid'); |
return $inst_external_uid->getVal('external_uid'); |
1643 |
} |
} |
1644 |
|
|
1645 |
protected function get_demandeurs_data(string $dossier) { |
protected function get_all_external_uids($fk_idx, $link_objects = array(), $category=PLATAU) { |
1646 |
|
if (count($link_objects) == 0) { |
1647 |
|
$link_objects = $this->get_list_distinct_objects_external_link(); |
1648 |
|
} |
1649 |
|
$val_external_uid = array(); |
1650 |
|
foreach ($link_objects as $link_object) { |
1651 |
|
$external_uid = $this->get_external_uid($fk_idx, $link_object, $category); |
1652 |
|
if ($external_uid !== '' && $external_uid !== null) { |
1653 |
|
$val_external_uid[$link_object] = $external_uid; |
1654 |
|
} |
1655 |
|
} |
1656 |
|
return $val_external_uid; |
1657 |
|
} |
1658 |
|
|
1659 |
|
protected function get_demandeurs_data($dossier) { |
1660 |
$val_demandeur = array(); |
$val_demandeur = array(); |
1661 |
|
if ($dossier === null) { |
1662 |
|
return $val_demandeur; |
1663 |
|
} |
1664 |
$inst_di = $this->f->get_inst__om_dbform(array( |
$inst_di = $this->f->get_inst__om_dbform(array( |
1665 |
"obj" => "dossier", |
"obj" => "dossier", |
1666 |
"idx" => $dossier, |
"idx" => $dossier, |
1691 |
return $val_architecte; |
return $val_architecte; |
1692 |
} |
} |
1693 |
|
|
1694 |
protected function get_instruction_data(string $dossier, $type = 'decision') { |
protected function get_instruction_data($dossier, $type = 'decision', $extra_params = array()) { |
1695 |
$val_instruction = null; |
$val_instruction = null; |
1696 |
|
if ($dossier === null) { |
1697 |
|
return $val_instruction; |
1698 |
|
} |
1699 |
$instruction_with_doc = null; |
$instruction_with_doc = null; |
1700 |
$inst_di = $this->f->get_inst__om_dbform(array( |
$inst_di = $this->f->get_inst__om_dbform(array( |
1701 |
"obj" => "dossier", |
"obj" => "dossier", |
1708 |
if ($type === 'incompletude') { |
if ($type === 'incompletude') { |
1709 |
$idx = $inst_di->get_last_instruction_incompletude(); |
$idx = $inst_di->get_last_instruction_incompletude(); |
1710 |
} |
} |
1711 |
|
// XXX Permet de récupérer l'instruction par son identifiant |
1712 |
|
if ($type === 'with-id') { |
1713 |
|
$idx = $extra_params['with-id']; |
1714 |
|
} |
1715 |
$inst_instruction = $this->f->get_inst__om_dbform(array( |
$inst_instruction = $this->f->get_inst__om_dbform(array( |
1716 |
"obj" => "instruction", |
"obj" => "instruction", |
1717 |
"idx" => $idx, |
"idx" => $idx, |
1749 |
} |
} |
1750 |
if ($instruction_with_doc !== null) { |
if ($instruction_with_doc !== null) { |
1751 |
// |
// |
1752 |
$val_instruction['path'] = sprintf('%s&snippet=%s&obj=%s&champ=%s&id=%s', 'openads/app/index.php?module=form', 'file', 'instruction', 'om_fichier_instruction', $instruction_with_doc); |
$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); |
1753 |
} |
} |
1754 |
} |
} |
1755 |
return $val_instruction; |
return $val_instruction; |
1756 |
} |
} |
1757 |
|
|
1758 |
|
|
1759 |
|
/** |
1760 |
|
* Récupère les informations pour les notifications ayant plusieurs annexe |
1761 |
|
*/ |
1762 |
|
protected function get_instruction_notification_data($category, $type = '', $extra_params = array()) { |
1763 |
|
$val_in = null; |
1764 |
|
|
1765 |
|
$idx = null; |
1766 |
|
if ($type === 'with-id') { |
1767 |
|
$idx = $extra_params['with-id']; |
1768 |
|
} |
1769 |
|
|
1770 |
|
// Récupération du type de notification. Le type est nécessaire pour récupérer |
1771 |
|
// le message et le titre de notification. |
1772 |
|
$typeNotification = $this->getVal('type'); |
1773 |
|
if (isset($this->valF['type'])) { |
1774 |
|
$typeNotification = $this->valF['type']; |
1775 |
|
} |
1776 |
|
|
1777 |
|
// récupére les données à intégrer à la payload |
1778 |
|
$inst_in = $this->f->get_inst__om_dbform(array( |
1779 |
|
"obj" => "instruction_notification", |
1780 |
|
"idx" => $idx, |
1781 |
|
)); |
1782 |
|
if (count($inst_in->val) > 0) { |
1783 |
|
$val_in = $inst_in->get_json_data(); |
1784 |
|
|
1785 |
|
$val_in['parametre_courriel_type_titre'] = ''; |
1786 |
|
$val_in['parametre_courriel_type_message'] = ''; |
1787 |
|
// Récupération du message et du titre |
1788 |
|
if ($category === 'mail') { |
1789 |
|
$inst_instruction = $this->f->get_inst__om_dbform(array( |
1790 |
|
"obj" => "instruction", |
1791 |
|
"idx" => $inst_in->getVal('instruction'), |
1792 |
|
)); |
1793 |
|
$collectivite_id = $inst_instruction->get_dossier_instruction_om_collectivite($inst_instruction->getVal('dossier')); |
1794 |
|
$phrase_type_notification = $this->f->get_notification_parametre_courriel_type($collectivite_id, $typeNotification); |
1795 |
|
$val_in['parametre_courriel_type_titre'] = $phrase_type_notification['parametre_courriel_type_titre']; |
1796 |
|
$val_in['parametre_courriel_type_message'] = $phrase_type_notification['parametre_courriel_type_message']; |
1797 |
|
} |
1798 |
|
|
1799 |
|
if ($typeNotification == 'notification_signataire') { |
1800 |
|
$val_in['lien_page_signature'] = $inst_in->getLienPageSignature($inst_instruction); |
1801 |
|
} |
1802 |
|
else { |
1803 |
|
// Récupération des liens vers les documents et des id et type des annexes |
1804 |
|
$infoDocNotif = $inst_in->getInfosDocumentsNotif($inst_in->getVal($inst_in->clePrimaire), $category); |
1805 |
|
$cle = $category == PORTAL ? 'path' : 'lien_telechargement_document'; |
1806 |
|
$val_in[$cle] = $infoDocNotif['document']['path']; |
1807 |
|
$val_in['annexes'] = $infoDocNotif['annexes']; |
1808 |
|
} |
1809 |
|
} |
1810 |
|
return $val_in; |
1811 |
|
} |
1812 |
|
|
1813 |
|
/** |
1814 |
|
* Récupère les informations concernant la lettre au pétitionnaire. |
1815 |
|
* |
1816 |
|
* @param string identifiant du dossier |
1817 |
|
* @param string type de tâche |
1818 |
|
* @param array paramètre supplémentaire permettant de récupérer les informations |
1819 |
|
* |
1820 |
|
* @return array information concernant la lettre au pétitionnaire |
1821 |
|
*/ |
1822 |
|
protected function get_lettre_petitionnaire_data($dossier, $type, $extra_params = array()) { |
1823 |
|
// Si la date limite de notification n'a pas été dépassé le type de lettre est 1 |
1824 |
|
// Si la date a été dépassé et qu'il s'agit d'une demande de pièce le type est 3 |
1825 |
|
// Si la date a été dépassé et qu'il s'agit d'une prolongation le type est 4 |
1826 |
|
// Le type de document dépend du type de pièce |
1827 |
|
$nomTypeLettre = ''; |
1828 |
|
$nomTypeDocument = ''; |
1829 |
|
if ($type === 'lettre_incompletude') { |
1830 |
|
$nomTypeLettre = '3'; |
1831 |
|
$nomTypeDocument = '4'; |
1832 |
|
} elseif ($type === 'lettre_majoration') { |
1833 |
|
$nomTypeLettre = '4'; |
1834 |
|
$nomTypeDocument = '6'; |
1835 |
|
} |
1836 |
|
|
1837 |
|
$inst_di = $this->f->get_inst__om_dbform(array( |
1838 |
|
"obj" => "dossier", |
1839 |
|
"idx" => $dossier, |
1840 |
|
)); |
1841 |
|
$date_limite_notification = DateTime::createFromFormat('Y-m-d', $inst_di->getVal('date_notification_delai')); |
1842 |
|
$aujourdhui = new DateTime(); |
1843 |
|
if (! $date_limite_notification instanceof DateTime) { |
1844 |
|
$nomTypeLettre = ''; |
1845 |
|
$nomTypeDocument = ''; |
1846 |
|
} elseif ($aujourdhui < $date_limite_notification) { |
1847 |
|
$nomTypeLettre = '1'; |
1848 |
|
$nomTypeDocument = '3'; |
1849 |
|
} |
1850 |
|
|
1851 |
|
return array( |
1852 |
|
'nomEtatLettre' => '3', |
1853 |
|
'nomModaliteNotifMetier' => '4', |
1854 |
|
'nomTypeLettre' => $nomTypeLettre, |
1855 |
|
'nomTypeDocument' => $nomTypeDocument |
1856 |
|
); |
1857 |
|
} |
1858 |
|
|
1859 |
protected function sort_instruction_data(array $values, array $res) { |
protected function sort_instruction_data(array $values, array $res) { |
1860 |
$fields = array( |
$fields = array( |
1861 |
|
"date_evenement", |
1862 |
"date_envoi_signature", |
"date_envoi_signature", |
1863 |
"date_retour_signature", |
"date_retour_signature", |
1864 |
"date_envoi_rar", |
"date_envoi_rar", |
1868 |
"signataire_arrete", |
"signataire_arrete", |
1869 |
"om_fichier_instruction", |
"om_fichier_instruction", |
1870 |
"tacite", |
"tacite", |
1871 |
|
"lettretype", |
1872 |
|
"commentaire", |
1873 |
|
"complement_om_html", |
1874 |
); |
); |
1875 |
foreach ($values as $key => $value) { |
foreach ($values as $key => $value) { |
1876 |
if (in_array($key, $fields) === true) { |
if (in_array($key, $fields) === true) { |
1889 |
return $res; |
return $res; |
1890 |
} |
} |
1891 |
|
|
1892 |
|
/** |
1893 |
|
* Permet de définir si l'instruction passée en paramètre est une instruction |
1894 |
|
* récépissé d'une demande et si la demande en question a générée un dossier d'instruction. |
1895 |
|
* |
1896 |
|
* @param integer $instruction Identifiant de l'instruction |
1897 |
|
* @return boolean |
1898 |
|
*/ |
1899 |
|
protected function is_demande_instruction_recepisse_without_dossier($instruction) { |
1900 |
|
if ($instruction === null) { |
1901 |
|
return false; |
1902 |
|
} |
1903 |
|
$qres = $this->f->get_one_result_from_db_query( |
1904 |
|
sprintf( |
1905 |
|
'SELECT |
1906 |
|
demande_type.dossier_instruction_type |
1907 |
|
FROM |
1908 |
|
%1$sdemande |
1909 |
|
INNER JOIN %1$sdemande_type |
1910 |
|
ON demande.demande_type = demande_type.demande_type |
1911 |
|
WHERE |
1912 |
|
demande.instruction_recepisse = %2$s', |
1913 |
|
DB_PREFIXE, |
1914 |
|
intval($instruction) |
1915 |
|
), |
1916 |
|
array( |
1917 |
|
"origin" => __METHOD__, |
1918 |
|
"force_return" => true, |
1919 |
|
) |
1920 |
|
); |
1921 |
|
if ($qres["code"] !== "OK") { |
1922 |
|
return null; |
1923 |
|
} |
1924 |
|
if ($qres["result"] === "") { |
1925 |
|
return true; |
1926 |
|
} |
1927 |
|
return false; |
1928 |
|
} |
1929 |
|
|
1930 |
protected function get_document_numerise_data(string $dn) { |
protected function get_document_numerise_data(string $dn) { |
1931 |
$val_dn = array(); |
$val_dn = array(); |
1932 |
$inst_dn = $this->f->get_inst__om_dbform(array( |
$inst_dn = $this->f->get_inst__om_dbform(array( |
1934 |
"idx" => $dn, |
"idx" => $dn, |
1935 |
)); |
)); |
1936 |
$val_dn = $inst_dn->get_json_data(); |
$val_dn = $inst_dn->get_json_data(); |
1937 |
$val_dn['path'] = sprintf('%s&snippet=%s&obj=%s&champ=%s&id=%s', 'openads/app/index.php?module=form', 'file', 'document_numerise', 'uid', $this->getVal('object_id')); |
$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')); |
1938 |
// Correspond à la nomenclature Plat'AU NATURE_PIECE |
// Correspond à la nomenclature Plat'AU NATURE_PIECE |
1939 |
$val_dn['nature'] = $val_dn['document_numerise_nature_libelle']; |
$val_dn['nature'] = $val_dn['document_numerise_nature_libelle']; |
1940 |
return $val_dn; |
return $val_dn; |
1959 |
return $val_dp; |
return $val_dp; |
1960 |
} |
} |
1961 |
|
|
1962 |
protected function view_form_json() { |
protected function get_avis_decision_data(string $dossier) { |
1963 |
// Mise à jour des valeurs |
$inst_di = $this->f->get_inst__om_dbform(array( |
1964 |
if ($this->f->get_submitted_post_value('valid') === 'true' |
"obj" => "dossier", |
1965 |
&& $this->f->get_submitted_post_value('state') !== null) { |
"idx" => $dossier, |
1966 |
|
)); |
1967 |
|
$ad = $inst_di->getVal('avis_decision'); |
1968 |
|
$val_ad = array(); |
1969 |
|
if ($ad !== null && trim($ad) !== '') { |
1970 |
|
$inst_ad = $this->f->get_inst__om_dbform(array( |
1971 |
|
"obj" => "avis_decision", |
1972 |
|
"idx" => $ad, |
1973 |
|
)); |
1974 |
|
$val_ad = $inst_ad->get_json_data(); |
1975 |
|
$val_ad['txAvis'] = "Voir document joint"; |
1976 |
|
if (isset($val_ad['tacite']) === true |
1977 |
|
&& $val_ad['tacite'] === 't') { |
1978 |
|
// |
1979 |
|
$val_ad['txAvis'] = "Sans objet"; |
1980 |
|
} |
1981 |
|
} |
1982 |
|
return $val_ad; |
1983 |
|
} |
1984 |
|
|
1985 |
|
protected function get_signataire_arrete_data(string $sa) { |
1986 |
|
$inst_sa = $this->f->get_inst__om_dbform(array( |
1987 |
|
"obj" => "signataire_arrete", |
1988 |
|
"idx" => $sa, |
1989 |
|
)); |
1990 |
|
$val_sa = array_combine($inst_sa->champs, $inst_sa->val); |
1991 |
|
foreach ($val_sa as $key => $value) { |
1992 |
|
$val_sa[$key] = strip_tags($value); |
1993 |
|
} |
1994 |
|
return $val_sa; |
1995 |
|
} |
1996 |
|
|
1997 |
|
// XXX WIP |
1998 |
|
protected function get_consultation_data(string $consultation) { |
1999 |
|
$val_consultation = array(); |
2000 |
|
$inst_consultation = $this->f->get_inst__om_dbform(array( |
2001 |
|
"obj" => "consultation", |
2002 |
|
"idx" => $consultation, |
2003 |
|
)); |
2004 |
|
$val_consultation = $inst_consultation->get_json_data(); |
2005 |
|
if (isset($val_consultation['fichier']) === true |
2006 |
|
&& $val_consultation['fichier'] !== '') { |
2007 |
// |
// |
2008 |
|
$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')); |
2009 |
|
} |
2010 |
|
if (isset($val_consultation['om_fichier_consultation']) === true |
2011 |
|
&& $val_consultation['om_fichier_consultation'] !== '') { |
2012 |
|
// |
2013 |
|
$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')); |
2014 |
|
} |
2015 |
|
return $val_consultation; |
2016 |
|
} |
2017 |
|
|
2018 |
|
// XXX WIP |
2019 |
|
protected function get_service_data(string $service) { |
2020 |
|
$val_service = array(); |
2021 |
|
$inst_service = $this->f->get_inst__om_dbform(array( |
2022 |
|
"obj" => "service", |
2023 |
|
"idx" => $service, |
2024 |
|
)); |
2025 |
|
$val_service = $inst_service->get_json_data(); |
2026 |
|
return $val_service; |
2027 |
|
} |
2028 |
|
|
2029 |
|
protected function view_form_json($in_field = false) { |
2030 |
|
// |
2031 |
|
$check_state = isset($this->valF['state']) === true ? $this->valF['state'] : $this->getVal('state'); |
2032 |
|
if ($check_state !== self::STATUS_CANCELED) { |
2033 |
|
// Liste des valeurs à afficher |
2034 |
|
$val = array(); |
2035 |
|
// |
2036 |
|
$val_task = array_combine($this->champs, $this->val); |
2037 |
|
foreach ($val_task as $key => $value) { |
2038 |
|
$val_task[$key] = strip_tags($value); |
2039 |
|
} |
2040 |
|
|
2041 |
|
// Vérifie pour les tâches dont l'affichage de la payload est calculée si l'objet |
2042 |
|
// de référence de la tâche existe. |
2043 |
|
$objectRefExist = true; |
2044 |
|
if ($val_task['stream'] === 'output' |
2045 |
|
&& (empty($val_task['json_payload']) || $val_task['json_payload'] === '{}')) { |
2046 |
|
$objectRefExist = $this->does_referenced_object_exist( |
2047 |
|
$val_task['object_id'], |
2048 |
|
$val_task['type'] |
2049 |
|
); |
2050 |
|
} |
2051 |
|
|
2052 |
|
// Si l'objet de référence n'existe pas log le numéro de la tâche concerné et |
2053 |
|
// renvoie une payload contenant le message d'erreur. |
2054 |
|
// Sinon constitue la payload du json. |
2055 |
|
if (! $objectRefExist) { |
2056 |
|
$this->f->addToLog( |
2057 |
|
sprintf( |
2058 |
|
__('Impossible de récupérer la payload car l\'objet de réference n\'existe pas pour la tâche : %s'), |
2059 |
|
$val_task['task'] |
2060 |
|
), |
2061 |
|
DEBUG_MODE |
2062 |
|
); |
2063 |
|
$val = __('Impossible de recuperer la payload car l\'objet de reference n\'existe pas.'); |
2064 |
|
} else { |
2065 |
|
|
2066 |
|
$val_task['timestamp_log'] = json_decode($val_task['timestamp_log'], true); |
2067 |
|
unset($val_task['timestamp_log_hidden']); |
2068 |
|
$val['task'] = $val_task; |
2069 |
|
// |
2070 |
|
if ($this->getVal('type') === 'creation_DA' |
2071 |
|
|| $this->getVal('type') === 'modification_DA') { |
2072 |
|
// |
2073 |
|
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id')); |
2074 |
|
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation'); |
2075 |
|
$val['dossier_autorisation_parcelle'] = $this->get_parcelles_data('dossier_autorisation', $val['dossier_autorisation']['dossier_autorisation']); |
2076 |
|
$val_external_uid = array(); |
2077 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier_autorisation']['dossier_autorisation'], 'dossier_autorisation'); |
2078 |
|
$val['external_uids'] = $val_external_uid; |
2079 |
|
} |
2080 |
|
// |
2081 |
|
if ($this->getVal('type') === 'creation_DI' |
2082 |
|
|| $this->getVal('type') === 'modification_DI' |
2083 |
|
|| $this->getVal('type') === 'depot_DI') { |
2084 |
|
// |
2085 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
2086 |
|
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_instruction'); |
2087 |
|
$val['demandeur'] = $this->get_demandeurs_data($val['dossier']['dossier']); |
2088 |
|
$architecte = isset($val['donnees_techniques']['architecte']) === true ? $val['donnees_techniques']['architecte'] : null; |
2089 |
|
$val['architecte'] = $this->get_architecte_data($architecte); |
2090 |
|
$val['dossier_parcelle'] = $this->get_parcelles_data('dossier', $val['dossier']['dossier']); |
2091 |
|
$val_external_uid = array(); |
2092 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2093 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2094 |
|
$val['external_uids'] = $val_external_uid; |
2095 |
|
} |
2096 |
|
// |
2097 |
|
if ($this->getVal('type') === 'qualification_DI') { |
2098 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2099 |
|
$val_external_uid = array(); |
2100 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2101 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2102 |
|
$val['external_uids'] = $val_external_uid; |
2103 |
|
} |
2104 |
|
// |
2105 |
|
if ($this->getVal('type') === 'ajout_piece') { |
2106 |
|
$val['document_numerise'] = $this->get_document_numerise_data($this->getVal('object_id')); |
2107 |
|
$val['dossier'] = $this->get_dossier_data($val['document_numerise']['dossier']); |
2108 |
|
$val_external_uid = array(); |
2109 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2110 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2111 |
|
$val_external_uid['piece'] = $this->get_external_uid($val['document_numerise']['document_numerise'], 'piece'); |
2112 |
|
$val['external_uids'] = $val_external_uid; |
2113 |
|
} |
2114 |
|
// |
2115 |
|
if ($this->getVal('type') === 'decision_DI') { |
2116 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2117 |
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
2118 |
|
$val['instruction']['final'] = 't'; |
2119 |
|
if (isset($val['instruction']['signataire_arrete']) === true) { |
2120 |
|
$val['signataire_arrete'] = $this->get_signataire_arrete_data($val['instruction']['signataire_arrete']); |
2121 |
|
} |
2122 |
|
$val_external_uid = array(); |
2123 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2124 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2125 |
|
$val['external_uids'] = $val_external_uid; |
2126 |
|
} |
2127 |
|
// |
2128 |
|
if ($this->getVal('type') === 'incompletude_DI') { |
2129 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2130 |
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
2131 |
|
$val_external_uid = array(); |
2132 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2133 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2134 |
|
$val['external_uids'] = $val_external_uid; |
2135 |
|
} |
2136 |
|
// |
2137 |
|
if ($this->getVal('type') === 'completude_DI') { |
2138 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2139 |
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
2140 |
|
$val_external_uid = array(); |
2141 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2142 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2143 |
|
$val['external_uids'] = $val_external_uid; |
2144 |
|
} |
2145 |
|
// |
2146 |
|
if ($this->getVal('type') === 'lettre_incompletude' |
2147 |
|
|| $this->getVal('type') === 'lettre_majoration') { |
2148 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2149 |
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
2150 |
|
$val['lettre_petitionnaire'] = $this->get_lettre_petitionnaire_data($val['dossier']['dossier'], $this->getVal('type')); |
2151 |
|
$val_external_uid = array(); |
2152 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2153 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2154 |
|
$val['external_uids'] = $val_external_uid; |
2155 |
|
} |
2156 |
|
// |
2157 |
|
if ($this->getVal('type') === 'pec_metier_consultation') { |
2158 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2159 |
|
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
2160 |
|
$val_external_uid = array(); |
2161 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2162 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2163 |
|
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
2164 |
|
$val['external_uids'] = $val_external_uid; |
2165 |
|
} |
2166 |
|
// |
2167 |
|
if ($this->getVal('type') === 'avis_consultation') { |
2168 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2169 |
|
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
2170 |
|
$val['avis_decision'] = $this->get_avis_decision_data($this->getVal('dossier')); |
2171 |
|
if (isset($val['instruction']['signataire_arrete']) === true) { |
2172 |
|
$val['signataire_arrete'] = $this->get_signataire_arrete_data($val['instruction']['signataire_arrete']); |
2173 |
|
} |
2174 |
|
$val_external_uid = array(); |
2175 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2176 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2177 |
|
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
2178 |
|
$val_external_uid['avis_dossier_consultation'] = $this->get_external_uid($this->getVal('object_id'), 'avis_dossier_consultation'); |
2179 |
|
$val['external_uids'] = $val_external_uid; |
2180 |
|
} |
2181 |
|
// XXX WIP |
2182 |
|
if ($this->getVal('type') === 'creation_consultation') { |
2183 |
|
// |
2184 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2185 |
|
$val['consultation'] = $this->get_consultation_data($this->getVal('object_id')); |
2186 |
|
$val['service'] = $this->get_service_data($val['consultation']['service']); |
2187 |
|
$val_external_uid = array(); |
2188 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2189 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2190 |
|
$val['external_uids'] = $val_external_uid; |
2191 |
|
} |
2192 |
|
// |
2193 |
|
if ($this->getVal('type') === 'envoi_CL') { |
2194 |
|
// |
2195 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2196 |
|
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
2197 |
|
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($val['dossier']['dossier_autorisation']); |
2198 |
|
$val_external_uid = array(); |
2199 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2200 |
|
$val_external_uid['dossier'] = $this->get_external_uid($this->getVal('dossier'), 'dossier'); |
2201 |
|
$val_external_uid['decision'] = $this->get_external_uid($this->getVal('object_id'), 'instruction'); |
2202 |
|
if ($val_external_uid['decision'] === '') { |
2203 |
|
$inst_instruction = $this->f->get_inst__om_dbform(array( |
2204 |
|
"obj" => "instruction", |
2205 |
|
"idx" => $this->getVal('object_id'), |
2206 |
|
)); |
2207 |
|
$val_external_uid['decision'] = $this->get_external_uid($inst_instruction->get_related_instructions_next('retour_signature'), 'instruction'); |
2208 |
|
} |
2209 |
|
$val['external_uids'] = $val_external_uid; |
2210 |
|
} |
2211 |
|
if ($this->getVal('type') === 'notification_instruction' |
2212 |
|
|| $this->getVal('type') === 'notification_recepisse' |
2213 |
|
|| $this->getVal('type') === 'notification_decision' |
2214 |
|
|| $this->getVal('type') === 'notification_service_consulte' |
2215 |
|
|| $this->getVal('type') === 'notification_tiers_consulte' |
2216 |
|
|| $this->getVal('type') === 'notification_signataire') { |
2217 |
|
// |
2218 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2219 |
|
$dossier_id = isset($val['dossier']['dossier']) === true ? $val['dossier']['dossier'] : null; |
2220 |
|
$val['demandeur'] = $this->get_demandeurs_data($dossier_id); |
2221 |
|
$val['instruction_notification'] = $this->get_instruction_notification_data($this->getVal('category'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
2222 |
|
$instruction_id = isset($val['instruction_notification']['instruction']) === true ? $val['instruction_notification']['instruction'] : null; |
2223 |
|
$instruction_annexes = isset($val['instruction_notification']['annexes']) === true ? $val['instruction_notification']['annexes'] : null; |
2224 |
|
$val['instruction'] = $this->get_instruction_data($dossier_id, 'with-id', array('with-id' => $instruction_id)); |
2225 |
|
// Précise qu'il s'agit d'une instruction final si l'instruction est liée à une |
2226 |
|
// demande dont le type ne génère pas de dossier |
2227 |
|
if ($this->is_demande_instruction_recepisse_without_dossier($instruction_id) === true) { |
2228 |
|
$val['instruction']['final'] = 't'; |
2229 |
|
} |
2230 |
|
$val_external_uid = array(); |
2231 |
|
// Affiche l'identifiant externe lié à l'instruction si cette combinaison existe, sinon celui lié au dossier |
2232 |
|
$val_external_uid['demande'] = $this->get_external_uid($instruction_id, 'demande') !== '' ? $this->get_external_uid($instruction_id, 'demande') : $this->get_external_uid($dossier_id, 'demande'); |
2233 |
|
$val_external_uid['demande (instruction)'] = $this->get_external_uid($instruction_id, 'demande', PORTAL, 'ASC'); |
2234 |
|
$val_external_uid['instruction_notification'] = $this->get_external_uid($this->getVal('object_id'), 'instruction_notification', PORTAL); |
2235 |
|
$val['external_uids'] = $val_external_uid; |
2236 |
|
} |
2237 |
|
// |
2238 |
|
if ($this->getVal('type') === 'prescription') { |
2239 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2240 |
|
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
2241 |
|
$val['avis_decision'] = $this->get_avis_decision_data($this->getVal('dossier')); |
2242 |
|
if (isset($val['instruction']['signataire_arrete']) === true) { |
2243 |
|
$val['signataire_arrete'] = $this->get_signataire_arrete_data($val['instruction']['signataire_arrete']); |
2244 |
|
} |
2245 |
|
$val_external_uid = array(); |
2246 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2247 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2248 |
|
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
2249 |
|
$val_external_uid['prescription'] = $this->get_external_uid($this->getVal('object_id'), 'prescription'); |
2250 |
|
$val['external_uids'] = $val_external_uid; |
2251 |
|
} |
2252 |
|
} |
2253 |
|
|
2254 |
|
if ($in_field === true) { |
2255 |
|
return json_encode($val, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
2256 |
|
} else { |
2257 |
|
// Liste des valeurs affichée en JSON |
2258 |
|
echo(json_encode($val, JSON_UNESCAPED_SLASHES)); |
2259 |
|
} |
2260 |
|
} |
2261 |
|
} |
2262 |
|
|
2263 |
|
function post_update_task() { |
2264 |
|
// Mise à jour des valeurs |
2265 |
|
|
2266 |
|
// Modification de l'état de la tâche |
2267 |
|
if ($this->f->get_submitted_post_value('state') !== null) { |
2268 |
$params = array( |
$params = array( |
2269 |
'val' => array( |
'val' => array( |
2270 |
'state' => $this->f->get_submitted_post_value('state') |
'state' => $this->f->get_submitted_post_value('state') |
2271 |
), |
), |
2272 |
); |
); |
2273 |
|
if ($this->f->get_submitted_post_value('comment') !== null) { |
2274 |
|
$params['comment'] = $this->f->get_submitted_post_value('comment'); |
2275 |
|
} |
2276 |
$update = $this->update_task($params); |
$update = $this->update_task($params); |
2277 |
$message_class = "valid"; |
$message_class = "valid"; |
2278 |
$message = $this->msg; |
$message = $this->msg; |
2287 |
} |
} |
2288 |
$this->f->displayMessage($message_class, $message); |
$this->f->displayMessage($message_class, $message); |
2289 |
} |
} |
2290 |
// |
|
2291 |
if ($this->f->get_submitted_post_value('valid') === 'true' |
// Sauvegarde de l'uid externe retourné |
2292 |
&& $this->f->get_submitted_post_value('external_uid') !== null) { |
if ($this->f->get_submitted_post_value('external_uid') !== null) { |
2293 |
// |
// |
2294 |
$inst_lien = $this->f->get_inst__om_dbform(array( |
$objects = $this->get_objects_by_task_type($this->getVal('type'), $this->getVal('stream')); |
2295 |
"obj" => "lien_id_interne_uid_externe", |
// Si l'identifiant externe contient le préfixe pour identifier les codes de suivi, |
2296 |
"idx" => ']', |
// le seul objet concerné sera celui du code de suivi |
2297 |
)); |
if (strpos($this->f->get_submitted_post_value('external_uid'), self::CS_PREFIX) !== false) { |
2298 |
$valF = array( |
$objects = array('code-suivi', ); |
2299 |
'lien_id_interne_uid_externe' => '', |
} |
2300 |
'object' => $this->get_lien_objet_by_type($this->getVal('type')), |
foreach ($objects as $object) { |
2301 |
'object_id' => $this->getVal('object_id'), |
$inst_lien = $this->f->get_inst__om_dbform(array( |
2302 |
'external_uid' => $this->f->get_submitted_post_value('external_uid'), |
"obj" => "lien_id_interne_uid_externe", |
2303 |
); |
"idx" => ']', |
2304 |
$add = $inst_lien->ajouter($valF); |
)); |
2305 |
$message_class = "valid"; |
$object_id = $this->getVal('object_id'); |
2306 |
$message = $inst_lien->msg; |
$is_exists = $inst_lien->is_exists($object, $object_id, $this->f->get_submitted_post_value('external_uid'), $this->getVal('dossier')); |
2307 |
if ($add === false) { |
// Dans le cas spécifique de la mise à jour d'une notification |
2308 |
$this->addToLog($inst_lien->msg, DEBUG_MODE); |
// et de la création d'une liaison d'identifiant pour l'objet demande, |
2309 |
$message_class = "error"; |
// l'identifiant de l'objet n'est plus celui de la notification |
2310 |
$message = sprintf( |
// d'instruction mais celui du dossier d'instruction |
2311 |
'%s %s', |
if ($object === 'demande' |
2312 |
__("Impossible de mettre à jour le lien entre l'identifiant interne et l'identifiant de l'application externe."), |
&& ($this->getVal('type') === 'notification_recepisse' |
2313 |
__('Veuillez contacter votre administrateur.') |
|| $this->getVal('type') === 'notification_instruction' |
2314 |
); |
|| $this->getVal('type') === 'notification_decision' |
2315 |
|
|| $this->getVal('type') === 'notification_service_consulte' |
2316 |
|
|| $this->getVal('type') === 'notification_tiers_consulte' |
2317 |
|
|| $this->getVal('type') === 'notification_signataire')) { |
2318 |
|
// |
2319 |
|
$object_id = $this->getVal('dossier'); |
2320 |
|
// Il ne doit y avoir qu'une liaison entre le numéro du dossier interne et un uid externe de "demande" |
2321 |
|
$is_exists = $inst_lien->is_exists($object, $object_id, null, $this->getVal('dossier')); |
2322 |
|
} |
2323 |
|
if ($is_exists === false) { |
2324 |
|
$valF = array( |
2325 |
|
'lien_id_interne_uid_externe' => '', |
2326 |
|
'object' => $object, |
2327 |
|
'object_id' => $object_id, |
2328 |
|
'external_uid' => $this->f->get_submitted_post_value('external_uid'), |
2329 |
|
'dossier' => $this->getVal('dossier'), |
2330 |
|
'category' => $this->getVal('category'), |
2331 |
|
); |
2332 |
|
$add = $inst_lien->ajouter($valF); |
2333 |
|
$message_class = "valid"; |
2334 |
|
$message = $inst_lien->msg; |
2335 |
|
if ($add === false) { |
2336 |
|
$this->addToLog($inst_lien->msg, DEBUG_MODE); |
2337 |
|
$message_class = "error"; |
2338 |
|
$message = sprintf( |
2339 |
|
'%s %s', |
2340 |
|
__("Impossible de mettre à jour le lien entre l'identifiant interne et l'identifiant de l'application externe."), |
2341 |
|
__('Veuillez contacter votre administrateur.') |
2342 |
|
); |
2343 |
|
} |
2344 |
|
$this->f->displayMessage($message_class, $message); |
2345 |
|
} |
2346 |
} |
} |
|
$this->f->displayMessage($message_class, $message); |
|
2347 |
} |
} |
2348 |
|
} |
2349 |
|
|
2350 |
|
function post_add_task() { |
2351 |
|
// TODO Tester de remplacer la ligne de json_payload par un $_POST |
2352 |
|
$result = $this->add_task(array( |
2353 |
|
'val' => array( |
2354 |
|
'stream' => 'input', |
2355 |
|
'json_payload' => html_entity_decode($this->f->get_submitted_post_value('json_payload'), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401), |
2356 |
|
'type' => $this->f->get_submitted_post_value('type'), |
2357 |
|
'category' => $this->f->get_submitted_post_value('category'), |
2358 |
|
) |
2359 |
|
)); |
2360 |
|
$message = sprintf( |
2361 |
|
__("Tâche %s ajoutée avec succès"), |
2362 |
|
$this->getVal($this->clePrimaire)). |
2363 |
|
'<br/><br/>'. |
2364 |
|
$this->msg; |
2365 |
|
$message_class = "valid"; |
2366 |
|
if ($result === false){ |
2367 |
|
$this->addToLog($this->msg, DEBUG_MODE); |
2368 |
|
$message_class = "error"; |
2369 |
|
$message = sprintf( |
2370 |
|
'%s %s', |
2371 |
|
__('Impossible d\'ajouter la tâche.'), |
2372 |
|
__('Veuillez contacter votre administrateur.') |
2373 |
|
); |
2374 |
|
} |
2375 |
|
$this->f->displayMessage($message_class, $message); |
2376 |
|
} |
2377 |
|
|
2378 |
|
function setLayout(&$form, $maj) { |
2379 |
// |
// |
2380 |
if ($this->f->get_submitted_post_value('valid') === null) { |
$form->setBloc('json_payload', 'D', '', 'col_6'); |
2381 |
// Liste des valeurs à afficher |
$fieldset_title_payload = __("json_payload (calculée)"); |
2382 |
$val = array(); |
if ($this->getVal('json_payload') !== "{}") { |
2383 |
// |
$fieldset_title_payload = __("json_payload"); |
2384 |
$val_task = array_combine($this->champs, $this->val); |
} |
2385 |
foreach ($val_task as $key => $value) { |
$form->setFieldset('json_payload', 'DF', $fieldset_title_payload, "collapsible, startClosed"); |
2386 |
$val_task[$key] = strip_tags($value); |
$form->setBloc('json_payload', 'F'); |
2387 |
} |
$form->setBloc('timestamp_log', 'DF', __("historique"), 'col_9 timestamp_log_jsontotab'); |
2388 |
$val_task['timestamp_log'] = json_decode($val_task['timestamp_log'], true); |
} |
|
$val['task'] = $val_task; |
|
|
// |
|
|
if ($this->getVal('type') === 'creation_DA') { |
|
|
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id')); |
|
|
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation'); |
|
|
$val['dossier_autorisation_parcelle'] = $this->get_parcelles_data('dossier_autorisation', $val['dossier_autorisation']['dossier_autorisation']); |
|
|
$val_external_uid = array(); |
|
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier_autorisation']['dossier_autorisation'], 'dossier_autorisation'); |
|
|
$val['external_uid'] = $val_external_uid; |
|
|
} |
|
|
// |
|
|
if ($this->getVal('type') === 'creation_DI' |
|
|
|| $this->getVal('type') === 'modification_DI' |
|
|
|| $this->getVal('type') === 'depot_DI') { |
|
|
// |
|
|
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
|
|
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_instruction'); |
|
|
$val['demandeur'] = $this->get_demandeurs_data($val['dossier']['dossier']); |
|
|
$architecte = isset($val['donnees_techniques']['architecte']) === true ? $val['donnees_techniques']['architecte'] : null; |
|
|
$val['architecte'] = $this->get_architecte_data($architecte); |
|
|
$val['dossier_parcelle'] = $this->get_parcelles_data('dossier', $val['dossier']['dossier']); |
|
|
$val_external_uid = array(); |
|
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
|
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
|
|
$val['external_uid'] = $val_external_uid; |
|
|
} |
|
|
// |
|
|
if ($this->getVal('type') === 'qualification_DI') { |
|
|
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
|
|
$val_external_uid = array(); |
|
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
|
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
|
|
$val['external_uid'] = $val_external_uid; |
|
|
} |
|
|
// |
|
|
if ($this->getVal('type') === 'ajout_piece') { |
|
|
$val['document_numerise'] = $this->get_document_numerise_data($this->getVal('object_id')); |
|
|
$val['dossier'] = $this->get_dossier_data($val['document_numerise']['dossier']); |
|
|
$val_external_uid = array(); |
|
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
|
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
|
|
$val_external_uid['document_numerise'] = $this->get_external_uid($val['document_numerise']['document_numerise'], 'document_numerise'); |
|
|
$val['external_uid'] = $val_external_uid; |
|
|
} |
|
|
// |
|
|
if ($this->getVal('type') === 'decision_DI') { |
|
|
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
|
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier']); |
|
|
$val_external_uid = array(); |
|
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
|
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
|
|
$val['external_uid'] = $val_external_uid; |
|
|
} |
|
|
// |
|
|
if ($this->getVal('type') === 'incompletude_DI') { |
|
|
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
|
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'incompletude'); |
|
|
$val_external_uid = array(); |
|
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
|
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
|
|
$val['external_uid'] = $val_external_uid; |
|
|
} |
|
|
// |
|
|
if ($this->getVal('type') === 'completude_DI') { |
|
|
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
|
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'completude'); |
|
|
$val_external_uid = array(); |
|
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
|
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
|
|
$val['external_uid'] = $val_external_uid; |
|
|
} |
|
2389 |
|
|
2390 |
// Liste des valeurs affichée en JSON |
/** |
2391 |
printf(json_encode($val, JSON_UNESCAPED_SLASHES)); |
* Récupère le nom de l'objet à mentionner dans la table lien_id_interne_uid_externe |
2392 |
|
* en fonction du type et du stream de la tâche. |
2393 |
|
* |
2394 |
|
* @param string $type Type de la tâche |
2395 |
|
* @param string $stream Stream de la tâche |
2396 |
|
* |
2397 |
|
* @return array |
2398 |
|
*/ |
2399 |
|
function get_objects_by_task_type($type, $stream = 'all') { |
2400 |
|
$objects = array(); |
2401 |
|
if (in_array($type, array('creation_DA', 'modification_DA', )) === true) { |
2402 |
|
$objects = array('dossier_autorisation', ); |
2403 |
|
} |
2404 |
|
if (in_array($type, array('creation_DI', 'depot_DI', 'notification_DI', 'qualification_DI', )) === true) { |
2405 |
|
$objects = array('dossier', ); |
2406 |
|
} |
2407 |
|
if (in_array($type, array('create_DI_for_consultation', )) === true) { |
2408 |
|
$objects = array('dossier', 'dossier_consultation', ); |
2409 |
|
} |
2410 |
|
if (in_array($type, array('create_DI', )) === true |
2411 |
|
&& $stream === 'input') { |
2412 |
|
$objects = array('dossier', 'dossier_autorisation', 'demande', ); |
2413 |
|
} |
2414 |
|
if (in_array($type, array( |
2415 |
|
'decision_DI', |
2416 |
|
'incompletude_DI', |
2417 |
|
'completude_DI', |
2418 |
|
'lettre_incompletude', |
2419 |
|
'lettre_majoration' |
2420 |
|
)) === true) { |
2421 |
|
$objects = array('instruction', ); |
2422 |
|
} |
2423 |
|
if (in_array($type, array('envoi_CL', )) === true) { |
2424 |
|
$objects = array('instruction_action_cl', ); |
2425 |
|
} |
2426 |
|
if (in_array($type, array('pec_metier_consultation', )) === true |
2427 |
|
&& $stream === 'output') { |
2428 |
|
$objects = array('pec_dossier_consultation', ); |
2429 |
|
} |
2430 |
|
if (in_array($type, array('avis_consultation', )) === true |
2431 |
|
&& $stream === 'output') { |
2432 |
|
$objects = array('avis_dossier_consultation', ); |
2433 |
|
} |
2434 |
|
if (in_array($type, array('prescription', )) === true |
2435 |
|
&& $stream === 'output') { |
2436 |
|
$objects = array('prescription', ); |
2437 |
|
} |
2438 |
|
if (in_array($type, array('ajout_piece', 'add_piece', )) === true) { |
2439 |
|
$objects = array('piece', ); |
2440 |
|
} |
2441 |
|
if (in_array($type, array('creation_consultation', )) === true) { |
2442 |
|
$objects = array('consultation', ); |
2443 |
|
} |
2444 |
|
if (in_array($type, array('pec_metier_consultation', )) === true |
2445 |
|
&& $stream === 'input') { |
2446 |
|
$objects = array('pec_metier_consultation', ); |
2447 |
|
} |
2448 |
|
if (in_array($type, array('avis_consultation', )) === true |
2449 |
|
&& $stream === 'input') { |
2450 |
|
$objects = array('avis_consultation', ); |
2451 |
|
} |
2452 |
|
if (in_array($type, array('create_message', )) === true |
2453 |
|
&& $stream === 'input') { |
2454 |
|
$objects = array('dossier_message', ); |
2455 |
} |
} |
2456 |
|
if (in_array( |
2457 |
|
$type, |
2458 |
|
array( |
2459 |
|
'notification_recepisse', |
2460 |
|
'notification_instruction', |
2461 |
|
'notification_decision', |
2462 |
|
'notification_service_consulte', |
2463 |
|
'notification_tiers_consulte', |
2464 |
|
'notification_signataire', |
2465 |
|
) |
2466 |
|
) === true) { |
2467 |
|
$objects = array('instruction_notification', 'demande', ); |
2468 |
|
} |
2469 |
|
return $objects; |
2470 |
} |
} |
2471 |
|
|
2472 |
protected function get_lien_objet_by_type($type) { |
/** |
2473 |
// |
* Récupère les tables auxquelles pourrait être rattaché l'objet lié à la tâche, |
2474 |
$objet = ''; |
* par rapport à son type. |
2475 |
if ($type === 'creation_DA') { |
* |
2476 |
$objet = 'dossier_autorisation'; |
* @param string $type Type de la tâche |
2477 |
} |
* @param string $stream input ou output |
2478 |
if ($type === 'creation_DI' |
* @return array |
2479 |
|| $type === 'depot_DI' |
*/ |
2480 |
|| $type === 'modification_DI' |
function get_tables_by_task_type($type, $stream = 'all') { |
2481 |
|| $type === 'qualification_DI' |
$tables = array(); |
2482 |
|| $type === 'decision_DI' |
if (in_array($type, array('creation_DA', 'modification_DA', )) === true) { |
2483 |
|| $type === 'incompletude_DI' |
$tables = array('dossier_autorisation', ); |
2484 |
|| $type === 'completude_DI') { |
} |
2485 |
// |
if (in_array($type, array('creation_DI', 'depot_DI', )) === true) { |
2486 |
$objet = 'dossier'; |
$tables = array('dossier', ); |
2487 |
|
} |
2488 |
|
if (in_array($type, array('qualification_DI', )) === true) { |
2489 |
|
$tables = array('instruction', 'dossier', ); |
2490 |
|
} |
2491 |
|
if (in_array($type, array('create_DI_for_consultation', )) === true) { |
2492 |
|
$tables = array('dossier', ); |
2493 |
|
} |
2494 |
|
if (in_array($type, array('create_DI', )) === true |
2495 |
|
&& $stream === 'input') { |
2496 |
|
$tables = array('dossier', 'dossier_autorisation', 'demande', ); |
2497 |
|
} |
2498 |
|
if (in_array($type, array( |
2499 |
|
'decision_DI', |
2500 |
|
'incompletude_DI', |
2501 |
|
'completude_DI', |
2502 |
|
'lettre_incompletude', |
2503 |
|
'lettre_majoration' |
2504 |
|
)) === true) { |
2505 |
|
$tables = array('instruction', ); |
2506 |
|
} |
2507 |
|
if (in_array($type, array('envoi_CL', )) === true) { |
2508 |
|
$objects = array('instruction', ); |
2509 |
|
} |
2510 |
|
if (in_array($type, array('pec_metier_consultation', )) === true |
2511 |
|
&& $stream === 'output') { |
2512 |
|
$tables = array('instruction', ); |
2513 |
|
} |
2514 |
|
if (in_array($type, array('avis_consultation', )) === true |
2515 |
|
&& $stream === 'output') { |
2516 |
|
$tables = array('instruction', ); |
2517 |
|
} |
2518 |
|
if (in_array($type, array('prescription', )) === true |
2519 |
|
&& $stream === 'output') { |
2520 |
|
$tables = array('instruction', ); |
2521 |
|
} |
2522 |
|
if (in_array($type, array('ajout_piece', 'add_piece', )) === true) { |
2523 |
|
$tables = array('document_numerise', ); |
2524 |
|
} |
2525 |
|
if (in_array($type, array('creation_consultation', )) === true) { |
2526 |
|
$tables = array('consultation', ); |
2527 |
|
} |
2528 |
|
if (in_array($type, array('pec_metier_consultation', )) === true |
2529 |
|
&& $stream === 'input') { |
2530 |
|
$tables = array('consultation', ); |
2531 |
|
} |
2532 |
|
if (in_array($type, array('avis_consultation', )) === true |
2533 |
|
&& $stream === 'input') { |
2534 |
|
$tables = array('consultation', ); |
2535 |
|
} |
2536 |
|
if (in_array($type, array('create_message', )) === true |
2537 |
|
&& $stream === 'input') { |
2538 |
|
$tables = array('dossier_message', ); |
2539 |
|
} |
2540 |
|
if (in_array( |
2541 |
|
$type, |
2542 |
|
array( |
2543 |
|
'notification_recepisse', |
2544 |
|
'notification_instruction', |
2545 |
|
'notification_decision', |
2546 |
|
'notification_service_consulte', |
2547 |
|
'notification_tiers_consulte', |
2548 |
|
'notification_signataire' |
2549 |
|
) |
2550 |
|
) === true) { |
2551 |
|
$tables = array('instruction_notification', ); |
2552 |
} |
} |
2553 |
if ($type === 'ajout_piece') { |
return $tables; |
2554 |
$objet = 'document_numerise'; |
} |
2555 |
|
|
2556 |
|
/** |
2557 |
|
* Vérifie si l'objet référencé par la tâche existe en base de données. |
2558 |
|
* |
2559 |
|
* Récupère la liste des tables de référence associé à la tâche à partir |
2560 |
|
* du type de tâche et de son flux (input ou output). |
2561 |
|
* Pour chaque table potentiellement référencé par la tâche on essaye d'instancier |
2562 |
|
* l'objet correspondant à partir de l'identifiant de l'objet de référence de la tâche. |
2563 |
|
* Si l'élément instancié existe renvoie true sinon renvoie false. |
2564 |
|
* |
2565 |
|
* @param string|integer $taskObjectId : identifiant de l'objet de référence de la tâche |
2566 |
|
* @param string $taskType : type de la tâche |
2567 |
|
* @param string $taskStream : flux entrant (output - valeur par défaut) ou sortant (input) |
2568 |
|
* @return boolean |
2569 |
|
*/ |
2570 |
|
protected function does_referenced_object_exist($taskObjectId, string $taskType, string $taskStream = 'output') { |
2571 |
|
$refTables = $this->get_tables_by_task_type($taskType, $taskStream); |
2572 |
|
if (empty($refTables) === true) { |
2573 |
|
$this->f->addToLog( |
2574 |
|
sprintf( |
2575 |
|
__("Impossible de vérifier si l'objet de référence existe, car le type de task '%s' n'a pas de correspondance avec une table dans la méthode %s."), |
2576 |
|
$taskType, |
2577 |
|
"get_tables_by_task_type()" |
2578 |
|
), |
2579 |
|
DEBUG_MODE |
2580 |
|
); |
2581 |
|
return true; |
2582 |
} |
} |
2583 |
return $objet; |
foreach ($refTables as $table) { |
2584 |
|
$inst = $this->f->get_inst__om_dbform(array( |
2585 |
|
'obj' => $table, |
2586 |
|
'idx' => $taskObjectId |
2587 |
|
)); |
2588 |
|
if ($inst->exists() === true) { |
2589 |
|
return true; |
2590 |
|
} |
2591 |
|
} |
2592 |
|
return false; |
2593 |
} |
} |
2594 |
|
|
2595 |
} |
} |