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