declarer_tables_interfaces

This pipeline is used to declare information relating to SQL tables or for certain fields in those tables. It makes it possible to supplement the information provided by ecrire/public/interfaces.php

The function accepts a parameter which is the array of declared elements, often called $interface, which must also be returned as output from the function. This array consists of the various elements, each of which are also arrays:

table_des_tables declares the alias names of SQL tables,

exceptions_des_tables assigns aliases to SQL columns for a given table,

table_titre specifies the SQL column of an object used to define the title for certain types of URL naming conventions,

table_date specifies an SQL data type column for a given SQL table which can be used for certain specific selection criteria (age, age_relatif, ...),

tables_jointures defines the possible joins between SQL tables,

exceptions_des_jointures creates aliases for SQL columns resulting from a join,

table_des_traitements specifies filters to be systematically applied on SPIP tags.

table_des_tables

Declares alias names for SQL tables, relating to the declaration provided in either the principal or join tables.

In general, any plugin offering a new editorial object also declares an identical alias as the object name. This makes it possible to write loops like <BOUCLEx(NAME)>, in exactly the same way as <BOUCLEx(spip_name)> (which simply specifies the name of the SQL table).

table_titre

Specifies which field will be used to generate the titles for certain URL naming conventions (propre, arborescent...). The character string passed is an SQL selection declaration (SELECT), which must return 2 columns as output (or the SQL column alias(s)) : "title" and "lang". When the object has no corresponding "lang" field, then it must return '' AS lang instead.

$interface['table_titre']['alias']="title_column AS titre, lang_column AS lang";

Whenever an object has declared its title, the URL generator can then create meaningful URL’s automatically (depending on the URL naming convention chosen for the web site).

table_date

This information is used to declare certain SQL columns as date type fields. The SPIP compiler can then apply certain kinds of criteria to these fields, such as "age", "age_relatif", "jour_relatif"... Only one single date type field can be declared for any given table.

tables_jointures

These declarations are used by the compiler to explicitly determine the possible joins whenever a loop on a table requests an unknown field (tag or criteria).

The compiler knows implicitly how to make certain joins (without declaring them) by looking for the column requested in the other SQL tables that it knows about. The compiler does not search through all tables, but only in those that have specific columns in common:

same name as the primary key,

same name as a column declared as a potential join in its join description in the principal or join tables.

In many cases, it is useful and preferable to explicitly declare to the compiler which joins that it can try to make when it is presented with an unknown field in a table. That is the explicit purpose of these kinds of declaration. The order of the declarations is sometimes important, since it will effect which join the compiler will find when it looks for the field in another table. Even if the field sought after would be found declared for the table anyway.

$interface['tables_jointures']['spip_nom'][]='other_table';

$interface['tables_jointures']['spip_nom']['column']='other_table';

// examples

// {id_mot} for ARTICLES

$interface['tables_jointures']['spip_articles'][]='mots_articles';

$interface['tables_jointures']['spip_articles'][]='mots';

// event joins (for the plugin agenda) on keywords or articles

$interface['tables_jointures']['spip_evenements'][]='mots';// inserted before the articles join

Most of the time, by also using the "exceptions_des_jointures" description explained below, it will be sufficient for a SPIP loop to know how to calculate the joins that it will need to display the various tags requested. If that is not always sufficient, don’t forget that joins can also be specified in the loops and criteria themselves (cf. Forcing joins).

exceptions_des_jointures

This definition is used to assign a column alias that creates a join with another table to retrieve another field, so long as the join is possible. It’s a bit like the "exception_des_tables" which declare a join, but is not specific to a given table. We can then use this alias as a SPIP tag or as a loop criteria.

Note that when we use these joins only as loop criteria like {titre_mots=xx}, it is preferable to write this as {mots.titre=xx}, which is a more generic style and does not require a declaration.

One special scenario also exists: a third argument can be provided that contains the name of the function which will create the join. This is a rare circumstance, one use of which is employed by the "Forms & Tables" plugin

An example which is often very useful is the automatic deletion of the numbers used as prefixes in section titles. This can be implemented using this method in the config/mes_options.php file (or by using this pipeline in a plugin, of course!) :

Example

Take the complex example of the Agenda plugin, which declares a table called spip_evenements(events), a linkage table called spip_mots_evenenents (keyword events) and a second linkage table called spip_evenements_participants (event participants).

An alias is defined to loop over the events. Explicit joins are declared, along with a date field and special processes. It uses nearly all of the features defined above!

function agenda_declarer_tables_interfaces($interface){

// 'spip_' dans l'index de $tables_principales

$interface['table_des_tables']['evenements']='evenements';

//-- Joins ----------------------------------------------------

$interface['tables_jointures']['spip_evenements'][]='mots';// to be inserted before the join on articles