/[openfoncier]/trunk/obj/task.class.php
ViewVC logotype

Annotation of /trunk/obj/task.class.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9404 - (hide annotations)
Tue Jun 2 14:12:09 2020 UTC (4 years, 8 months ago) by softime
Original Path: branches/4.14.0-develop_demat/obj/task.class.php
File size: 17520 byte(s)
* WIP Démat : correction affichage JSON + correction MàJ external_uid

1 softime 9293 <?php
2     //$Id$
3     //gen openMairie le 14/04/2020 14:11
4    
5     require_once "../gen/obj/task.class.php";
6    
7     class task extends task_gen {
8    
9     /**
10     * Définition des actions disponibles sur la classe.
11     *
12     * @return void
13     */
14     public function init_class_actions() {
15     parent::init_class_actions();
16     //
17     $this->class_actions[998] = array(
18 softime 9330 "identifier" => "json_data",
19     "view" => "view_json_data",
20 softime 9293 "permission_suffix" => "consulter",
21     );
22     }
23    
24 softime 9395 protected function task_exists(string $type, string $object_id) {
25     $query = sprintf('
26     SELECT task
27     FROM %1$stask
28     WHERE state != \'%2$s\'
29     AND type = \'%3$s\'
30     AND object_id = \'%4$s\'
31     ',
32     DB_PREFIXE,
33     'done',
34     $type,
35     $object_id
36     );
37     $res = $this->f->get_one_result_from_db_query($query);
38     if ($res['result'] !== null && $res['result'] !== '') {
39     return $res['result'];
40     }
41     return false;
42     }
43    
44 softime 9293 /**
45     * TREATMENT - add_task
46     * Ajoute un enregistrement.
47     *
48     * @param array $params Tableau des paramètres
49     * @return boolean
50     */
51     public function add_task($params = array()) {
52     $this->begin_treatment(__METHOD__);
53     $timestamp_log = json_encode(array(
54     'creation_date' => date('Y-m-d H:i:s'),
55     ));
56     // Mise à jour du DI
57     $valF = array(
58     'task' => '',
59     'type' => $params['val']['type'],
60     'timestamp_log' => $timestamp_log,
61 softime 9385 'state' => isset($params['val']['state']) === true ? $params['val']['state'] : 'new',
62 softime 9389 'object_id' => $params['val']['object_id'],
63 softime 9293 );
64 softime 9395 $task_exists = $this->task_exists($valF['type'], $valF['object_id']);
65     if ($task_exists !== false) {
66     $inst_task = $this->f->get_inst__om_dbform(array(
67     "obj" => "task",
68     "idx" => $task_exists,
69     ));
70     $update_params = array(
71     'val' => array(
72     'state' => $inst_task->getVal('state'),
73     ),
74     );
75     return $inst_task->update_task($update_params);
76     }
77 softime 9293 $add = $this->ajouter($valF);
78     if ($add === false) {
79     $this->addToLog($this->msg, DEBUG_MODE);
80     return $this->end_treatment(__METHOD__, false);
81     }
82     return $this->end_treatment(__METHOD__, true);
83     }
84    
85     /**
86     * TREATMENT - update_task
87     * Met à jour l'enregistrement instancié.
88     *
89     * @param array $params Tableau des paramètres
90     * @return boolean
91     */
92     public function update_task($params = array()) {
93     $this->begin_treatment(__METHOD__);
94     $timestamp_log = $this->get_timestamp_log();
95     if ($timestamp_log === false) {
96     $this->addToLog(__('XXX'), DEBUG_MODE);
97     return $this->end_treatment(__METHOD__, false);
98     }
99     array_push($timestamp_log, array(
100     'modification_date' => date('Y-m-d H:i:s'),
101     'state' => $params['val']['state'],
102     'prev_state' => $this->getVal('state'),
103     ));
104     $timestamp_log = json_encode($timestamp_log);
105     $valF = array(
106     'task' => $this->getVal($this->clePrimaire),
107     'type' => $this->getVal('type'),
108     'timestamp_log' => $timestamp_log,
109     'state' => $params['val']['state'],
110 softime 9389 'object_id' => $this->getVal('object_id'),
111 softime 9293 );
112     $update = $this->modifier($valF);
113     if ($update === false) {
114     $this->addToLog($this->msg, DEBUG_MODE);
115     return $this->end_treatment(__METHOD__, false);
116     }
117     return $this->end_treatment(__METHOD__, true);
118     }
119    
120     /**
121     * Récupère le journal d'horodatage dans le champ timestamp_log de
122     * l'enregistrement instancié.
123     *
124     * @param array $params Tableau des paramètres
125     * @return array sinon false en cas d'erreur
126     */
127     protected function get_timestamp_log($params = array()) {
128     $val = $this->getVal('timestamp_log');
129     if ($val === '') {
130     $val = json_encode(array());
131     }
132     if($this->isJson($val) === false) {
133     return false;
134     }
135     return json_decode($val, true);
136     }
137    
138     /**
139 softime 9330 * VIEW - view_json_data
140 softime 9293 * Affiche l'enregistrement dans le format JSON.
141     *
142     * @return void
143     */
144 softime 9330 public function view_json_data() {
145 softime 9293 $this->checkAccessibility();
146 softime 9330 $this->f->disableLog();
147 softime 9298 if ($this->getParameter('idx') !== ']'
148     && $this->getParameter('idx') !== '0') {
149     //
150     $this->view_form_json();
151     }
152     else {
153     $this->view_tab_json();
154     }
155     }
156    
157     protected function view_tab_json() {
158 softime 9304 $where = '';
159     if ($this->f->get_submitted_get_value('state') !== null
160     && $this->f->get_submitted_get_value('state') !== '') {
161     //
162     $where = sprintf(' WHERE state = \'%s\' ', $this->f->get_submitted_get_value('state'));
163     }
164 softime 9298 $query = sprintf('
165     SELECT
166     *
167     FROM %1$stask
168 softime 9304 %2$s
169 softime 9298 ',
170 softime 9304 DB_PREFIXE,
171     $where
172 softime 9298 );
173     $res = $this->f->get_all_results_from_db_query($query, true);
174     if ($res['code'] === 'KO') {
175     return false;
176     }
177     $list_tasks = array();
178     foreach ($res['result'] as $task) {
179 softime 9404 $task['timestamp_log'] = json_decode($task['timestamp_log'], true);
180 softime 9298 $list_tasks[$task['task']] = $task;
181     }
182     printf(json_encode($list_tasks));
183     }
184    
185 softime 9395 protected function get_dossier_data(string $dossier) {
186     $val_di = array();
187     $inst_di = $this->f->get_inst__om_dbform(array(
188     "obj" => "dossier",
189     "idx" => $dossier,
190     ));
191 softime 9404 $val_di = $inst_di->get_json_data();
192 softime 9396 if ($val_di['dossier_instruction_type_code'] === 'T') {
193     $val_di['date_decision_transfert'] = $val_di['date_decision'];
194     }
195 softime 9395 unset($val_di['initial_dt']);
196     unset($val_di['log_instructions']);
197     return $val_di;
198     }
199    
200     protected function get_dossier_autorisation_data(string $da) {
201     $val_da = array();
202     $inst_da = $this->f->get_inst__om_dbform(array(
203     "obj" => "dossier_autorisation",
204     "idx" => $da,
205     ));
206 softime 9404 $val_da = $inst_da->get_json_data();
207 softime 9395 return $val_da;
208     }
209    
210     protected function get_donnees_techniques_data(string $fk_idx, string $fk_field) {
211     $val_dt = array();
212     $inst_dt = $this->f->get_inst__by_other_idx(array(
213     "obj" => "donnees_techniques",
214     "fk_field" => $fk_field,
215     "fk_idx" => $fk_idx,
216     ));
217     $val_dt = array(
218     'donnees_techniques' => $inst_dt->getVal($inst_dt->clePrimaire),
219     'cerfa' => $inst_dt->getVal('cerfa'),
220     );
221     $val_dt = array_merge($val_dt, $inst_dt->get_donnees_techniques_applicables());
222 softime 9396 if (isset($val_dt['am_exist_date']) === true) {
223     $val_dt['am_exist_date_num'] = '';
224     if (is_numeric($val_dt['am_exist_date']) === true) {
225     $val_dt['am_exist_date_num'] = $val_dt['am_exist_date'];
226     }
227     }
228 softime 9403 // Correspond à la nomenclature de Plat'AU STATUT_INFO
229     $val_dt['tax_statut_info'] = 'Déclaré';
230 softime 9395 return $val_dt;
231     }
232    
233     protected function get_external_uid($fk_idx, string $fk_idx_2) {
234 softime 9404 $inst_external_uid = $this->f->get_inst__by_other_idx(array(
235 softime 9395 "obj" => "lien_id_interne_uid_externe",
236     "fk_field" => 'object_id',
237     "fk_idx" => $fk_idx,
238     "fk_field_2" => 'object',
239     "fk_idx_2" => $fk_idx_2,
240     ));
241 softime 9404 return $inst_external_uid->getVal('external_uid');
242 softime 9395 }
243    
244     protected function get_demandeurs_data(string $dossier) {
245     $val_demandeur = array();
246     $inst_di = $this->f->get_inst__om_dbform(array(
247     "obj" => "dossier",
248     "idx" => $dossier,
249     ));
250     $list_demandeurs = $inst_di->get_demandeurs();
251     foreach ($list_demandeurs as $demandeur) {
252     $inst_demandeur = $this->f->get_inst__om_dbform(array(
253     "obj" => "demandeur",
254     "idx" => $demandeur['demandeur'],
255 softime 9334 ));
256 softime 9404 $val_demandeur[$demandeur['demandeur']] = $inst_demandeur->get_json_data();
257 softime 9395 $val_demandeur[$demandeur['demandeur']]['petitionnaire_principal'] = $demandeur['petitionnaire_principal'];
258 softime 9334 }
259 softime 9395 return $val_demandeur;
260     }
261    
262     protected function get_architecte_data($architecte = null) {
263     $val_architecte = array();
264     if ($architecte !== null
265     && $architecte !== '') {
266 softime 9334 //
267 softime 9395 $inst_architecte = $this->f->get_inst__om_dbform(array(
268     "obj" => "architecte",
269     "idx" => $architecte,
270 softime 9334 ));
271 softime 9404 $val_architecte = $inst_architecte->get_json_data();
272 softime 9334 }
273 softime 9395 return $val_architecte;
274     }
275 softime 9334
276 softime 9395 protected function get_instruction_data(string $dossier) {
277     $val_instruction = array();
278     $inst_di = $this->f->get_inst__om_dbform(array(
279     "obj" => "dossier",
280     "idx" => $dossier,
281     ));
282     $inst_instruction = $this->f->get_inst__om_dbform(array(
283     "obj" => "instruction",
284     "idx" => $inst_di->get_last_instruction_decision(),
285     ));
286     if (count($inst_instruction->val) > 0) {
287 softime 9404 $val_instruction = $inst_instruction->get_json_data();
288 softime 9384 }
289 softime 9395 return $val_instruction;
290     }
291 softime 9334
292 softime 9395 protected function get_document_numerise_data(string $dn) {
293     $val_dn = array();
294     $inst_dn = $this->f->get_inst__om_dbform(array(
295     "obj" => "document_numerise",
296     "idx" => $dn,
297     ));
298 softime 9404 $val_dn = $inst_dn->get_json_data();
299 softime 9395 $val_dn['path'] = sprintf('%s/%s&snippet=%s&obj=%s&champ=%s&id=%s', $_SERVER['HTTP_HOST'], 'openads/app/index.php?module=form', 'file', 'document_numerise', 'uid', $this->getVal('object_id'));
300 softime 9403 // Correspond à la nomenclature Plat'AU NATURE_PIECE
301     $val_dn['nature'] = 'Initiale';
302 softime 9395 return $val_dn;
303     }
304    
305 softime 9396 protected function get_parcelles_data(string $object, string $idx) {
306     $val_dp = array();
307     $inst_di = $this->f->get_inst__om_dbform(array(
308     "obj" => $object,
309     "idx" => $idx,
310     ));
311     $list_parcelles = $inst_di->get_parcelles();
312     $no_ordre = 1;
313     foreach ($list_parcelles as $parcelle) {
314     $val_dp[$parcelle[$object.'_parcelle']] = array(
315     $object.'_parcelle' => $parcelle[$object.'_parcelle'],
316     'libelle' => $parcelle['libelle'],
317     'no_ordre' => $no_ordre,
318     );
319     $no_ordre++;
320     }
321     return $val_dp;
322     }
323    
324 softime 9395 protected function view_form_json() {
325     // Mise à jour des valeurs
326 softime 9402 if ($this->f->get_submitted_post_value('valid') === 'true'
327     && $this->f->get_submitted_post_value('state') !== null) {
328 softime 9293 //
329     $params = array(
330     'val' => array(
331 softime 9402 'state' => $this->f->get_submitted_post_value('state')
332 softime 9293 ),
333     );
334     $update = $this->update_task($params);
335     $message_class = "valid";
336     $message = $this->msg;
337     if ($update === false) {
338     $this->addToLog($this->msg, DEBUG_MODE);
339     $message_class = "error";
340     $message = sprintf(
341     '%s %s',
342     __('Impossible de mettre à jour la tâche.'),
343     __('Veuillez contacter votre administrateur.')
344     );
345     }
346     $this->f->displayMessage($message_class, $message);
347 softime 9389 }
348 softime 9395 //
349 softime 9402 if ($this->f->get_submitted_post_value('valid') === 'true'
350     && $this->f->get_submitted_post_value('external_uid') !== null) {
351 softime 9385 //
352 softime 9389 $inst_lien = $this->f->get_inst__om_dbform(array(
353     "obj" => "lien_id_interne_uid_externe",
354     "idx" => ']',
355     ));
356     $valF = array(
357     'lien_id_interne_uid_externe' => '',
358     'object' => $this->get_lien_objet_by_type($this->getVal('type')),
359     'object_id' => $this->getVal('object_id'),
360 softime 9402 'external_uid' => $this->f->get_submitted_post_value('external_uid'),
361 softime 9389 );
362     $add = $inst_lien->ajouter($valF);
363     $message_class = "valid";
364     $message = $inst_lien->msg;
365     if ($add === false) {
366     $this->addToLog($inst_lien->msg, DEBUG_MODE);
367     $message_class = "error";
368     $message = sprintf(
369     '%s %s',
370     __("Impossible de mettre à jour le lien entre l'identifiant interne et l'identifiant de l'application externe."),
371     __('Veuillez contacter votre administrateur.')
372 softime 9385 );
373     }
374 softime 9389 $this->f->displayMessage($message_class, $message);
375 softime 9293 }
376 softime 9395
377     //
378 softime 9402 if ($this->f->get_submitted_post_value('valid') === null) {
379     // Liste des valeurs à afficher
380     $val = array();
381 softime 9395 //
382 softime 9402 $val_task = array_combine($this->champs, $this->val);
383 softime 9404 $val_task['timestamp_log'] = json_decode($val_task['timestamp_log'], true);
384 softime 9402 $val['task'] = $val_task;
385     //
386     if ($this->getVal('type') === 'creation_DA') {
387     $val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id'));
388     $val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation');
389     $val['dossier_autorisation_parcelle'] = $this->get_parcelles_data('dossier_autorisation', $val['dossier_autorisation']['dossier_autorisation']);
390     $val_external_uid = array();
391     $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier_autorisation']['dossier_autorisation'], 'dossier_autorisation');
392     $val['external_uid'] = $val_external_uid;
393     }
394     //
395     if ($this->getVal('type') === 'creation_DI'
396     || $this->getVal('type') === 'modification_DI') {
397     //
398     $val['dossier'] = $this->get_dossier_data($this->getVal('object_id'));
399     $val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_instruction');
400     $val['demandeur'] = $this->get_demandeurs_data($val['dossier']['dossier']);
401 softime 9403 $architecte = isset($val['donnees_techniques']['architecte']) === true ? $val['donnees_techniques']['architecte'] : null;
402     $val['architecte'] = $this->get_architecte_data($architecte);
403 softime 9402 $val['dossier_parcelle'] = $this->get_parcelles_data('dossier', $val['dossier']['dossier']);
404     $val_external_uid = array();
405     $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation');
406     $val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier');
407     $val['external_uid'] = $val_external_uid;
408     }
409     //
410     if ($this->getVal('type') === 'qualification_DI') {
411     $val['dossier'] = $this->get_dossier_data($this->getVal('object_id'));
412     $val['instruction'] = $this->get_instruction_data($val['dossier']['dossier']);
413     $val_external_uid = array();
414     $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation');
415     $val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier');
416     $val['external_uid'] = $val_external_uid;
417     }
418     //
419     if ($this->getVal('type') === 'ajout_piece') {
420     $val['document_numerise'] = $this->get_document_numerise_data($this->getVal('object_id'));
421     $val['dossier'] = $this->get_dossier_data($val['document_numerise']['dossier']);
422     $val_external_uid = array();
423     $val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation');
424     $val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier');
425     $val_external_uid['document_numerise'] = $this->get_external_uid($val['document_numerise']['document_numerise'], 'document_numerise');
426     $val['external_uid'] = $val_external_uid;
427     }
428    
429     // Liste des valeurs affichée en JSON
430     printf(json_encode($val));
431 softime 9395 }
432 softime 9293 }
433 softime 9385
434     protected function get_lien_objet_by_type($type) {
435     //
436     $objet = '';
437     if ($type === 'creation_DA') {
438     $objet = 'dossier_autorisation';
439     }
440 softime 9404 if ($type === 'creation_DI' || $type === 'modification_DI') {
441 softime 9385 $objet = 'dossier';
442     }
443     if ($type === 'ajout_piece') {
444     $objet = 'document_numerise';
445     }
446     return $objet;
447     }
448 softime 9293 }

Properties

Name Value
svn:executable *

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26