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 |
if (array_key_exists('timestamp_log', $val) === true) { |
// récupération de l'ID de l'objet existant |
76 |
$this->valF['timestamp_log'] = str_replace("'", '"', $val['timestamp_log']); |
$id = property_exists($this, 'id') ? $this->id : null; |
77 |
|
if(isset($val[$this->clePrimaire])) { |
78 |
|
$id = $val[$this->clePrimaire]; |
79 |
|
} elseif(isset($this->valF[$this->clePrimaire])) { |
80 |
|
$id = $this->valF[$this->clePrimaire]; |
81 |
|
} |
82 |
|
|
83 |
|
// MODE MODIFIER |
84 |
|
if (! empty($id)) { |
85 |
|
|
86 |
|
// si aucune payload n'est fourni (devrait toujours être le cas) |
87 |
|
if (! isset($val['json_payload']) || empty($val['json_payload'])) { |
88 |
|
|
89 |
|
// récupère l'objet existant |
90 |
|
$existing = $this->f->findObjectById(get_class($this), $id); |
91 |
|
if (! empty($existing)) { |
92 |
|
|
93 |
|
// récupère la payload de l'objet |
94 |
|
$val['json_payload'] = $existing->getVal('json_payload'); |
95 |
|
$this->valF['json_payload'] = $existing->getVal('json_payload'); |
96 |
|
$this->f->addToLog(__METHOD__."() récupère la payload de la tâche existante ". |
97 |
|
"'$id': ".$existing->getVal('json_payload'), EXTRA_VERBOSE_MODE); |
98 |
|
} |
99 |
|
} |
100 |
} |
} |
101 |
} |
} |
102 |
|
|
119 |
|
|
120 |
function setType(&$form, $maj) { |
function setType(&$form, $maj) { |
121 |
parent::setType($form, $maj); |
parent::setType($form, $maj); |
122 |
|
|
123 |
// Récupération du mode de l'action |
// Récupération du mode de l'action |
124 |
$crud = $this->get_action_crud($maj); |
$crud = $this->get_action_crud($maj); |
125 |
|
|
126 |
if ($maj < 2) { |
// MODE CREER |
127 |
|
if ($maj == 0 || $crud == 'create') { |
128 |
|
$form->setType("state", "select"); |
129 |
|
$form->setType("stream", "select"); |
130 |
|
$form->setType("json_payload", "textarea"); |
131 |
|
} |
132 |
|
// MDOE MODIFIER |
133 |
|
if ($maj == 1 || $crud == 'update') { |
134 |
$form->setType("state", "select"); |
$form->setType("state", "select"); |
135 |
$form->setType("stream", "select"); |
$form->setType("stream", "select"); |
136 |
$form->setType("json_payload", "jsonprettyprint"); |
$form->setType("json_payload", "jsonprettyprint"); |
137 |
} |
} |
138 |
if ($maj == 3){ |
// MODE CONSULTER |
139 |
|
if ($maj == 3 || $crud == 'read') { |
140 |
$form->setType('dossier', 'link'); |
$form->setType('dossier', 'link'); |
141 |
$form->setType('json_payload', 'jsonprettyprint'); |
$form->setType('json_payload', 'jsonprettyprint'); |
142 |
} |
} |
208 |
|
|
209 |
function setLib(&$form, $maj) { |
function setLib(&$form, $maj) { |
210 |
parent::setLib($form, $maj); |
parent::setLib($form, $maj); |
211 |
$form->setLib('json_payload', ''); |
|
212 |
|
// Récupération du mode de l'action |
213 |
|
$crud = $this->get_action_crud($maj); |
214 |
|
|
215 |
|
// MODE different de CREER |
216 |
|
if ($maj != 0 || $crud != 'create') { |
217 |
|
$form->setLib('json_payload', ''); |
218 |
|
} |
219 |
} |
} |
220 |
|
|
221 |
public function verifier($val = array(), &$dnu1 = null, $dnu2 = null) { |
public function verifier($val = array(), &$dnu1 = null, $dnu2 = null) { |
222 |
$ret = parent::verifier($val, $dnu1, $dnu2); |
$ret = parent::verifier($val, $dnu1, $dnu2); |
223 |
|
|
|
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')) |
|
|
)); |
|
|
} |
|
|
|
|
224 |
// 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 |
225 |
if (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') { |
if (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') { |
226 |
if (isset($this->valF['type']) === false) { |
if (isset($this->valF['type']) === false) { |
241 |
} |
} |
242 |
} |
} |
243 |
|
|
244 |
// le JSON doit être décodable |
// les JSONs doivent être décodables |
245 |
if (isset($this->valF['json_payload']) && ! empty($this->valF['json_payload']) && ( |
foreach(array('json_payload', 'timestamp_log') as $key) { |
246 |
is_array(json_decode($this->valF['json_payload'], true)) === false |
if (isset($this->valF[$key]) && ! empty($this->valF[$key]) && ( |
247 |
|| json_last_error() !== JSON_ERROR_NONE)) { |
is_array(json_decode($this->valF[$key], true)) === false |
248 |
$this->correct = false; |
|| json_last_error() !== JSON_ERROR_NONE)) { |
249 |
$this->addToMessage(sprintf( |
$this->correct = false; |
250 |
__("Le champ %s doit être dans un format JSON valide (erreur: %s)."), |
$champ_text = sprintf('<span class="bold">%s</span>', $this->getLibFromField($key)); |
251 |
sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload'), |
$this->addToMessage(sprintf( |
252 |
json_last_error() !== JSON_ERROR_NONE ? json_last_error_msg() : __('invalide')) |
__("Le champ %s doit être dans un format JSON valide (erreur: %s).". |
253 |
)); |
"<p>%s valF:</br><pre>%s</pre></p>". |
254 |
$this->addToLog(__METHOD__.'(): erreur JSON: '.$this->msg, DEBUG_MODE); |
"<p>%s val:</br><pre>%s</pre></p>". |
255 |
|
"<p>%s POST:</br><pre>%s</pre></p>". |
256 |
|
"<p>%s submitted POST value:</br><pre>%s</pre></p>"), |
257 |
|
$champ_text, |
258 |
|
json_last_error() !== JSON_ERROR_NONE ? json_last_error_msg() : __('invalide'), |
259 |
|
$champ_text, |
260 |
|
$this->valF[$key], |
261 |
|
$champ_text, |
262 |
|
$val[$key], |
263 |
|
$champ_text, |
264 |
|
isset($_POST[$key]) ? $_POST[$key] : '', |
265 |
|
$champ_text, |
266 |
|
$this->f->get_submitted_post_value($key) |
267 |
|
)); |
268 |
|
$this->addToLog(__METHOD__.'(): erreur JSON: '.$this->msg, DEBUG_MODE); |
269 |
|
} |
270 |
} |
} |
271 |
|
|
272 |
// 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 |
273 |
elseif (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') { |
if ($this->correct && (isset($this->valF['stream']) === false || |
274 |
|
$this->valF['stream'] == 'input')) { |
275 |
|
|
276 |
// décode la payload JSON |
// décode la payload JSON |
277 |
$json_payload = json_decode($this->valF['json_payload'], true); |
$json_payload = json_decode($this->valF['json_payload'], true); |
390 |
$this->valF["dossier"] = $json_payload['dossier']['dossier']; |
$this->valF["dossier"] = $json_payload['dossier']['dossier']; |
391 |
} |
} |
392 |
|
|
393 |
|
/** |
394 |
|
* Puisque le dossier n'a potentiellement pas encore été créé |
395 |
|
* alors il faut ne faut chercher à récupérer le numéro de dossier openADS |
396 |
|
* à partir de l'external_uids (en passant par la table de liens) |
397 |
// sinon si la tâche possède une clé external_uids/dossier |
// sinon si la tâche possède une clé external_uids/dossier |
398 |
elseif(isset($json_payload['external_uids']['dossier']) && |
elseif(isset($json_payload['external_uids']['dossier']) && |
399 |
! empty($json_payload['external_uids']['dossier'])) { |
! empty($json_payload['external_uids']['dossier'])) { |
414 |
return false; |
return false; |
415 |
} |
} |
416 |
$this->valF["dossier"] = $dossier; |
$this->valF["dossier"] = $dossier; |
417 |
} |
}*/ |
418 |
} |
} |
419 |
} |
} |
420 |
|
|
520 |
$this->begin_treatment(__METHOD__); |
$this->begin_treatment(__METHOD__); |
521 |
$timestamp_log = $this->get_timestamp_log(); |
$timestamp_log = $this->get_timestamp_log(); |
522 |
if ($timestamp_log === false) { |
if ($timestamp_log === false) { |
523 |
$this->addToLog(__('XXX'), DEBUG_MODE); |
$this->addToLog(__METHOD__."(): erreur timestamp log", DEBUG_MODE); |
524 |
return $this->end_treatment(__METHOD__, false); |
return $this->end_treatment(__METHOD__, false); |
525 |
} |
} |
526 |
array_push($timestamp_log, array( |
array_push($timestamp_log, array( |
797 |
return $val_architecte; |
return $val_architecte; |
798 |
} |
} |
799 |
|
|
800 |
protected function get_instruction_data(string $dossier, $type = 'decision') { |
protected function get_instruction_data(string $dossier, $type = 'decision', $extra_params = array()) { |
801 |
$val_instruction = null; |
$val_instruction = null; |
802 |
$instruction_with_doc = null; |
$instruction_with_doc = null; |
803 |
$inst_di = $this->f->get_inst__om_dbform(array( |
$inst_di = $this->f->get_inst__om_dbform(array( |
811 |
if ($type === 'incompletude') { |
if ($type === 'incompletude') { |
812 |
$idx = $inst_di->get_last_instruction_incompletude(); |
$idx = $inst_di->get_last_instruction_incompletude(); |
813 |
} |
} |
814 |
|
// XXX Permet de récupérer l'instruction par son identifiant |
815 |
|
if ($type === 'with-id') { |
816 |
|
$idx = $extra_params['with-id']; |
817 |
|
} |
818 |
$inst_instruction = $this->f->get_inst__om_dbform(array( |
$inst_instruction = $this->f->get_inst__om_dbform(array( |
819 |
"obj" => "instruction", |
"obj" => "instruction", |
820 |
"idx" => $idx, |
"idx" => $idx, |
860 |
|
|
861 |
protected function sort_instruction_data(array $values, array $res) { |
protected function sort_instruction_data(array $values, array $res) { |
862 |
$fields = array( |
$fields = array( |
863 |
|
"date_evenement", |
864 |
"date_envoi_signature", |
"date_envoi_signature", |
865 |
"date_retour_signature", |
"date_retour_signature", |
866 |
"date_envoi_rar", |
"date_envoi_rar", |
1003 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1004 |
$val['external_uids'] = $val_external_uid; |
$val['external_uids'] = $val_external_uid; |
1005 |
} |
} |
1006 |
|
// |
1007 |
|
if ($this->getVal('type') === 'pec_metier_consultation') { |
1008 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1009 |
|
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
1010 |
|
$val_external_uid = array(); |
1011 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1012 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1013 |
|
$val_external_uid['consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'consultation'); |
1014 |
|
$val['external_uids'] = $val_external_uid; |
1015 |
|
} |
1016 |
|
|
1017 |
if ($in_field === true) { |
if ($in_field === true) { |
1018 |
return json_encode($val, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
return json_encode($val, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
1106 |
|| $type === 'qualification_DI' |
|| $type === 'qualification_DI' |
1107 |
|| $type === 'decision_DI' |
|| $type === 'decision_DI' |
1108 |
|| $type === 'incompletude_DI' |
|| $type === 'incompletude_DI' |
1109 |
|| $type === 'completude_DI') { |
|| $type === 'completude_DI' |
1110 |
|
|| $type === 'pec_metier_consultation') { |
1111 |
// |
// |
1112 |
$objet = 'dossier'; |
$objet = 'dossier'; |
1113 |
} |
} |
1122 |
} |
} |
1123 |
|
|
1124 |
function setLayout(&$form, $maj) { |
function setLayout(&$form, $maj) { |
1125 |
$form->setBloc('json_payload', 'D', '', 'col_6'); |
|
1126 |
$form->setFieldset('json_payload', 'DF', __("json_payload"), "collapsible, startClosed"); |
// Récupération du mode de l'action |
1127 |
$form->setBloc('json_payload', 'F'); |
$crud = $this->get_action_crud($maj); |
1128 |
|
|
1129 |
|
// MODE different de CREER |
1130 |
|
if ($maj != 0 || $crud != 'create') { |
1131 |
|
$form->setBloc('json_payload', 'D', '', 'col_6'); |
1132 |
|
$form->setFieldset('json_payload', 'DF', __("json_payload"), "collapsible, startClosed"); |
1133 |
|
$form->setBloc('json_payload', 'F'); |
1134 |
|
} |
1135 |
$form->setBloc('timestamp_log', 'DF', '', 'col_9'); |
$form->setBloc('timestamp_log', 'DF', '', 'col_9'); |
1136 |
} |
} |
1137 |
|
|