Exemple d'implémentation : Un espace de téléchargement de documents
Un article de ReaxiaWiki.
Dans cet exemple, l'espace de téléchargement de documents à créer sera une page présentant une liste de fichiers classés. Les contributeurs pourront ajouter, supprimer des fichiers et rédiger leur description.
Sommaire |
Création du type Reaxia
Notre liste de fichiers est un contenu structuré, qui s'appellera "Fichiers". Elle peut être représentée par les champs du tableau suivant :
| Information | Type de champ |
|---|---|
| Fichier | Fichier à télécharger |
| Description | Texte de paragraphe |
| Catégorie | Catégorie |
Ajout d'un contenu
Après avoir créé le type, il faut ajouter au site un contenu dont le type est "Fichiers". Dans la colonne "Contenu du site", à gauche, cliquez sur l'icône "Ajouter un contenu" puis choisissez le type "Fichiers".
Mise en place du mot-clé
A présent, il faut ajouter le mot-clé [[TELECHARGEMENTS]] dans un champ paragraphe d'un contenu structuré :
Pour que le contributeur ait une description de ce mot-clé dans la liste des mots-clés, il faut ajouter une ligne dans le fichier reaxia_conf/Reaxia_Conf.php :
$GLOBALS['conf']['keywords']['TELECHARGEMENTS'] = "Affiche la liste des fichiers à télécharger";
Interprétation du mot-clé
Le code suivant est à ajouter dans la librairie traitant l'affichage des pages du site.
$textBefore = '';
$textAfter = '';
if (FindKeyword($Texte_de_la_page, '[[TELECHARGEMENTS]]', $textBefore, $textAfter))
{
$Texte_de_la_page = $textBefore;
$Texte_de_la_page .= display_thread('fichiers', 'files_list', array('return' => true));
$Texte_de_la_page .= $textAfter;
}
Librairie d'affichage
Voici le code de le librairie chargée d'afficher la liste des fichiers à télécharger, à enregistrer dans le fichier reaxia_lib/files_list/files_list.php :
<?php
class files_list extends thread_displayer
{
/**
* @param array $thread array with threadname, display_name, categories, PublishedTime
* @param array $options
*/
function files_list($threadname, &$options)
{
// Call the parent's constructor, initializes the class members
$this->thread_displayer($threadname, $options);
// Override any of thread_displayer's class members here:
}
/**
* Specify the SQL query who returns blocs
* @return string the SQL statement that fetches the data
*/
function GetSQLQuery()
{
if ($this->UsePreviewData)
$rxp = '_rxp';
else
$rxp = '';
$sql = 'SELECT * FROM `' . $this->threadRef . $rxp . '`';
$sql .= ' ORDER BY file_download_1_description ASC';
return $sql;
}
/**
* Does whatever needs to be done with the selected blocs
* @return string usually an HTML fragment, but it can be nothing.
*/
function process_thread_content()
{
$html = '';
$Categorie_array = $this->categories['category_1'];
foreach ($Categorie_array as $aCategory)
{
// for each category: display files in this category
$html .= '<h1>'.$aCategory['name'].'</h1>';
foreach ($this->Blocs as $aBloc)
{
$Categorie_id = $aBloc['category_1_id'];
if ($Categorie_id != $aCategory['id'])
continue;
// display a file
if ($aBloc['file_download_1_filename'] != '')
$Fichier = '<a target="_blank" href="'.GetFilePath($aBloc, 'file_download_1').'">'.$aBloc['file_download_1_description'].'</a>';
else
$Fichier = '';
$Description = $aBloc['paragraph_1_text'];
// Output each bloc as HTML
if ($Fichier != '')
{
$html .= $Fichier.'<br>';
$html .= $Description;
}
}
}
return $html;
}
}
?>
