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 |
|
|
"identifier" => "view_json", |
19 |
|
|
"view" => "view_json", |
20 |
|
|
"permission_suffix" => "consulter", |
21 |
|
|
); |
22 |
|
|
} |
23 |
|
|
|
24 |
|
|
/** |
25 |
|
|
* TREATMENT - add_task |
26 |
|
|
* Ajoute un enregistrement. |
27 |
|
|
* |
28 |
|
|
* @param array $params Tableau des paramètres |
29 |
|
|
* @return boolean |
30 |
|
|
*/ |
31 |
|
|
public function add_task($params = array()) { |
32 |
|
|
$this->begin_treatment(__METHOD__); |
33 |
|
|
$timestamp_log = json_encode(array( |
34 |
|
|
'creation_date' => date('Y-m-d H:i:s'), |
35 |
|
|
)); |
36 |
|
|
// Mise à jour du DI |
37 |
|
|
$valF = array( |
38 |
|
|
'task' => '', |
39 |
|
|
'type' => $params['val']['type'], |
40 |
|
|
'timestamp_log' => $timestamp_log, |
41 |
|
|
'state' => 'draft', |
42 |
|
|
'id' => $params['val']['id'], |
43 |
|
|
); |
44 |
|
|
$add = $this->ajouter($valF); |
45 |
|
|
if ($add === false) { |
46 |
|
|
$this->addToLog($this->msg, DEBUG_MODE); |
47 |
|
|
return $this->end_treatment(__METHOD__, false); |
48 |
|
|
} |
49 |
|
|
return $this->end_treatment(__METHOD__, true); |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
/** |
53 |
|
|
* TREATMENT - update_task |
54 |
|
|
* Met à jour l'enregistrement instancié. |
55 |
|
|
* |
56 |
|
|
* @param array $params Tableau des paramètres |
57 |
|
|
* @return boolean |
58 |
|
|
*/ |
59 |
|
|
public function update_task($params = array()) { |
60 |
|
|
$this->begin_treatment(__METHOD__); |
61 |
|
|
$timestamp_log = $this->get_timestamp_log(); |
62 |
|
|
if ($timestamp_log === false) { |
63 |
|
|
$this->addToLog(__('XXX'), DEBUG_MODE); |
64 |
|
|
return $this->end_treatment(__METHOD__, false); |
65 |
|
|
} |
66 |
|
|
array_push($timestamp_log, array( |
67 |
|
|
'modification_date' => date('Y-m-d H:i:s'), |
68 |
|
|
'state' => $params['val']['state'], |
69 |
|
|
'prev_state' => $this->getVal('state'), |
70 |
|
|
)); |
71 |
|
|
$timestamp_log = json_encode($timestamp_log); |
72 |
|
|
$valF = array( |
73 |
|
|
'task' => $this->getVal($this->clePrimaire), |
74 |
|
|
'type' => $this->getVal('type'), |
75 |
|
|
'timestamp_log' => $timestamp_log, |
76 |
|
|
'state' => $params['val']['state'], |
77 |
|
|
'id' => $this->getVal('id'), |
78 |
|
|
); |
79 |
|
|
$update = $this->modifier($valF); |
80 |
|
|
if ($update === false) { |
81 |
|
|
$this->addToLog($this->msg, DEBUG_MODE); |
82 |
|
|
return $this->end_treatment(__METHOD__, false); |
83 |
|
|
} |
84 |
|
|
return $this->end_treatment(__METHOD__, true); |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
/** |
88 |
|
|
* Récupère le journal d'horodatage dans le champ timestamp_log de |
89 |
|
|
* l'enregistrement instancié. |
90 |
|
|
* |
91 |
|
|
* @param array $params Tableau des paramètres |
92 |
|
|
* @return array sinon false en cas d'erreur |
93 |
|
|
*/ |
94 |
|
|
protected function get_timestamp_log($params = array()) { |
95 |
|
|
$val = $this->getVal('timestamp_log'); |
96 |
|
|
if ($val === '') { |
97 |
|
|
$val = json_encode(array()); |
98 |
|
|
} |
99 |
|
|
if($this->isJson($val) === false) { |
100 |
|
|
return false; |
101 |
|
|
} |
102 |
|
|
return json_decode($val, true); |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
/** |
106 |
|
|
* VIEW - view_json |
107 |
|
|
* Affiche l'enregistrement dans le format JSON. |
108 |
|
|
* |
109 |
|
|
* @return void |
110 |
|
|
*/ |
111 |
|
|
public function view_json() { |
112 |
|
|
$this->checkAccessibility(); |
113 |
softime |
9298 |
if ($this->getParameter('idx') !== ']' |
114 |
|
|
&& $this->getParameter('idx') !== '0') { |
115 |
|
|
// |
116 |
|
|
$this->view_form_json(); |
117 |
|
|
} |
118 |
|
|
else { |
119 |
|
|
$this->view_tab_json(); |
120 |
|
|
} |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
protected function view_tab_json() { |
124 |
|
|
$query = sprintf(' |
125 |
|
|
SELECT |
126 |
|
|
* |
127 |
|
|
FROM %1$stask |
128 |
|
|
', |
129 |
|
|
DB_PREFIXE |
130 |
|
|
); |
131 |
|
|
$res = $this->f->get_all_results_from_db_query($query, true); |
132 |
|
|
if ($res['code'] === 'KO') { |
133 |
|
|
return false; |
134 |
|
|
} |
135 |
|
|
$list_tasks = array(); |
136 |
|
|
foreach ($res['result'] as $task) { |
137 |
|
|
$list_tasks[$task['task']] = $task; |
138 |
|
|
} |
139 |
|
|
printf(json_encode($list_tasks)); |
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
protected function view_form_json() { |
143 |
softime |
9293 |
$val = array_combine($this->champs, $this->val); |
144 |
|
|
printf(json_encode($val)); |
145 |
softime |
9297 |
if ($this->f->get_submitted_post_value('valid') === 'true' |
146 |
|
|
&& $this->f->get_submitted_post_value('state') !== null) { |
147 |
softime |
9293 |
// |
148 |
|
|
$params = array( |
149 |
|
|
'val' => array( |
150 |
softime |
9297 |
'state' => $this->f->get_submitted_post_value('state') |
151 |
softime |
9293 |
), |
152 |
|
|
); |
153 |
|
|
$update = $this->update_task($params); |
154 |
|
|
$message_class = "valid"; |
155 |
|
|
$message = $this->msg; |
156 |
|
|
if ($update === false) { |
157 |
|
|
$this->addToLog($this->msg, DEBUG_MODE); |
158 |
|
|
$message_class = "error"; |
159 |
|
|
$message = sprintf( |
160 |
|
|
'%s %s', |
161 |
|
|
__('Impossible de mettre à jour la tâche.'), |
162 |
|
|
__('Veuillez contacter votre administrateur.') |
163 |
|
|
); |
164 |
|
|
} |
165 |
|
|
$this->f->displayMessage($message_class, $message); |
166 |
|
|
} |
167 |
|
|
} |
168 |
|
|
} |