1 | <?php |
---|
2 | /** |
---|
3 | * Déclarations relatives à la base de données |
---|
4 | * |
---|
5 | * @plugin Contacts & Organisations pour Spip 3.0 |
---|
6 | * @license GPL (c) 2009 - 2013 |
---|
7 | * @author Cyril Marion, Matthieu Marcillaud, Rastapopoulos |
---|
8 | * |
---|
9 | * @package SPIP\Contacts\Pipelines |
---|
10 | **/ |
---|
11 | |
---|
12 | if (!defined("_ECRIRE_INC_VERSION")) return; |
---|
13 | |
---|
14 | /** |
---|
15 | * Déclarer les interfaces des tables organisations et contacts |
---|
16 | * |
---|
17 | * @pipeline declarer_tables_interfaces |
---|
18 | * |
---|
19 | * @param array $interface |
---|
20 | * Déclarations d'interface pour le compilateur |
---|
21 | * @return array |
---|
22 | * Déclarations d'interface pour le compilateur |
---|
23 | */ |
---|
24 | function contacts_declarer_tables_interfaces($interface) { |
---|
25 | |
---|
26 | $interface['table_des_tables']['annuaires'] = 'annuaires'; |
---|
27 | $interface['table_des_tables']['organisations'] = 'organisations'; |
---|
28 | $interface['table_des_tables']['organisations_liens'] = 'organisations_liens'; |
---|
29 | $interface['table_des_tables']['contacts'] = 'contacts'; |
---|
30 | $interface['table_des_tables']['contacts_liens'] = 'contacts_liens'; |
---|
31 | |
---|
32 | // -- Liaisons organisations/contacts |
---|
33 | $interface['tables_jointures']['spip_organisations_liens'][] = 'contacts'; |
---|
34 | $interface['tables_jointures']['spip_organisations_liens'][] = 'organisations'; |
---|
35 | |
---|
36 | /** |
---|
37 | * Objectif : autoriser les traitements SPIP sur certains champs texte... |
---|
38 | */ |
---|
39 | $interface['table_des_traitements']['NOM'][] = _TRAITEMENT_TYPO; |
---|
40 | $interface['table_des_traitements']['PRENOM'][] = _TRAITEMENT_TYPO; |
---|
41 | $interface['table_des_traitements']['CIVILITE'][] = _TRAITEMENT_TYPO; |
---|
42 | $interface['table_des_traitements']['FONCTION'][] = _TRAITEMENT_TYPO; |
---|
43 | $interface['table_des_traitements']['ACTIVITE'][] = _TRAITEMENT_TYPO; |
---|
44 | $interface['table_des_traitements']['OUVERTURES'][] = _TRAITEMENT_RACCOURCIS; |
---|
45 | $interface['table_des_traitements']['TARIFS'][] = _TRAITEMENT_RACCOURCIS; |
---|
46 | |
---|
47 | // Chercher plus facilement dans les annuaires avec {annuaire=truc} |
---|
48 | $interface['exceptions_des_tables']['organisations']['annuaire'] = array('spip_annuaires', 'identifiant'); |
---|
49 | $interface['exceptions_des_tables']['contacts']['annuaire'] = array('spip_annuaires', 'identifiant'); |
---|
50 | |
---|
51 | return $interface; |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | /** |
---|
56 | * Déclarer les objets éditoriaux des contacts et organisations |
---|
57 | * |
---|
58 | * @pipeline declarer_tables_objets_sql |
---|
59 | * |
---|
60 | * @param array $tables |
---|
61 | * Description des tables |
---|
62 | * @return array |
---|
63 | * Description complétée des tables |
---|
64 | */ |
---|
65 | function contacts_declarer_tables_objets_sql($tables) { |
---|
66 | //-- Table annuaires ---------------------------------------- |
---|
67 | $tables['spip_annuaires'] = array( |
---|
68 | // Caractéristiques |
---|
69 | 'principale' => 'oui', |
---|
70 | 'page' => 'annuaire', |
---|
71 | // Les champs et leurs particularités (clés etc) |
---|
72 | 'field' => array( |
---|
73 | 'id_annuaire' => "bigint(21) NOT NULL auto_increment", |
---|
74 | 'identifiant' => 'varchar(255) not null default ""', |
---|
75 | 'titre' => "text DEFAULT '' NOT NULL", |
---|
76 | 'descriptif' => "TEXT DEFAULT '' NOT NULL", |
---|
77 | 'maj' => "TIMESTAMP" |
---|
78 | ), |
---|
79 | 'key' => array( |
---|
80 | "PRIMARY KEY" => "id_annuaire", |
---|
81 | 'KEY identifiant' => 'identifiant', |
---|
82 | ), |
---|
83 | 'join' => array( |
---|
84 | "id_annuaire" => "id_annuaire", |
---|
85 | ), |
---|
86 | 'titre' => 'titre, "" AS lang', |
---|
87 | 'champs_editables' => array('identifiant', 'titre', 'descriptif'), |
---|
88 | 'champs_versionnes' => array('identifiant', 'titre', 'descriptif'), |
---|
89 | 'rechercher_champs' => array( |
---|
90 | 'identifiant' => 8, 'titre' => 8, 'descriptif' => 4, |
---|
91 | ), |
---|
92 | 'tables_jointures' => array( |
---|
93 | 'contacts', |
---|
94 | 'organisations', |
---|
95 | ), |
---|
96 | // Chaînes de langue explicite |
---|
97 | 'texte_objets' => 'contacts:annuaires', |
---|
98 | 'texte_objet' => 'contacts:annuaire', |
---|
99 | 'texte_modifier' => 'contacts:annuaire_editer', |
---|
100 | 'texte_creer' => 'contacts:annuaire_creer', |
---|
101 | 'texte_creer_associer' => 'contacts:annuaire_creer_associer', |
---|
102 | 'texte_ajouter' => 'contacts:annuaire_ajouter', |
---|
103 | 'texte_logo_objet' => 'contacts:annuaire_logo', |
---|
104 | 'info_aucun_objet' => 'contacts:annuaire_aucun', |
---|
105 | 'info_1_objet' => 'contacts:annuaire_un', |
---|
106 | 'info_nb_objets' => 'contacts:annuaires_nb', |
---|
107 | ); |
---|
108 | |
---|
109 | //-- Table organisations ---------------------------------------- |
---|
110 | $tables['spip_organisations'] = array( |
---|
111 | 'page' => 'organisation', |
---|
112 | 'texte_objets' => 'contacts:organisations', |
---|
113 | 'texte_objet' => 'contacts:organisation', |
---|
114 | 'texte_modifier' => 'contacts:organisation_editer', |
---|
115 | 'texte_creer' => 'contacts:organisation_creer', |
---|
116 | 'texte_creer_enfant' => 'contacts:organisation_creer_fille', |
---|
117 | 'texte_creer_associer' => 'contacts:organisation_creer_associer', |
---|
118 | 'texte_ajouter' => 'contacts:organisation_ajouter', |
---|
119 | 'texte_logo_objet' => 'contacts:organisation_logo', |
---|
120 | 'info_aucun_objet' => 'contacts:organisation_aucun', |
---|
121 | 'info_1_objet' => 'contacts:organisation_un', |
---|
122 | 'info_nb_objets' => 'contacts:organisations_nb', |
---|
123 | 'titre' => 'nom AS titre, "" AS lang', |
---|
124 | 'date' => 'date_creation', |
---|
125 | 'principale' => 'oui', |
---|
126 | 'champs_editables' => array( |
---|
127 | 'id_parent', 'id_auteur', 'id_annuaire', |
---|
128 | 'nom', 'statut_juridique', 'identification', 'activite', |
---|
129 | 'date_creation', 'descriptif', 'ouvertures', 'tarifs', 'url_site'), |
---|
130 | 'field' => array( |
---|
131 | "id_organisation" => "bigint(21) NOT NULL auto_increment", |
---|
132 | 'id_annuaire' => 'bigint(21) NOT NULL default 0', |
---|
133 | "id_parent" => "bigint(21) NOT NULL default 0", |
---|
134 | "id_auteur" => "bigint(21) NOT NULL default 0", |
---|
135 | "nom" => "tinytext DEFAULT '' NOT NULL", |
---|
136 | "statut_juridique" => "tinytext DEFAULT '' NOT NULL", // forme juridique : SA, SARL, association, etc. |
---|
137 | "identification" => "tinytext DEFAULT '' NOT NULL", // N° d'identification : SIRET, SIREN, N° TVA... |
---|
138 | "activite" => "tinytext DEFAULT '' NOT NULL", // Secteur d'activité : humanitaire, formation... |
---|
139 | "date_creation" => "datetime NOT NULL default '0000-00-00 00:00:00'", |
---|
140 | "descriptif" => "TEXT DEFAULT '' NOT NULL", |
---|
141 | "ouvertures" => "text not null default ''", |
---|
142 | "tarifs" => "text not null default ''", |
---|
143 | "url_site" => "text not null default ''", |
---|
144 | "maj" => "TIMESTAMP", |
---|
145 | ), |
---|
146 | 'key' => array( |
---|
147 | "PRIMARY KEY" => "id_organisation", |
---|
148 | "KEY id_auteur" => "id_auteur", |
---|
149 | 'KEY id_annuaire' => 'id_annuaire', |
---|
150 | ), |
---|
151 | 'join' => array( |
---|
152 | "id_organisation" => "id_organisation", |
---|
153 | "id_auteur" => "id_auteur", |
---|
154 | 'id_annuaire' => 'id_annuaire', |
---|
155 | ), |
---|
156 | 'tables_jointures' => array( |
---|
157 | 'auteurs', 'annuaires', 'organisations_liens' |
---|
158 | ), |
---|
159 | 'rechercher_champs' => array( |
---|
160 | 'id_organisation' => 12, 'nom' => 8, 'descriptif' => 4, 'activite' => 4, 'statut_juridique' => 2, 'ouvertures' => 1, 'tarifs' => 1, |
---|
161 | ), |
---|
162 | /* |
---|
163 | 'rechercher_jointures' => array( |
---|
164 | 'auteur' => array('nom' => 2, 'bio' => 1) |
---|
165 | ),*/ |
---|
166 | 'champs_versionnes' => array( |
---|
167 | 'id_parent', 'id_auteur', 'id_annuaire', |
---|
168 | 'nom', 'descriptif', 'identification', 'statut_juridique', |
---|
169 | 'activite', 'date_creation', 'ouvertures', 'tarifs', 'url_site' |
---|
170 | ), |
---|
171 | 'parent' => array( |
---|
172 | array('condition' => 'id_parent=0', 'type' => 'annuaire', 'champ' => 'id_annuaire'), |
---|
173 | array('condition' => 'id_parent>0', 'type' => 'organisation', 'champ' => 'id_parent'), |
---|
174 | ), |
---|
175 | ); |
---|
176 | |
---|
177 | |
---|
178 | |
---|
179 | //-- Table contacts ---------------------------------------- |
---|
180 | $tables['spip_contacts'] = array( |
---|
181 | 'page' => 'contact', |
---|
182 | 'texte_objets' => 'contacts:contacts', |
---|
183 | 'texte_objet' => 'contacts:contact', |
---|
184 | 'texte_modifier' => 'contacts:contact_editer', |
---|
185 | 'texte_creer' => 'contacts:contact_creer', |
---|
186 | 'texte_creer_associer' => 'contacts:contact_creer_associer', |
---|
187 | 'texte_ajouter' => 'contacts:contact_ajouter', |
---|
188 | 'texte_logo_objet' => 'contacts:contact_logo', |
---|
189 | 'info_aucun_objet' => 'contacts:contact_aucun', |
---|
190 | 'info_1_objet' => 'contacts:contact_un', |
---|
191 | 'info_nb_objets' => 'contacts:contacts_nb', |
---|
192 | 'titre' => '"" as lang, trim(concat(prenom, \' \', nom)) AS titre', |
---|
193 | 'date' => 'date_naissance', |
---|
194 | 'principale' => 'oui', |
---|
195 | 'champs_editables' => array( |
---|
196 | 'id_auteur', 'id_annuaire', 'civilite', 'nom', 'prenom', 'fonction', |
---|
197 | 'date_naissance', 'descriptif'), |
---|
198 | 'field' => array( |
---|
199 | "id_contact" => "bigint(21) NOT NULL auto_increment", |
---|
200 | 'id_annuaire' => 'bigint(21) NOT NULL default 0', |
---|
201 | "id_auteur" => "bigint(21) NOT NULL default 0", |
---|
202 | "civilite" => "tinytext DEFAULT '' NOT NULL", |
---|
203 | "nom" => "tinytext DEFAULT '' NOT NULL", |
---|
204 | "prenom" => "tinytext NOT NULL DEFAULT ''", |
---|
205 | "fonction" => "tinytext DEFAULT '' NOT NULL", // gérant, membre, trésorier, etc. |
---|
206 | "date_naissance" => "datetime NOT NULL default '0000-00-00 00:00:00'", |
---|
207 | "descriptif" => "text DEFAULT '' NOT NULL", |
---|
208 | "maj" => "TIMESTAMP" |
---|
209 | ), |
---|
210 | 'key' => array( |
---|
211 | "PRIMARY KEY" => "id_contact", |
---|
212 | "KEY id_auteur" => "id_auteur", |
---|
213 | 'KEY id_annuaire' => 'id_annuaire', |
---|
214 | ), |
---|
215 | 'join' => array( |
---|
216 | "id_contact" => "id_contact", |
---|
217 | "id_auteur" => "id_auteur", |
---|
218 | 'id_annuaire' => 'id_annuaire', |
---|
219 | ), |
---|
220 | 'tables_jointures' => array( |
---|
221 | 'auteurs', 'annuaires', 'organisations_liens', 'contacts_liens' |
---|
222 | ), |
---|
223 | 'rechercher_champs' => array( |
---|
224 | 'id_contact' => 12, 'nom' => 8, 'prenom' => 2, 'descriptif' => 4, 'fonction' => 2, |
---|
225 | ), |
---|
226 | /* |
---|
227 | 'rechercher_jointures' => array( |
---|
228 | 'auteur' => array('nom' => 2, 'bio' => 1) |
---|
229 | ),*/ |
---|
230 | 'champs_versionnes' => array( |
---|
231 | 'id_auteur', 'id_annuaire', 'civilite', 'nom', 'prenom', 'fonction', |
---|
232 | 'date_naissance', 'descriptif' |
---|
233 | ), |
---|
234 | ); |
---|
235 | |
---|
236 | //-- Jointures ---------------------------------------------------- |
---|
237 | $tables['spip_auteurs']['tables_jointures'][] = 'contacts'; |
---|
238 | $tables['spip_auteurs']['tables_jointures'][] = 'organisations'; |
---|
239 | |
---|
240 | return $tables; |
---|
241 | } |
---|
242 | |
---|
243 | |
---|
244 | |
---|
245 | /** |
---|
246 | * Déclarer les tables auxiliaires des contacts et organisations |
---|
247 | * |
---|
248 | * @pipeline declarer_tables_auxiliaires |
---|
249 | * |
---|
250 | * @param array $tables_auxiliaires |
---|
251 | * Description des tables |
---|
252 | * @return array |
---|
253 | * Description complétée des tables |
---|
254 | */ |
---|
255 | function contacts_declarer_tables_auxiliaires($tables_auxiliaires) { |
---|
256 | |
---|
257 | //-- Table organisations_liens ------------------------------------- |
---|
258 | $organisations_liens = array( |
---|
259 | "id_organisation" => "BIGINT(21) NOT NULL", |
---|
260 | "id_objet" => "BIGINT(21) NOT NULL", |
---|
261 | "objet" => "VARCHAR(25) NOT NULL", |
---|
262 | "type_liaison" => "VARCHAR(25) NOT NULL DEFAULT ''", |
---|
263 | ); |
---|
264 | $organisations_liens_key = array( |
---|
265 | "PRIMARY KEY" => "id_organisation, id_objet, objet, type_liaison", |
---|
266 | "KEY id_organisation" => "id_organisation", |
---|
267 | "KEY id_objet" => "id_objet", |
---|
268 | "KEY objet" => "objet" |
---|
269 | ); |
---|
270 | $tables_auxiliaires['spip_organisations_liens'] = |
---|
271 | array('field' => &$organisations_liens, 'key' => &$organisations_liens_key); |
---|
272 | |
---|
273 | |
---|
274 | //-- Table contacts_liens ------------------------------------- |
---|
275 | $contacts_liens = array( |
---|
276 | "id_contact" => "BIGINT(21) NOT NULL", |
---|
277 | "id_objet" => "BIGINT(21) NOT NULL", |
---|
278 | "objet" => "VARCHAR(25) NOT NULL", |
---|
279 | "type_liaison" => "VARCHAR(25) NOT NULL DEFAULT ''", |
---|
280 | ); |
---|
281 | $contacts_liens_key = array( |
---|
282 | "PRIMARY KEY" => "id_contact, id_objet, objet, type_liaison", |
---|
283 | "KEY id_contact" => "id_contact", |
---|
284 | "KEY id_objet" => "id_objet", |
---|
285 | "KEY objet" => "objet" |
---|
286 | ); |
---|
287 | $tables_auxiliaires['spip_contacts_liens'] = |
---|
288 | array('field' => &$contacts_liens, 'key' => &$contacts_liens_key); |
---|
289 | |
---|
290 | return $tables_auxiliaires; |
---|
291 | } |
---|