1 |
gmalvolti |
15752 |
<?php |
2 |
|
|
//$Id$ |
3 |
|
|
//gen openMairie le 20/09/2023 16:22 |
4 |
|
|
|
5 |
|
|
require_once "../gen/obj/enjeux.class.php"; |
6 |
|
|
|
7 |
|
|
class enjeux extends enjeux_gen { |
8 |
|
|
|
9 |
|
|
/** |
10 |
|
|
* Liaison NaN |
11 |
|
|
* |
12 |
|
|
* Tableau contenant les objets qui représente les liaisons. |
13 |
|
|
*/ |
14 |
|
|
var $liaisons_nan = array( |
15 |
|
|
"lien_enjeux_om_collectivite" => array( |
16 |
|
|
"table_l" => "lien_enjeux_om_collectivite", |
17 |
|
|
"table_f" => "om_collectivite", |
18 |
|
|
"field" => "om_collectivite", |
19 |
|
|
), |
20 |
|
|
"lien_enjeux_dossier_instruction_type" => array( |
21 |
|
|
"table_l" => "lien_enjeux_dossier_instruction_type", |
22 |
|
|
"table_f" => "dossier_instruction_type", |
23 |
|
|
"field" => "dossier_instruction_type", |
24 |
|
|
), |
25 |
|
|
); |
26 |
|
|
|
27 |
|
|
function setType(&$form, $maj) { |
28 |
|
|
parent::setType($form, $maj); |
29 |
|
|
// Récupération du mode de l'action |
30 |
|
|
$crud = $this->get_action_crud($maj); |
31 |
|
|
|
32 |
|
|
// MODE AJOUTER / MODIFIER |
33 |
|
|
if ($maj == 0 || $maj == 1) { |
34 |
cgarcin |
15853 |
$form->setType("couleur", "color"); |
35 |
gmalvolti |
15752 |
$form->setType('om_collectivite','select_multiple'); |
36 |
|
|
$form->setType('dossier_instruction_type','select_multiple'); |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
// MODE SUPPRIMER / CONSULTER |
40 |
|
|
if ($maj == 2 || $maj == 3) { |
41 |
|
|
$form->setType('om_collectivite','select_multiple_static'); |
42 |
|
|
$form->setType('dossier_instruction_type','select_multiple_static'); |
43 |
|
|
} |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
/** |
47 |
|
|
* Clause where pour la requête de sélection des données de l'enregistrement. |
48 |
|
|
* |
49 |
|
|
* @return string |
50 |
|
|
*/ |
51 |
|
|
function get_var_sql_forminc__selection() { |
52 |
|
|
return " GROUP BY enjeux.enjeux "; |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
/** |
56 |
|
|
* |
57 |
|
|
* @return array |
58 |
|
|
*/ |
59 |
|
|
function get_var_sql_forminc__champs() { |
60 |
|
|
return array( |
61 |
|
|
"enjeux.enjeux", |
62 |
|
|
"enjeux.libelle", |
63 |
|
|
"couleur", |
64 |
cgarcin |
15937 |
"priorite", |
65 |
gmalvolti |
15752 |
"array_to_string(array_agg(distinct(om_collectivite) ORDER BY om_collectivite), ';') as om_collectivite", |
66 |
|
|
"array_to_string(array_agg(distinct(dossier_instruction_type) ORDER BY dossier_instruction_type), ';') as dossier_instruction_type", |
67 |
|
|
); |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
/** |
71 |
|
|
* SETTER_FORM - setLib |
72 |
|
|
* |
73 |
|
|
* @return void |
74 |
|
|
*/ |
75 |
|
|
function setLib(&$form, $maj) { |
76 |
|
|
parent::setLib($form, $maj); |
77 |
|
|
// |
78 |
softime |
15963 |
$form->setLib('enjeux', __('enjeu')); |
79 |
gmalvolti |
15752 |
$form->setLib('om_collectivite', __('om_collectivite')); |
80 |
|
|
$form->setLib('dossier_instruction_type', __('dossier_instruction_type')); |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
/** |
84 |
|
|
* SETTER_FORM - setTaille |
85 |
|
|
* |
86 |
|
|
* @return void |
87 |
|
|
*/ |
88 |
|
|
function setTaille(&$form, $maj) { |
89 |
|
|
// |
90 |
|
|
parent::setTaille($form, $maj); |
91 |
|
|
// |
92 |
|
|
$form->setTaille("om_collectivite", 10); |
93 |
|
|
$form->setTaille("dossier_instruction_type", 11); |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
/** |
97 |
|
|
* SETTER_FORM - setMax |
98 |
|
|
* |
99 |
|
|
* @return void |
100 |
|
|
*/ |
101 |
|
|
function setMax(&$form, $maj) { |
102 |
|
|
// |
103 |
|
|
parent::setMax($form, $maj); |
104 |
|
|
// |
105 |
|
|
$form->setMax("om_collectivite", 5); |
106 |
|
|
$form->setMax("dossier_instruction_type", 11); |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
/** |
110 |
|
|
* Clause from pour la requête de sélection des données de l'enregistrement. |
111 |
|
|
* |
112 |
|
|
* @return string |
113 |
|
|
*/ |
114 |
|
|
function get_var_sql_forminc__tableSelect() { |
115 |
|
|
return sprintf( |
116 |
|
|
'%1$s%2$s |
117 |
|
|
LEFT JOIN %1$slien_enjeux_om_collectivite |
118 |
|
|
ON lien_enjeux_om_collectivite.enjeux=enjeux.enjeux |
119 |
|
|
LEFT JOIN %1$slien_enjeux_dossier_instruction_type |
120 |
|
|
ON lien_enjeux_dossier_instruction_type.enjeux=enjeux.enjeux', |
121 |
|
|
DB_PREFIXE, |
122 |
|
|
$this->table |
123 |
|
|
); |
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
/** |
127 |
|
|
* |
128 |
|
|
* @return string |
129 |
|
|
*/ |
130 |
|
|
function get_var_sql_forminc__sql_om_collectivite() { |
131 |
|
|
return "SELECT |
132 |
|
|
om_collectivite.om_collectivite, |
133 |
|
|
CONCAT(om_collectivite.libelle) as lib |
134 |
|
|
FROM ".DB_PREFIXE."om_collectivite |
135 |
|
|
ORDER BY om_collectivite.libelle"; |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
/** |
139 |
|
|
* |
140 |
|
|
* @return string |
141 |
|
|
*/ |
142 |
|
|
function get_var_sql_forminc__sql_om_collectivite_by_id() { |
143 |
|
|
return "SELECT |
144 |
|
|
om_collectivite.om_collectivite, |
145 |
|
|
CONCAT(om_collectivite.libelle) as lib |
146 |
|
|
FROM ".DB_PREFIXE."om_collectivite |
147 |
|
|
WHERE om_collectivite IN (<idx>) |
148 |
|
|
ORDER BY om_collectivite.libelle"; |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
/** |
152 |
|
|
* |
153 |
|
|
* @return string |
154 |
|
|
*/ |
155 |
|
|
function get_var_sql_forminc__sql_dossier_instruction_type() { |
156 |
|
|
return "SELECT |
157 |
|
|
dossier_instruction_type.dossier_instruction_type, |
158 |
|
|
CONCAT(dossier_autorisation_type_detaille.code,' - ',dossier_instruction_type.code,' - ',dossier_instruction_type.libelle) as lib |
159 |
|
|
FROM ".DB_PREFIXE."dossier_instruction_type |
160 |
|
|
LEFT JOIN ".DB_PREFIXE."dossier_autorisation_type_detaille |
161 |
|
|
ON dossier_instruction_type.dossier_autorisation_type_detaille=dossier_autorisation_type_detaille.dossier_autorisation_type_detaille |
162 |
|
|
ORDER BY dossier_autorisation_type_detaille.code"; |
163 |
|
|
} |
164 |
|
|
|
165 |
|
|
/** |
166 |
|
|
* |
167 |
|
|
* @return string |
168 |
|
|
*/ |
169 |
|
|
function get_var_sql_forminc__sql_dossier_instruction_type_by_id() { |
170 |
|
|
return "SELECT |
171 |
|
|
dossier_instruction_type.dossier_instruction_type, |
172 |
|
|
CONCAT(dossier_autorisation_type_detaille.code,' - ',dossier_instruction_type.code,' - ',dossier_instruction_type.libelle) as lib |
173 |
|
|
FROM ".DB_PREFIXE."dossier_instruction_type |
174 |
|
|
LEFT JOIN ".DB_PREFIXE."dossier_autorisation_type_detaille |
175 |
|
|
ON dossier_instruction_type.dossier_autorisation_type_detaille=dossier_autorisation_type_detaille.dossier_autorisation_type_detaille |
176 |
|
|
WHERE dossier_instruction_type IN (<idx>) |
177 |
|
|
ORDER BY dossier_autorisation_type_detaille.code"; |
178 |
|
|
} |
179 |
|
|
|
180 |
|
|
/** |
181 |
|
|
* SETTER_FORM - setSelect. |
182 |
|
|
* |
183 |
|
|
* @return void |
184 |
|
|
*/ |
185 |
|
|
function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) { |
186 |
|
|
parent::setSelect($form, $maj); |
187 |
|
|
|
188 |
|
|
// Initialisation du selecteur multiple om_collectivite |
189 |
|
|
$this->init_select( |
190 |
|
|
$form, |
191 |
|
|
$this->f->db, |
192 |
|
|
$maj, |
193 |
|
|
null, |
194 |
|
|
"om_collectivite", |
195 |
|
|
$this->get_var_sql_forminc__sql("om_collectivite"), |
196 |
|
|
$this->get_var_sql_forminc__sql("om_collectivite_by_id"), |
197 |
|
|
false, |
198 |
|
|
true |
199 |
|
|
); |
200 |
|
|
|
201 |
|
|
// Initialisation du selecteur multiple dossier_instruction_type |
202 |
|
|
$this->init_select( |
203 |
|
|
$form, |
204 |
|
|
$this->f->db, |
205 |
|
|
$maj, |
206 |
|
|
null, |
207 |
|
|
"dossier_instruction_type", |
208 |
|
|
$this->get_var_sql_forminc__sql("dossier_instruction_type"), |
209 |
|
|
$this->get_var_sql_forminc__sql("dossier_instruction_type_by_id"), |
210 |
|
|
false, |
211 |
|
|
true |
212 |
|
|
); |
213 |
|
|
} |
214 |
|
|
|
215 |
|
|
/** |
216 |
|
|
* TRIGGER - triggerajouterapres. |
217 |
|
|
* |
218 |
|
|
* - ... |
219 |
|
|
* - Ajoute autant de lien_dossier_instruction_type_evenement que de dossier_instruction_type |
220 |
|
|
* - ... |
221 |
|
|
* |
222 |
|
|
* @return boolean |
223 |
|
|
*/ |
224 |
|
|
function triggerajouterapres($id, &$dnu1 = null, $val = array(), $dnu2 = null) { |
225 |
|
|
$this->addToLog(__METHOD__."(): start", EXTRA_VERBOSE_MODE); |
226 |
|
|
parent::triggerajouterapres($id, $dnu1, $val); |
227 |
|
|
|
228 |
|
|
// Liaison NaN |
229 |
|
|
foreach ($this->liaisons_nan as $liaison_nan) { |
230 |
|
|
// Si le champ possède une valeur |
231 |
|
|
if (isset($val[$liaison_nan["field"]]) === true) { |
232 |
|
|
// Ajout des liaisons table Nan |
233 |
|
|
$nb_liens = $this->ajouter_liaisons_table_nan( |
234 |
|
|
$liaison_nan["table_l"], |
235 |
|
|
$liaison_nan["table_f"], |
236 |
|
|
$liaison_nan["field"], |
237 |
|
|
$val[$liaison_nan["field"]] |
238 |
|
|
); |
239 |
|
|
// Message de confirmation |
240 |
|
|
if ($nb_liens > 0) { |
241 |
|
|
if ($nb_liens == 1) { |
242 |
|
|
$this->addToMessage(sprintf(__("Création d'une nouvelle liaison réalisee avec succès."))); |
243 |
|
|
} else { |
244 |
|
|
$this->addToMessage(sprintf(__("Création de %s nouvelles liaisons réalisée avec succès."), $nb_liens)); |
245 |
|
|
} |
246 |
|
|
} |
247 |
|
|
} |
248 |
|
|
} |
249 |
|
|
|
250 |
|
|
return true; |
251 |
|
|
} |
252 |
|
|
|
253 |
|
|
/** |
254 |
|
|
* TRIGGER - triggermodifierapres. |
255 |
|
|
* |
256 |
|
|
* @return boolean |
257 |
|
|
*/ |
258 |
|
|
function triggermodifierapres($id, &$dnu1 = null, $val = array(), $dnu2 = null) { |
259 |
|
|
$this->addToLog(__METHOD__."(): start", EXTRA_VERBOSE_MODE); |
260 |
|
|
|
261 |
|
|
// Liaisons NaN |
262 |
|
|
foreach ($this->liaisons_nan as $liaison_nan) { |
263 |
|
|
// Suppression des liaisons table NaN |
264 |
|
|
$this->supprimer_liaisons_table_nan($liaison_nan["table_l"]); |
265 |
|
|
// Ajout des liaisons table Nan |
266 |
|
|
$nb_liens = $this->ajouter_liaisons_table_nan( |
267 |
|
|
$liaison_nan["table_l"], |
268 |
|
|
$liaison_nan["table_f"], |
269 |
|
|
$liaison_nan["field"], |
270 |
|
|
$val[$liaison_nan["field"]] |
271 |
|
|
); |
272 |
|
|
// Message de confirmation |
273 |
|
|
if ($nb_liens > 0) { |
274 |
|
|
$this->addToMessage(__("Mise à jour des liaisons realisée avec succès.")); |
275 |
|
|
} |
276 |
|
|
} |
277 |
|
|
} |
278 |
|
|
|
279 |
|
|
|
280 |
|
|
/** |
281 |
|
|
* Surcharge de la méthode rechercheTable pour éviter de court-circuiter le |
282 |
|
|
* générateur en devant surcharger la méthode cleSecondaire afin de supprimer |
283 |
|
|
* les éléments liés dans les tables NaN. |
284 |
|
|
* |
285 |
|
|
* @param [type] $dnu1 Instance BDD - À ne pas utiliser |
286 |
|
|
* @param [type] $table Table |
287 |
|
|
* @param [type] $field Champ |
288 |
|
|
* @param [type] $id Identifiant |
289 |
|
|
* @param [type] $dnu2 Marqueur de débogage - À ne pas utiliser |
290 |
|
|
* @param string $selection Condition de la requête |
291 |
|
|
* |
292 |
|
|
* @return [type] [description] |
293 |
|
|
*/ |
294 |
|
|
function rechercheTable(&$dnu1 = null, $table = "", $field = "", $id = null, $dnu2 = null, $selection = "") { |
295 |
|
|
// |
296 |
|
|
if (in_array($table, array_keys($this->liaisons_nan))) { |
297 |
|
|
// |
298 |
|
|
$this->addToLog(__METHOD__."(): On ne vérifie pas la table ".$table." car liaison nan.", EXTRA_VERBOSE_MODE); |
299 |
|
|
return; |
300 |
|
|
} |
301 |
|
|
// |
302 |
|
|
parent::rechercheTable($this->f->db, $table, $field, $id, null, $selection); |
303 |
|
|
} |
304 |
|
|
|
305 |
|
|
/** |
306 |
|
|
* TRIGGER - triggersupprimer. |
307 |
|
|
* |
308 |
|
|
* @return boolean |
309 |
|
|
*/ |
310 |
|
|
function triggersupprimer($id, &$dnu1 = null, $val = array(), $dnu2 = null) { |
311 |
|
|
$this->addToLog(__METHOD__."(): start", EXTRA_VERBOSE_MODE); |
312 |
|
|
parent::triggersupprimer($id, $dnu1, $val); |
313 |
|
|
// Liaisons NaN |
314 |
|
|
foreach ($this->liaisons_nan as $liaison_nan) { |
315 |
|
|
// Suppression des liaisons table NaN |
316 |
|
|
$this->supprimer_liaisons_table_nan($liaison_nan["table_l"]); |
317 |
|
|
} |
318 |
|
|
|
319 |
|
|
return true; |
320 |
|
|
} |
321 |
|
|
|
322 |
|
|
} |