V. Développer avec PHPBoost

Système de commentaires

Dernière mise à jour : 13/06/2013 à 17h37
Cet article indique les différents éléments à mettre en place pour gérer et afficher les commentaires dans un module.

Implémentation de l'extension point



Créer un fichier NomDuModuleCommentsTopic.class.php dans le dossier phpboost du module contenant :
Code PHP :
 
<?php
/*##################################################
 *                           NomDuModuleCommentsTopic.class.php
 *                            -------------------
 *   begin                : May 30, 2013
 *   copyright            : (C) 2013 Kevin MASSY
 *   email                : kevin.massy@phpboost.com
 *
 *
 ###################################################
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 ###################################################*/
 
class NomDuModuleCommentsTopic extends CommentsTopic
{
    public function __construct()
    {
        parent::__construct('nomdumodule');
    }
 
    public function get_authorizations()
    {
        return new CommentsAuthorizations();
    }
 
    public function is_display()
    {
        return true;
    }
}
?>
 


Editer le fichier NomDuModuleExtensionPointProvider.class.php dans le dossier phpboost du module et ajouter la fonction suivante dans la classe :
Code PHP :
 
    public function comments()
    {
        return new CommentsTopics(array(new NomDuModuleCommentsTopic()));
    }
 

Appel de la classe



Ajouter le contenu suivant dans votre page php à l'endroit où les commentaires doivent être affichés :
Code PHP :
 
$comments_topic = new NomDuModuleCommentsTopic();
$comments_topic->set_id_in_module('ID DE L ELEMENT');
$comments_topic->set_url(new Url('URL DE TON ELEMENT'));
$tpl->put('COMMENTS', $comments_topic->display());
 

Affichage du système de commentaires



Ajouter le code suivant dans le template appelé par votre contrôleur à l'endroit où les commentaires doivent être affichés :
Code TPL :
 
# INCLUDE  COMMENTS #
 
Cette page a été vue 4560 fois