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 |
|
|
17 |
/** |
/** |
18 |
* Définition des actions disponibles sur la classe. |
* Définition des actions disponibles sur la classe. |
19 |
* |
* |
40 |
} |
} |
41 |
|
|
42 |
public function setvalF($val = array()) { |
public function setvalF($val = array()) { |
43 |
|
|
44 |
|
// // les guillets doubles sont remplacés automatiquement par des simples |
45 |
|
// // dans core/om_formulaire.clasS.php::recupererPostvar() |
46 |
|
// // voir le ticket https://dev.atreal.fr/projets/openmairie/tracker/209 |
47 |
|
// // ceci est un hack sale temporaire en attendant résolution du ticket |
48 |
|
// foreach(array('json_payload', 'timestamp_log') as $key) { |
49 |
|
// if (isset($val[$key]) && ! empty($val[$key]) && |
50 |
|
// isset($_POST[$key]) && ! empty($_POST[$key])) { |
51 |
|
// $submited_payload = $_POST[$key]; |
52 |
|
// if (! empty($submited_payload)) { |
53 |
|
// $new_payload = str_replace("'", '"', $val[$key]); |
54 |
|
// if ($new_payload == $submited_payload || |
55 |
|
// strpos($submited_payload, '"') === false) { |
56 |
|
// $val[$key] = $new_payload; |
57 |
|
// } |
58 |
|
// else { |
59 |
|
// $error_msg = sprintf( |
60 |
|
// __("La convertion des guillemets de la payload JSON '%s' ". |
61 |
|
// "n'est pas idempotente (courante: %s, postée: %s, convertie: %s)"), |
62 |
|
// $key, var_export($val[$key], true), var_export($submited_payload, true), |
63 |
|
// var_export($new_payload, true)); |
64 |
|
// $this->correct = false; |
65 |
|
// $this->addToMessage($error_msg); |
66 |
|
// $this->addToLog(__METHOD__."() erreur : $error_msg", DEBUG_MODE); |
67 |
|
// return false; |
68 |
|
// } |
69 |
|
// } |
70 |
|
// } |
71 |
|
// } |
72 |
|
|
73 |
parent::setvalF($val); |
parent::setvalF($val); |
74 |
// |
|
75 |
|
// XXX Ancien code : permet de ne pas avoir d'erreru lors de la modification d'une task |
76 |
if (array_key_exists('timestamp_log', $val) === true) { |
if (array_key_exists('timestamp_log', $val) === true) { |
77 |
$this->valF['timestamp_log'] = str_replace("'", '"', $val['timestamp_log']); |
$this->valF['timestamp_log'] = str_replace("'", '"', $val['timestamp_log']); |
78 |
} |
} |
79 |
|
|
80 |
|
// récupération de l'ID de l'objet existant |
81 |
|
$id = property_exists($this, 'id') ? $this->id : null; |
82 |
|
if(isset($val[$this->clePrimaire])) { |
83 |
|
$id = $val[$this->clePrimaire]; |
84 |
|
} elseif(isset($this->valF[$this->clePrimaire])) { |
85 |
|
$id = $this->valF[$this->clePrimaire]; |
86 |
|
} |
87 |
|
|
88 |
|
// MODE MODIFIER |
89 |
|
if (! empty($id)) { |
90 |
|
|
91 |
|
// si aucune payload n'est fourni (devrait toujours être le cas) |
92 |
|
if (! isset($val['json_payload']) || empty($val['json_payload'])) { |
93 |
|
|
94 |
|
// récupère l'objet existant |
95 |
|
$existing = $this->f->findObjectById(get_class($this), $id); |
96 |
|
if (! empty($existing)) { |
97 |
|
|
98 |
|
// récupère la payload de l'objet |
99 |
|
$val['json_payload'] = $existing->getVal('json_payload'); |
100 |
|
$this->valF['json_payload'] = $existing->getVal('json_payload'); |
101 |
|
$this->f->addToLog(__METHOD__."() récupère la payload de la tâche existante ". |
102 |
|
"'$id': ".$existing->getVal('json_payload'), EXTRA_VERBOSE_MODE); |
103 |
|
} |
104 |
|
} |
105 |
|
} |
106 |
} |
} |
107 |
|
|
108 |
/** |
/** |
124 |
|
|
125 |
function setType(&$form, $maj) { |
function setType(&$form, $maj) { |
126 |
parent::setType($form, $maj); |
parent::setType($form, $maj); |
127 |
|
|
128 |
// Récupération du mode de l'action |
// Récupération du mode de l'action |
129 |
$crud = $this->get_action_crud($maj); |
$crud = $this->get_action_crud($maj); |
130 |
|
|
131 |
if ($maj < 2) { |
// MODE CREER |
132 |
|
if ($maj == 0 || $crud == 'create') { |
133 |
|
$form->setType("state", "select"); |
134 |
|
$form->setType("stream", "select"); |
135 |
|
$form->setType("json_payload", "textarea"); |
136 |
|
} |
137 |
|
// MDOE MODIFIER |
138 |
|
if ($maj == 1 || $crud == 'update') { |
139 |
$form->setType("state", "select"); |
$form->setType("state", "select"); |
140 |
$form->setType("stream", "select"); |
$form->setType("stream", "select"); |
141 |
$form->setType("json_payload", "jsonprettyprint"); |
$form->setType("json_payload", "jsonprettyprint"); |
142 |
} |
} |
143 |
if ($maj == 3){ |
// MODE CONSULTER |
144 |
|
if ($maj == 3 || $crud == 'read') { |
145 |
$form->setType('dossier', 'link'); |
$form->setType('dossier', 'link'); |
146 |
$form->setType('json_payload', 'jsonprettyprint'); |
$form->setType('json_payload', 'jsonprettyprint'); |
147 |
} |
} |
153 |
*/ |
*/ |
154 |
function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) { |
function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) { |
155 |
if($maj < 2) { |
if($maj < 2) { |
|
$contenu=array(); |
|
156 |
|
|
157 |
$contenu[0][0]="draft"; |
$contenu = array(); |
158 |
$contenu[1][0]=_('draft'); |
foreach(array('DRAFT', 'NEW', 'PENDING', 'DONE', 'ERROR', 'DEBUG') as $key) { |
159 |
$contenu[0][1]="new"; |
$const_name = 'STATUS_'.$key; |
160 |
$contenu[1][1]=_('new'); |
$const_value = constant("self::$const_name"); |
161 |
$contenu[0][2]="pending"; |
$contenu[0][] = $const_value; |
162 |
$contenu[1][2]=_('pending'); |
$contenu[1][] = __($const_value); |
163 |
$contenu[0][3]="done"; |
} |
|
$contenu[1][3]=_('done'); |
|
|
$contenu[0][4]="archived"; |
|
|
$contenu[1][4]=_('archived'); |
|
|
$contenu[0][5]="error"; |
|
|
$contenu[1][5]=_('error'); |
|
|
$contenu[0][6]="debug"; |
|
|
$contenu[1][6]=_('debug'); |
|
164 |
|
|
165 |
$form->setSelect("state", $contenu); |
$form->setSelect("state", $contenu); |
166 |
|
|
207 |
if ($this->getVal('stream') == "output") { |
if ($this->getVal('stream') == "output") { |
208 |
$form->setVal('json_payload', $this->view_form_json(true)); |
$form->setVal('json_payload', $this->view_form_json(true)); |
209 |
} else { |
} else { |
210 |
if ($this->getVal('type') == 'ajout_piece'){ |
$form->setVal('json_payload', htmlentities($this->getVal('json_payload'))); |
|
// On modifie la valeur du champ "file_content" afin de tronquer le base64 |
|
|
$json_payload = json_decode($this->getVal("json_payload"), true); |
|
|
$json_payload["document_numerise"]["file_content"] = substr($json_payload["document_numerise"]["file_content"], 0, 64)."[...]"; |
|
|
$json_payload_result = json_encode($json_payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ); |
|
|
$form->setVal('json_payload', htmlentities($json_payload_result)); |
|
|
} else { |
|
|
// |
|
|
$form->setVal('json_payload', htmlentities($this->getVal('json_payload'))); |
|
|
} |
|
211 |
} |
} |
212 |
} |
} |
213 |
|
|
214 |
function setLib(&$form, $maj) { |
function setLib(&$form, $maj) { |
215 |
parent::setLib($form, $maj); |
parent::setLib($form, $maj); |
216 |
$form->setLib('json_payload', ''); |
|
217 |
|
// Récupération du mode de l'action |
218 |
|
$crud = $this->get_action_crud($maj); |
219 |
|
|
220 |
|
// MODE different de CREER |
221 |
|
if ($maj != 0 || $crud != 'create') { |
222 |
|
$form->setLib('json_payload', ''); |
223 |
|
} |
224 |
} |
} |
225 |
|
|
226 |
public function verifier($val = array(), &$dnu1 = null, $dnu2 = null) { |
public function verifier($val = array(), &$dnu1 = null, $dnu2 = null) { |
227 |
$ret = parent::verifier($val, $dnu1, $dnu2); |
$ret = parent::verifier($val, $dnu1, $dnu2); |
228 |
|
|
|
if (array_key_exists('timestamp_log', $this->valF) === true |
|
|
&& is_array(json_decode($this->valF['timestamp_log'], true)) === false) { |
|
|
// |
|
|
$this->correct = false; |
|
|
$this->addToMessage(sprintf( |
|
|
__("Le champ %s doit être dans un format JSON valide."), |
|
|
sprintf('<span class="bold">%s</span>', $this->getLibFromField('timestamp_log')) |
|
|
)); |
|
|
} |
|
|
|
|
229 |
// une tâche entrante doit avoir un type et une payload non-vide |
// une tâche entrante doit avoir un type et une payload non-vide |
230 |
if (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') { |
if (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') { |
231 |
if (isset($this->valF['type']) === false) { |
if (isset($this->valF['type']) === false) { |
246 |
} |
} |
247 |
} |
} |
248 |
|
|
249 |
// le JSON doit être décodable |
// les JSONs doivent être décodables |
250 |
if (isset($this->valF['json_payload']) && ! empty($this->valF['json_payload']) && ( |
foreach(array('json_payload', 'timestamp_log') as $key) { |
251 |
is_array(json_decode($this->valF['json_payload'], true)) === false |
if (isset($this->valF[$key]) && ! empty($this->valF[$key]) && ( |
252 |
|| json_last_error() !== JSON_ERROR_NONE)) { |
is_array(json_decode($this->valF[$key], true)) === false |
253 |
$this->correct = false; |
|| json_last_error() !== JSON_ERROR_NONE)) { |
254 |
$this->addToMessage(sprintf( |
$this->correct = false; |
255 |
__("Le champ %s doit être dans un format JSON valide (erreur: %s)."), |
$champ_text = sprintf('<span class="bold">%s</span>', $this->getLibFromField($key)); |
256 |
sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload'), |
$this->addToMessage(sprintf( |
257 |
json_last_error() !== JSON_ERROR_NONE ? json_last_error_msg() : __('invalide')) |
__("Le champ %s doit être dans un format JSON valide (erreur: %s).". |
258 |
)); |
"<p>%s valF:</br><pre>%s</pre></p>". |
259 |
$this->addToLog(__METHOD__.'(): erreur JSON: '.$this->msg, DEBUG_MODE); |
"<p>%s val:</br><pre>%s</pre></p>". |
260 |
|
"<p>%s POST:</br><pre>%s</pre></p>". |
261 |
|
"<p>%s submitted POST value:</br><pre>%s</pre></p>"), |
262 |
|
$champ_text, |
263 |
|
json_last_error() !== JSON_ERROR_NONE ? json_last_error_msg() : __('invalide'), |
264 |
|
$champ_text, |
265 |
|
$this->valF[$key], |
266 |
|
$champ_text, |
267 |
|
$val[$key], |
268 |
|
$champ_text, |
269 |
|
isset($_POST[$key]) ? $_POST[$key] : '', |
270 |
|
$champ_text, |
271 |
|
$this->f->get_submitted_post_value($key) |
272 |
|
)); |
273 |
|
$this->addToLog(__METHOD__.'(): erreur JSON: '.$this->msg, DEBUG_MODE); |
274 |
|
} |
275 |
} |
} |
276 |
|
|
277 |
// une tâche entrante doit avoir une payload avec les clés requises |
// une tâche entrante doit avoir une payload avec les clés requises |
278 |
elseif (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') { |
if ($this->correct && (isset($this->valF['stream']) === false || |
279 |
|
$this->valF['stream'] == 'input')) { |
280 |
|
|
281 |
// décode la payload JSON |
// décode la payload JSON |
282 |
$json_payload = json_decode($this->valF['json_payload'], true); |
$json_payload = json_decode($this->valF['json_payload'], true); |
283 |
|
|
284 |
// défini une liste de chemin de clés requises |
// défini une liste de chemin de clés requises |
285 |
$paths = array( |
$paths = array( |
286 |
'dossier/dossier' |
'external_uids/dossier' |
287 |
); |
); |
288 |
|
|
289 |
// tâche de type création de DI/DA |
// tâche de type création de DI/DA |
290 |
if (isset($this->valF['type']) !== false && $this->valF['type'] == 'create_DI_for_consultation') { |
if (isset($this->valF['type']) !== false && $this->valF['type'] == 'create_DI_for_consultation') { |
291 |
|
|
292 |
$paths = array_merge($paths, array( |
$paths = array_merge($paths, array( |
293 |
|
'dossier/dossier', |
294 |
'dossier/dossier_autorisation_type_detaille_code', |
'dossier/dossier_autorisation_type_detaille_code', |
295 |
'dossier/date_demande', |
'dossier/date_demande', |
296 |
'dossier/depot_electronique', |
'dossier/depot_electronique', |
302 |
} |
} |
303 |
|
|
304 |
// présence d'un moyen d'identifier la collectivité/le service |
// présence d'un moyen d'identifier la collectivité/le service |
305 |
if (! isset($json_payload['dossier']['acteur']) && |
if (! isset($json_payload['external_uids']['acteur']) && |
306 |
! isset($json_payload['dossier']['om_collectivite'])) { |
! isset($json_payload['dossier']['om_collectivite'])) { |
307 |
$this->correct = false; |
$this->correct = false; |
308 |
$this->addToMessage(sprintf( |
$this->addToMessage(sprintf( |
309 |
__("L'une des clés %s ou %s est obligatoire dans le contenu du champ %s pour une tâche entrante."), |
__("L'une des clés %s ou %s est obligatoire dans le contenu du champ %s pour une tâche entrante."), |
310 |
sprintf('<span class="bold">%s</span>', 'dossier/acteur'), |
sprintf('<span class="bold">%s</span>', 'external_uids/acteur'), |
311 |
sprintf('<span class="bold">%s</span>', 'dossier/om_collectivite'), |
sprintf('<span class="bold">%s</span>', 'dossier/om_collectivite'), |
312 |
sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload')) |
sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload')) |
313 |
)); |
)); |
359 |
AND object_id = \'%4$s\' |
AND object_id = \'%4$s\' |
360 |
', |
', |
361 |
DB_PREFIXE, |
DB_PREFIXE, |
362 |
'done', |
self::STATUS_DONE, |
363 |
$type, |
$type, |
364 |
$object_id |
$object_id |
365 |
); |
); |
388 |
// décode la paylod JSON pour extraire les données métiers à ajouter |
// décode la paylod JSON pour extraire les données métiers à ajouter |
389 |
// en tant que métadonnées de la tâche |
// en tant que métadonnées de la tâche |
390 |
$json_payload = json_decode($this->valF['json_payload'], true); |
$json_payload = json_decode($this->valF['json_payload'], true); |
391 |
$this->valF["dossier"] = $json_payload['dossier']['dossier']; |
|
392 |
|
// si la tâche possède déjà une clé dossier |
393 |
|
if (isset($json_payload['dossier']['dossier']) && |
394 |
|
! empty($json_payload['dossier']['dossier'])) { |
395 |
|
$this->valF["dossier"] = $json_payload['dossier']['dossier']; |
396 |
|
} |
397 |
} |
} |
398 |
} |
} |
399 |
|
|
406 |
*/ |
*/ |
407 |
public function add_task($params = array()) { |
public function add_task($params = array()) { |
408 |
$this->begin_treatment(__METHOD__); |
$this->begin_treatment(__METHOD__); |
409 |
|
|
410 |
|
// Vérifie si la task doit être ajoutée en fonction du mode de l'application, |
411 |
|
// seulement pour les tasks output |
412 |
|
$task_types_si = array( |
413 |
|
'creation_DA', |
414 |
|
'creation_DI', |
415 |
|
'depot_DI', |
416 |
|
'modification_DI', |
417 |
|
'qualification_DI', |
418 |
|
'decision_DI', |
419 |
|
'incompletude_DI', |
420 |
|
'completude_DI', |
421 |
|
'ajout_piece', |
422 |
|
'add_piece', |
423 |
|
); |
424 |
|
$task_types_sc = array( |
425 |
|
'create_DI_for_consultation', |
426 |
|
'avis_consultation', |
427 |
|
'pec_metier_consultation', |
428 |
|
); |
429 |
|
$stream = isset($params['val']['stream']) === true ? $params['val']['stream'] : 'output'; |
430 |
|
if ($stream === 'output' |
431 |
|
&& isset($params['val']['type']) === true |
432 |
|
&& $this->f->is_option_mode_service_consulte_enabled() === true |
433 |
|
&& in_array($params['val']['type'], $task_types_sc) === false) { |
434 |
|
// |
435 |
|
return $this->end_treatment(__METHOD__, true); |
436 |
|
} |
437 |
|
if ($stream === 'output' |
438 |
|
&& isset($params['val']['type']) === true |
439 |
|
&& $this->f->is_option_mode_service_consulte_enabled() === false |
440 |
|
&& in_array($params['val']['type'], $task_types_si) === false) { |
441 |
|
// |
442 |
|
return $this->end_treatment(__METHOD__, true); |
443 |
|
} |
444 |
|
|
445 |
$timestamp_log = json_encode(array( |
$timestamp_log = json_encode(array( |
446 |
'creation_date' => date('Y-m-d H:i:s'), |
'creation_date' => date('Y-m-d H:i:s'), |
447 |
)); |
)); |
449 |
// Si la tâche est de type ajout_piece et de stream input alors on ajoute le fichier |
// Si la tâche est de type ajout_piece et de stream input alors on ajoute le fichier |
450 |
// et on ajoute l'uid dans le champ json_payload avant l'ajout de la tâche |
// et on ajoute l'uid dans le champ json_payload avant l'ajout de la tâche |
451 |
if (isset($params['val']['type']) |
if (isset($params['val']['type']) |
452 |
&& $params['val']['type'] == "ajout_piece" |
&& $params['val']['type'] == "add_piece" |
453 |
&& isset($params['val']['stream']) |
&& isset($params['val']['stream']) |
454 |
&& $params['val']['stream'] == "input" ) { |
&& $params['val']['stream'] == "input" ) { |
455 |
// |
// |
456 |
$json_payload = json_decode($params['val']['json_payload'], true); |
$json_payload = json_decode($params['val']['json_payload'], true); |
457 |
|
if (json_last_error() !== JSON_ERROR_NONE) { |
458 |
|
$this->addToMessage(__("Le contenu JSON de la tâche n'est pas valide.")); |
459 |
|
return $this->end_treatment(__METHOD__, false); |
460 |
|
} |
461 |
$document_numerise = $json_payload['document_numerise']; |
$document_numerise = $json_payload['document_numerise']; |
462 |
$file_content = base64_decode($document_numerise["file_content"]); |
$file_content = base64_decode($document_numerise["file_content"]); |
463 |
if ($file_content === false){ |
if ($file_content === false){ |
476 |
return $this->end_treatment(__METHOD__, false); |
return $this->end_treatment(__METHOD__, false); |
477 |
} |
} |
478 |
$json_payload["document_numerise"]["uid"] = $uid_fichier; |
$json_payload["document_numerise"]["uid"] = $uid_fichier; |
479 |
|
// Le fichier a été ajouté nous n'avons plus besoin du champ file_content dans la payload |
480 |
|
unset($json_payload["document_numerise"]["file_content"]); |
481 |
$params['val']['json_payload'] = json_encode($json_payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
$params['val']['json_payload'] = json_encode($json_payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
482 |
} |
} |
483 |
|
|
486 |
'task' => '', |
'task' => '', |
487 |
'type' => $params['val']['type'], |
'type' => $params['val']['type'], |
488 |
'timestamp_log' => $timestamp_log, |
'timestamp_log' => $timestamp_log, |
489 |
'state' => isset($params['val']['state']) === true ? $params['val']['state'] : 'new', |
'state' => isset($params['val']['state']) === true ? $params['val']['state'] : self::STATUS_NEW, |
490 |
'object_id' => isset($params['val']['object_id']) ? $params['val']['object_id'] : '', |
'object_id' => isset($params['val']['object_id']) ? $params['val']['object_id'] : '', |
491 |
'dossier' => isset($params['val']['dossier']) ? $params['val']['dossier'] : '', |
'dossier' => isset($params['val']['dossier']) ? $params['val']['dossier'] : '', |
492 |
'stream' => isset($params['val']['stream']) === true ? $params['val']['stream'] : 'output', |
'stream' => $stream, |
493 |
'json_payload' => isset($params['val']['json_payload']) === true ? $params['val']['json_payload'] : '{}', |
'json_payload' => isset($params['val']['json_payload']) === true ? $params['val']['json_payload'] : '{}', |
494 |
); |
); |
495 |
|
|
539 |
$this->begin_treatment(__METHOD__); |
$this->begin_treatment(__METHOD__); |
540 |
$timestamp_log = $this->get_timestamp_log(); |
$timestamp_log = $this->get_timestamp_log(); |
541 |
if ($timestamp_log === false) { |
if ($timestamp_log === false) { |
542 |
$this->addToLog(__('XXX'), DEBUG_MODE); |
$this->addToLog(__METHOD__."(): erreur timestamp log", DEBUG_MODE); |
543 |
return $this->end_treatment(__METHOD__, false); |
return $this->end_treatment(__METHOD__, false); |
544 |
} |
} |
545 |
array_push($timestamp_log, array( |
array_push($timestamp_log, array( |
627 |
$list_tasks = array(); |
$list_tasks = array(); |
628 |
foreach ($res['result'] as $task) { |
foreach ($res['result'] as $task) { |
629 |
$task['timestamp_log'] = json_decode($task['timestamp_log'], true); |
$task['timestamp_log'] = json_decode($task['timestamp_log'], true); |
630 |
$task['dossier'] = $task['object_id']; |
$task['dossier'] = $task['dossier']; |
631 |
if ($this->get_lien_objet_by_type($task['type']) === 'document_numerise') { |
if ($task['type'] === 'ajout_piece') { |
632 |
$val_dn = $this->get_document_numerise_data($task['object_id']); |
$val_dn = $this->get_document_numerise_data($task['object_id']); |
633 |
$task['dossier'] = $val_dn['dossier']; |
} |
634 |
|
if ($task['stream'] === 'output') { |
635 |
|
$task['external_uids'] = $this->get_all_external_uids($task['dossier']); |
636 |
} |
} |
637 |
$list_tasks[$task['task']] = $task; |
$list_tasks[$task['task']] = $task; |
638 |
} |
} |
775 |
return $val_dt; |
return $val_dt; |
776 |
} |
} |
777 |
|
|
778 |
|
/** |
779 |
|
* Récupère la liste des objets distincts existants dans la table des liens |
780 |
|
* entre identifiants internes et identifiants externes. |
781 |
|
* |
782 |
|
* @return array |
783 |
|
*/ |
784 |
|
protected function get_list_distinct_objects_external_link() { |
785 |
|
$query = sprintf(' |
786 |
|
SELECT |
787 |
|
DISTINCT(object) |
788 |
|
FROM %1$slien_id_interne_uid_externe |
789 |
|
ORDER BY object ASC |
790 |
|
', |
791 |
|
DB_PREFIXE |
792 |
|
); |
793 |
|
$res = $this->f->get_all_results_from_db_query($query, true); |
794 |
|
if ($res['code'] === 'KO') { |
795 |
|
return array(); |
796 |
|
} |
797 |
|
$result = array(); |
798 |
|
foreach ($res['result'] as $object) { |
799 |
|
$result[] = $object['object']; |
800 |
|
} |
801 |
|
return $result; |
802 |
|
} |
803 |
|
|
804 |
protected function get_external_uid($fk_idx, string $fk_idx_2) { |
protected function get_external_uid($fk_idx, string $fk_idx_2) { |
805 |
$inst_external_uid = $this->f->get_inst__by_other_idx(array( |
$inst_external_uid = $this->f->get_inst__by_other_idx(array( |
806 |
"obj" => "lien_id_interne_uid_externe", |
"obj" => "lien_id_interne_uid_externe", |
812 |
return $inst_external_uid->getVal('external_uid'); |
return $inst_external_uid->getVal('external_uid'); |
813 |
} |
} |
814 |
|
|
815 |
|
protected function get_all_external_uids($fk_idx, $link_objects = array()) { |
816 |
|
if (count($link_objects) == 0) { |
817 |
|
$link_objects = $this->get_list_distinct_objects_external_link(); |
818 |
|
} |
819 |
|
$val_external_uid = array(); |
820 |
|
foreach ($link_objects as $link_object) { |
821 |
|
$external_uid = $this->get_external_uid($fk_idx, $link_object); |
822 |
|
if ($external_uid !== '' && $external_uid !== null) { |
823 |
|
$val_external_uid[$link_object] = $external_uid; |
824 |
|
} |
825 |
|
} |
826 |
|
return $val_external_uid; |
827 |
|
} |
828 |
|
|
829 |
protected function get_demandeurs_data(string $dossier) { |
protected function get_demandeurs_data(string $dossier) { |
830 |
$val_demandeur = array(); |
$val_demandeur = array(); |
831 |
$inst_di = $this->f->get_inst__om_dbform(array( |
$inst_di = $this->f->get_inst__om_dbform(array( |
858 |
return $val_architecte; |
return $val_architecte; |
859 |
} |
} |
860 |
|
|
861 |
protected function get_instruction_data(string $dossier, $type = 'decision') { |
protected function get_instruction_data(string $dossier, $type = 'decision', $extra_params = array()) { |
862 |
$val_instruction = null; |
$val_instruction = null; |
863 |
$instruction_with_doc = null; |
$instruction_with_doc = null; |
864 |
$inst_di = $this->f->get_inst__om_dbform(array( |
$inst_di = $this->f->get_inst__om_dbform(array( |
872 |
if ($type === 'incompletude') { |
if ($type === 'incompletude') { |
873 |
$idx = $inst_di->get_last_instruction_incompletude(); |
$idx = $inst_di->get_last_instruction_incompletude(); |
874 |
} |
} |
875 |
|
// XXX Permet de récupérer l'instruction par son identifiant |
876 |
|
if ($type === 'with-id') { |
877 |
|
$idx = $extra_params['with-id']; |
878 |
|
} |
879 |
$inst_instruction = $this->f->get_inst__om_dbform(array( |
$inst_instruction = $this->f->get_inst__om_dbform(array( |
880 |
"obj" => "instruction", |
"obj" => "instruction", |
881 |
"idx" => $idx, |
"idx" => $idx, |
921 |
|
|
922 |
protected function sort_instruction_data(array $values, array $res) { |
protected function sort_instruction_data(array $values, array $res) { |
923 |
$fields = array( |
$fields = array( |
924 |
|
"date_evenement", |
925 |
"date_envoi_signature", |
"date_envoi_signature", |
926 |
"date_retour_signature", |
"date_retour_signature", |
927 |
"date_envoi_rar", |
"date_envoi_rar", |
982 |
return $val_dp; |
return $val_dp; |
983 |
} |
} |
984 |
|
|
985 |
|
protected function get_avis_decision_data(string $dossier) { |
986 |
|
$inst_di = $this->f->get_inst__om_dbform(array( |
987 |
|
"obj" => "dossier", |
988 |
|
"idx" => $dossier, |
989 |
|
)); |
990 |
|
$ad = $inst_di->getVal('avis_decision'); |
991 |
|
$val_ad = array(); |
992 |
|
$inst_ad = $this->f->get_inst__om_dbform(array( |
993 |
|
"obj" => "avis_decision", |
994 |
|
"idx" => $ad, |
995 |
|
)); |
996 |
|
$val_ad = $inst_ad->get_json_data(); |
997 |
|
$val_ad['txAvis'] = "Voir document joint"; |
998 |
|
if (isset($val_ad['tacite']) === true |
999 |
|
&& $val_ad['tacite'] === 't') { |
1000 |
|
// |
1001 |
|
$val_ad['txAvis'] = "Sans objet"; |
1002 |
|
} |
1003 |
|
return $val_ad; |
1004 |
|
} |
1005 |
|
|
1006 |
|
protected function get_signataire_arrete_data(string $sa) { |
1007 |
|
$inst_sa = $this->f->get_inst__om_dbform(array( |
1008 |
|
"obj" => "signataire_arrete", |
1009 |
|
"idx" => $sa, |
1010 |
|
)); |
1011 |
|
$val_sa = array_combine($inst_sa->champs, $inst_sa->val); |
1012 |
|
foreach ($val_sa as $key => $value) { |
1013 |
|
$val_sa[$key] = strip_tags($value); |
1014 |
|
} |
1015 |
|
return $val_sa; |
1016 |
|
} |
1017 |
|
|
1018 |
protected function view_form_json($in_field = false) { |
protected function view_form_json($in_field = false) { |
1019 |
// |
// |
1020 |
if ($this->f->get_submitted_post_value('valid') === null) { |
if ($this->f->get_submitted_post_value('valid') === null) { |
1072 |
} |
} |
1073 |
// |
// |
1074 |
if ($this->getVal('type') === 'decision_DI') { |
if ($this->getVal('type') === 'decision_DI') { |
1075 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1076 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier']); |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1077 |
$val_external_uid = array(); |
$val_external_uid = array(); |
1078 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1079 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1081 |
} |
} |
1082 |
// |
// |
1083 |
if ($this->getVal('type') === 'incompletude_DI') { |
if ($this->getVal('type') === 'incompletude_DI') { |
1084 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1085 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'incompletude'); |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1086 |
$val_external_uid = array(); |
$val_external_uid = array(); |
1087 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1088 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1090 |
} |
} |
1091 |
// |
// |
1092 |
if ($this->getVal('type') === 'completude_DI') { |
if ($this->getVal('type') === 'completude_DI') { |
1093 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1094 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'completude'); |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1095 |
|
$val_external_uid = array(); |
1096 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1097 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1098 |
|
$val['external_uids'] = $val_external_uid; |
1099 |
|
} |
1100 |
|
// |
1101 |
|
if ($this->getVal('type') === 'pec_metier_consultation') { |
1102 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1103 |
|
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
1104 |
|
$val_external_uid = array(); |
1105 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1106 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1107 |
|
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
1108 |
|
$val['external_uids'] = $val_external_uid; |
1109 |
|
} |
1110 |
|
// |
1111 |
|
if ($this->getVal('type') === 'avis_consultation') { |
1112 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1113 |
|
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
1114 |
|
$val['avis_decision'] = $this->get_avis_decision_data($this->getVal('dossier')); |
1115 |
|
if (isset($val['instruction']['signataire_arrete']) === true) { |
1116 |
|
$val['signataire_arrete'] = $this->get_signataire_arrete_data($val['instruction']['signataire_arrete']); |
1117 |
|
} |
1118 |
$val_external_uid = array(); |
$val_external_uid = array(); |
1119 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1120 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1121 |
|
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
1122 |
$val['external_uids'] = $val_external_uid; |
$val['external_uids'] = $val_external_uid; |
1123 |
} |
} |
1124 |
|
|
1133 |
|
|
1134 |
function post_update_task() { |
function post_update_task() { |
1135 |
// Mise à jour des valeurs |
// Mise à jour des valeurs |
1136 |
// |
|
1137 |
$params = array( |
// Modification de l'état de la tâche |
1138 |
'val' => array( |
if ($this->f->get_submitted_post_value('state') !== null) { |
1139 |
'state' => $this->f->get_submitted_post_value('state') |
$params = array( |
1140 |
), |
'val' => array( |
1141 |
); |
'state' => $this->f->get_submitted_post_value('state') |
1142 |
$update = $this->update_task($params); |
), |
|
$message_class = "valid"; |
|
|
$message = $this->msg; |
|
|
if ($update === false) { |
|
|
$this->addToLog($this->msg, DEBUG_MODE); |
|
|
$message_class = "error"; |
|
|
$message = sprintf( |
|
|
'%s %s', |
|
|
__('Impossible de mettre à jour la tâche.'), |
|
|
__('Veuillez contacter votre administrateur.') |
|
1143 |
); |
); |
1144 |
|
$update = $this->update_task($params); |
1145 |
|
$message_class = "valid"; |
1146 |
|
$message = $this->msg; |
1147 |
|
if ($update === false) { |
1148 |
|
$this->addToLog($this->msg, DEBUG_MODE); |
1149 |
|
$message_class = "error"; |
1150 |
|
$message = sprintf( |
1151 |
|
'%s %s', |
1152 |
|
__('Impossible de mettre à jour la tâche.'), |
1153 |
|
__('Veuillez contacter votre administrateur.') |
1154 |
|
); |
1155 |
|
} |
1156 |
|
$this->f->displayMessage($message_class, $message); |
1157 |
} |
} |
1158 |
$this->f->displayMessage($message_class, $message); |
|
1159 |
// |
// Sauvegarde de l'uid externe retourné |
1160 |
$inst_lien = $this->f->get_inst__om_dbform(array( |
if ($this->f->get_submitted_post_value('external_uid') !== null) { |
1161 |
"obj" => "lien_id_interne_uid_externe", |
// |
1162 |
"idx" => ']', |
$objects = $this->get_objects_by_task_type($this->getVal('type')); |
1163 |
)); |
foreach ($objects as $object) { |
1164 |
$valF = array( |
$inst_lien = $this->f->get_inst__om_dbform(array( |
1165 |
'lien_id_interne_uid_externe' => '', |
"obj" => "lien_id_interne_uid_externe", |
1166 |
'object' => $this->get_lien_objet_by_type($this->getVal('type')), |
"idx" => ']', |
1167 |
'object_id' => $this->getVal('object_id'), |
)); |
1168 |
'external_uid' => $this->f->get_submitted_post_value('external_uid'), |
if ($inst_lien->is_exists($object, $this->getVal('object_id'), $this->f->get_submitted_post_value('external_uid'), $this->getVal('dossier')) === false) { |
1169 |
); |
$valF = array( |
1170 |
$add = $inst_lien->ajouter($valF); |
'lien_id_interne_uid_externe' => '', |
1171 |
$message_class = "valid"; |
'object' => $object, |
1172 |
$message = $inst_lien->msg; |
'object_id' => $this->getVal('object_id'), |
1173 |
if ($add === false) { |
'external_uid' => $this->f->get_submitted_post_value('external_uid'), |
1174 |
$this->addToLog($inst_lien->msg, DEBUG_MODE); |
'dossier' => $this->getVal('dossier'), |
1175 |
$message_class = "error"; |
); |
1176 |
$message = sprintf( |
$add = $inst_lien->ajouter($valF); |
1177 |
'%s %s', |
$message_class = "valid"; |
1178 |
__("Impossible de mettre à jour le lien entre l'identifiant interne et l'identifiant de l'application externe."), |
$message = $inst_lien->msg; |
1179 |
__('Veuillez contacter votre administrateur.') |
if ($add === false) { |
1180 |
); |
$this->addToLog($inst_lien->msg, DEBUG_MODE); |
1181 |
|
$message_class = "error"; |
1182 |
|
$message = sprintf( |
1183 |
|
'%s %s', |
1184 |
|
__("Impossible de mettre à jour le lien entre l'identifiant interne et l'identifiant de l'application externe."), |
1185 |
|
__('Veuillez contacter votre administrateur.') |
1186 |
|
); |
1187 |
|
} |
1188 |
|
$this->f->displayMessage($message_class, $message); |
1189 |
|
} |
1190 |
|
} |
1191 |
} |
} |
|
$this->f->displayMessage($message_class, $message); |
|
1192 |
} |
} |
1193 |
|
|
1194 |
function post_add_task() { |
function post_add_task() { |
1200 |
'type' => $this->f->get_submitted_post_value('type'), |
'type' => $this->f->get_submitted_post_value('type'), |
1201 |
) |
) |
1202 |
)); |
)); |
1203 |
$message = $this->msg; |
$message = sprintf( |
1204 |
|
__("Tâche %s ajoutée avec succès"), |
1205 |
|
$this->getVal($this->clePrimaire)). |
1206 |
|
'<br/><br/>'. |
1207 |
|
$this->msg; |
1208 |
$message_class = "valid"; |
$message_class = "valid"; |
1209 |
if ($result === false){ |
if ($result === false){ |
1210 |
$this->addToLog($this->msg, DEBUG_MODE); |
$this->addToLog($this->msg, DEBUG_MODE); |
1218 |
$this->f->displayMessage($message_class, $message); |
$this->f->displayMessage($message_class, $message); |
1219 |
} |
} |
1220 |
|
|
1221 |
function get_lien_objet_by_type($type) { |
function setLayout(&$form, $maj) { |
1222 |
// |
|
1223 |
$objet = ''; |
// Récupération du mode de l'action |
1224 |
if ($type === 'creation_DA') { |
$crud = $this->get_action_crud($maj); |
1225 |
$objet = 'dossier_autorisation'; |
|
1226 |
} |
// MODE different de CREER |
1227 |
if ($type === 'creation_DI' |
if ($maj != 0 || $crud != 'create') { |
1228 |
|| $type === 'create_DI_for_consultation' |
$form->setBloc('json_payload', 'D', '', 'col_6'); |
1229 |
|| $type === 'depot_DI' |
$form->setFieldset('json_payload', 'DF', __("json_payload"), "collapsible, startClosed"); |
1230 |
|| $type === 'modification_DI' |
$form->setBloc('json_payload', 'F'); |
|
|| $type === 'qualification_DI' |
|
|
|| $type === 'decision_DI' |
|
|
|| $type === 'incompletude_DI' |
|
|
|| $type === 'completude_DI') { |
|
|
// |
|
|
$objet = 'dossier'; |
|
|
} |
|
|
if ($type === 'ajout_piece') { |
|
|
$objet = 'document_numerise'; |
|
1231 |
} |
} |
1232 |
return $objet; |
$form->setBloc('timestamp_log', 'DF', '', 'col_9'); |
1233 |
} |
} |
1234 |
|
|
1235 |
function setLayout(&$form, $maj) { |
/** |
1236 |
$form->setBloc('json_payload', 'D', '', 'col_6'); |
* [get_objects_by_task_type description] |
1237 |
$form->setFieldset('json_payload', 'DF', __("json_payload"), "collapsible, startClosed"); |
* @param [type] $type [description] |
1238 |
$form->setBloc('json_payload', 'F'); |
* @return [type] [description] |
1239 |
$form->setBloc('timestamp_log', 'DF', '', 'col_9'); |
*/ |
1240 |
|
function get_objects_by_task_type($type) { |
1241 |
|
$objects = array(); |
1242 |
|
if (in_array($type, array('creation_DA', )) === true) { |
1243 |
|
$objects = array('dossier_autorisation', ); |
1244 |
|
} |
1245 |
|
if (in_array($type, array('creation_DI', 'depot_DI', 'notification_DI', 'qualification_DI', )) === true) { |
1246 |
|
$objects = array('dossier', ); |
1247 |
|
} |
1248 |
|
if (in_array($type, array('create_DI_for_consultation', )) === true) { |
1249 |
|
$objects = array('dossier', 'dossier_consultation', ); |
1250 |
|
} |
1251 |
|
if (in_array($type, array('decision_DI', 'incompletude_DI', 'completude_DI', )) === true) { |
1252 |
|
$objects = array('instruction', ); |
1253 |
|
} |
1254 |
|
if (in_array($type, array('pec_metier_consultation', )) === true) { |
1255 |
|
$objects = array('pec_dossier_consultation', ); |
1256 |
|
} |
1257 |
|
if (in_array($type, array('avis_consultation', )) === true) { |
1258 |
|
$objects = array('avis_dossier_consultation', ); |
1259 |
|
} |
1260 |
|
if (in_array($type, array('ajout_piece', 'add_piece', )) === true) { |
1261 |
|
$objects = array('piece', ); |
1262 |
|
} |
1263 |
|
return $objects; |
1264 |
} |
} |
1265 |
|
|
1266 |
} |
} |