Dernière mise à jour : 19/01/2018 à 00h32
Table des matières
Cette documentation permet de rendre votre module compatible avec la version 5.1 de PHPBoost sans trop de modifications dans le code. Elle n'a pas pour but de le convertir en utilisant le modèle MVC s'il n'est pas MVC. Effectuez les différentes étapes suivantes (peu importe l'ordre) pour mettre à jour votre module.
Le fichier de configuration - OBLIGATOIRE
Les seuls changements à effectuer dans le fichier /module/config.ini pour rendre votre module compatible avec la nouvelle version sont les paramètres "compatibility" et "version". Remplacez la valeur de "compatibility" par 5.1 et augmentez le numéro de version de votre module pour plus de cohérence.
Code TEXT :
version=5.1.0 compatibility=5.1
Encodage de vos fichiers en UTF8 sans BOM - OBLIGATOIRE
Voici la démarche à suivre avec Notepad++ (c'est un exemple, d'autres éditeurs font la même chose) pour que tous les nouveaux documents créés soient en UTF8 sans Bom (UTF8 et BOM - Explications):
Si vous voulez convertir en UTF8 sans Bom tous vos documents ouverts, voici ce qu'il faut faire (toujours avec Notepad++) :
Gestion des catégories et des éléments en front - OBLIGATOIRE
Dans le cas d'utilisation des catégories - Exemples en image :
En 5.0, la gestion des catégories se trouve en back :
En 5.1, la gestion des catégories se trouve en front :
Il en est de même pour la gestion des éléments. Elle passe donc en front en 5.1 .
En 5.0 :
En 5.1 :
Renommer le fichier AdminMonModuleManageController.class.php en MonModuleManageController.class.php.
Maintenant, il va falloir effectuer l'ensemble des modifications décrites dans ce lien. En rouge, le code à effacer et en vert le code à ajouter. Le module Articles a encore été pris en exemple.
Les fichiers concernés sont :
- monmodule/controllers/AdminMonModuleManageController ->monmodule/controllers/MonModuleManageController.class.php
- monmodule/controllers/AdminMonModuleConfigController.class.php
- monmodule/controllers/categories/MonModuleCategoriesFormController.class.php
- monmodules/controllers/categories/MonModuleCategoriesManageController.class.php
- monmodule/controllers/categories/MonModuleDeleteCategoryController.class.php
- monmodule/index.php
- monmodule/phpboost/MonModuleTreeLinks.class.php
- monmodule/services/MonModuleAuthorizationsService.class.php
- monmodule/util/AdminMonModuleDisplayResponse.class.php
- monmodule/util/MonModuleUrlBuilder.class.php
Gestion globale dans l'administration
En 5.1, la gestion du système de commentaire ainsi que celui de la notation a été entièrement transférée dans la rubrique contenu de l'administration générale.
Si vos modules utilisaient ces fonctionnalités en 5.0, veuillez suivre les modifications ci-dessous.
De plus, Phpboost 5.1 offre une nouvelle fonction New Content que vous allez pouvoir ajouter.
Les commentaires (facultatif)
Création du fichier NomModuleComments.class.php dans NomModule/phpboost/
NomModuleComments.class.php :
<?php /*################################################## * NomModuleComments.class.php * ------------------- * begin : *champ à renseigner * copyright : *champ à renseigner * email : *champ à renseigner * * ################################################### * * 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. * ###################################################*/ /** * @author Votre Nom <votre e-mail> */ class NomModuleComments extends AbstractCommentsExtensionPoint { public function __construct() { parent::__construct('nommodule'); } } ?>
Puisque l'activation des commentaires doit se faire à partir de l'administration générale et non dans la configuration de votre module, voici les quelques lignes de codes à supprimer (si bien-entendu elles existent dans votre module) :
NomModuleConfig.class.php :
// A supprimer dans la déclaration des constantes const COMMENTS_ENABLED = 'comments_enable'; // // // A supprimer dans la déclaration des méthodes public function enable_comments() { $this->set_property(self::COMMENTS_ENABLED, true); } public function disable_comments() { $this->set_property(self::COMMENTS_ENABLED, false); } public function are_comments_enabled() { return $this->get_property(self::COMMENTS_ENABLED); } // // // A supprimer dans public function get_default_values() { return array ( self::COMMENTS_ENABLED => true,
Nous allons maintenant supprimer le champ d'activation des commentaires de la configuration de votre module :
AdminNomModuleConfigController.class.php :
// A supprimer dans la déclaration des champs $fieldset->add_field(new FormFieldCheckbox('comments_enabled', $this->admin_common_lang['config.comments_enabled'], $this->config->are_comments_enabled())); // // // A supprimer dans private function save() if ($this->form->get_value('comments_enabled')) { $this->config->enable_comments(); } else { $this->config->disable_comments(); }
Le système de notation (facultatif)
Création du fichier NomModuleNotation.class.php dans NomModule/phpboost/
NomModuleNotation.class.php :
<?php /*################################################## * NomModuleNotation.class.php * ------------------- * begin : *champ à renseigner * copyright : *champ à renseigner * email : *champ à renseigner * * ################################################### * * 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. * ###################################################*/ /** * @author Votre Nom <votre e-mail> */ class NomModuleNotation extends AbstractNotationExtensionPoint { public function __construct() { parent::__construct('nommodule'); } } ?>
Ensuite ajoutez dans NomModuleExtensionPointProvider.class.php dans NomModule/phpboost/
NomModuleExtensionPointProvider.class.php :
public function notation() { return new NomModuleNotation(); }
Puisque l'activation de la notation doit se faire à partir de l'administration générale et non dans la configuration de votre module, voici les quelques lignes de codes à supprimer (si bien-entendu elles existent dans votre module) :
NomModuleConfig.class.php :
// A supprimer dans la déclaration des constantes const NOTATION_ENABLED = 'notation_enabled'; const NOTATION_SCALE = 'notation_scale'; // // // A supprimer dans la déclaration des méthodes public function enable_notation() { $this->set_property(self::NOTATION_ENABLED, true); } public function disable_notation() { $this->set_property(self::NOTATION_ENABLED, false); } public function is_notation_enabled() { return $this->get_property(self::NOTATION_ENABLED); } public function get_notation_scale() { return $this->get_property(self::NOTATION_SCALE); } public function set_notation_scale($notation_scale) { $this->set_property(self::NOTATION_SCALE, $notation_scale); } // // A supprimer dans public function get_default_values() { return array ( self::NOTATION_ENABLED => true, self::NOTATION_SCALE => 5,
Nous allons maintenant supprimer les champs de configuration de la notation de votre module :
AdminNomModuleConfigController.class.php :
// A supprimer dans public function execute(HTTPRequestCustom $request) $this->form->get_field_by_id('notation_scale')->set_hidden(!$this->config->is_notation_enabled()); // // // A supprimer dans la déclaration des champs $fieldset->add_field(new FormFieldCheckbox('notation_enabled', $this->admin_common_lang['config.notation_enabled'], $this->config->is_notation_enabled(), array( 'events' => array('click' => ' if (HTMLForms.getField("notation_enabled").getValue()) { HTMLForms.getField("notation_scale").enable(); } else { HTMLForms.getField("notation_scale").disable(); }' ) ))); // // // A supprimer dans private function save() if ($this->form->get_value('notation_enabled')) { $this->config->enable_notation(); $this->config->set_notation_scale($this->form->get_value('notation_scale')); if ($this->form->get_value('notation_scale') != $this->config->get_notation_scale()) NotationService::update_notation_scale('nommodule', $this->config->get_notation_scale(), $this->form->get_value('notation_scale')); } else $this->config->disable_notation();
Dans services/NomModule.class.php
NomModule.class.php :
// A supprimer dans la déclaration des attributs et des constantes private $notation_enabled; // // const NOTATION_DISABLED = 0; const NOTATION_ENABLED = 1; // // public function get_notation_enabled() { return $this->notation_enabled; } public function set_notation_enabled($enabled) { $this->notation_enabled = $enabled; } // A supprimer dans public function get_properties() { return array( 'notation_enabled' => $this->get_notation_enabled(), // // // A supprimer dans public function set_properties(array $properties) { $this->set_notation_enabled($properties['notation_enabled']); // Dans la même méthode, ajouter sous $notation = new Notation(); $notation_config = new NomModuleNotation(); // // //A supprimer dans public function init_default_properties($id_category = Category::ROOT_CATEGORY) $this->notation_enabled = self::NOTATION_ENABLED; // // // Dans public function get_array_tpl_vars() , ajouter : $notation_config = new NomModuleNotation(); // Et dans return array( modifier : 'C_NOTATION_ENABLED' => $this->get_notation_enabled(), // par 'C_NOTATION_ENABLED' => $notation_config->is_notation_enabled(),
Activation du New-Content (facultatif)
Création du fichier NomModuleNewContent.class.php dans NomModule/phpboost/
NomModuleNewContent.class.php :
<?php /*################################################## * NomModuleNewContent.class.php * ------------------- * begin : *champ à renseigner * copyright : *champ à renseigner * email : *champ à renseigner * * ################################################### * * 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. * ###################################################*/ /** * @author Votre Nom <votre e-mail> */ class NomModuleNewContent extends AbstractNewContentExtensionPoint { public function __construct() { parent::__construct('nommodule'); } } ?>
Ensuite ajoutez dans NomModuleExtensionPointProvider.class.php dans NomModule/phpboost/
NomModuleExtensionPointProvider.class.php :
public function newcontent() { return new NomModuleNewContent(); }
Dans la majorité des cas, il faudra modifier NomModule.class.php en ajoutant :
- pour créer l'objet :
Code PHP :
$new_content = new NomModuleContent();
- pour créer la variable template :
Code PHP :
'C_NEW_CONTENT' => $new_content->check_if_is_new_content($this->publishing_start_date != null ? $this->publishing_start_date->get_timestamp() : $this->get_date_created()->get_timestamp()) && $this->is_published(),
Exemple avec le module Articles (L 11 et L 36):
Articles.class.php :
public function get_array_tpl_vars() { $category = $this->get_category(); $contents = FormatingHelper::second_parse($this->contents); $description = $this->get_real_description(); $user = $this->get_author_user(); $user_group_color = User::get_group_color($user->get_groups(), $user->get_level(), true); $sources = $this->get_sources(); $new_content = new ArticlesNewContent(); $notation_config = new ArticlesNotation(); //Conditions 'C_EDIT' => $this->is_authorized_to_edit(), 'C_DELETE' => $this->is_authorized_to_delete(), 'C_HAS_PICTURE' => $this->has_picture(), 'C_PUBLISHED' => $this->is_published(), 'C_PUBLISHING_START_AND_END_DATE' => $this->publishing_start_date != null && $this->publishing_end_date != null, 'C_PUBLISHING_START_DATE' => $this->publishing_start_date != null, 'C_PUBLISHING_END_DATE' => $this->publishing_end_date != null, 'C_DATE_UPDATED' => $this->date_updated != null, 'C_AUTHOR_DISPLAYED' => $this->get_author_name_displayed(), 'C_AUTHOR_CUSTOM_NAME' => $this->is_author_custom_name_enabled(), 'C_NOTATION_ENABLED' => $notation_config->is_notation_enabled(), 'C_READ_MORE' => !$this->get_description_enabled() && TextHelper::strlen($contents) > ArticlesConfig::load()->get_number_character_to_cut() && $description != @strip_tags($contents, '<br><br/>'), 'C_SOURCES' => $nbr_sources > 0, 'C_DIFFERED' => $this->published == self::PUBLISHED_DATE, 'C_NEW_CONTENT' => $new_content->check_if_is_new_content($this->publishing_start_date != null ? $this->publishing_start_date->get_timestamp() : $this->get_date_created()->get_timestamp()) && $this->is_published(),
La variable C_NEW_CONTENT peut être différente suivant les champs utilisés dans votre module. Si votre module utilise une date de publication :
Code PHP :
'C_NEW_CONTENT' => $new_content->check_if_is_new_content($this->publishing_start_date != null ? $this->publishing_start_date->get_timestamp() : $this->get_date_created()->get_timestamp()) && $this->is_published(),
Sinon :
Code PHP :
'C_NEW_CONTENT' => $new_content->check_if_is_new_content($this->get_creation_date()->get_timestamp()),
Il ne reste maintenant qu'à intégrer notre variable C_NEW_CONTENT dans le template
Voici deux exemples avec le module Articles:
ArticlesDisplayArticlesController.tpl :
ArticlesDisplaySeveralArticlesController.tpl :
<div class="content elements-container# IF C_SEVERAL_COLUMNS # columns-{NUMBER_COLUMNS}# ENDIF#"> # START articles # <article id="article-articles-{articles.ID}" class="article-articles article-several# IF C_MOSAIC # block# ENDIF ## IF articles.C_NEW_CONTENT # new-content# ENDIF #" itemscope="itemscope" itemtype="http://schema.org/CreativeWork">
Affichage des catégories d'un formulaire s'il existe au moins une catégorie (facultatif)
Ce formulaire ne sera pas affiché s'il n'y a pas de catégorie créée :
Utilisation de MonModuleService::get_categories_manager()->get_categories_cache()->has_categories().
Exemple avec le module Articles, on ajoute la condition :
Code PHP :
if (ArticlesService::get_categories_manager()->get_categories_cache()->has_categories()) { ......}
à
Code PHP :
$search_category_children_options = new SearchCategoryChildrensOptions(); $search_category_children_options->add_authorizations_bits(Category::CONTRIBUTION_AUTHORIZATIONS); $search_category_children_options->add_authorizations_bits(Category::WRITE_AUTHORIZATIONS); $fieldset->add_field(ArticlesService::get_categories_manager()->get_select_categories_form_field('id_category', $this->common_lang['form.category'], $this->get_article()->get_id_category(), $search_category_children_options));
Il faut faire de même pour la méthode save().
Voici les deux modifications en exemple :
ArticlesFormController.class.php :
private function build_form(HTTPRequestCustom $request) { . . . if (ArticlesService::get_categories_manager()->get_categories_cache()->has_categories()) { $search_category_children_options = new SearchCategoryChildrensOptions(); $search_category_children_options->add_authorizations_bits(Category::CONTRIBUTION_AUTHORIZATIONS); $search_category_children_options->add_authorizations_bits(Category::WRITE_AUTHORIZATIONS); $fieldset->add_field(ArticlesService::get_categories_manager()->get_select_categories_form_field('id_category', $this->common_lang['form.category'], $this->get_article()->get_id_category(), $search_category_children_options)); } . . . . private function save() { $article = $this->get_article(); $article->set_title($this->form->get_value('title')); if (ArticlesService::get_categories_manager()->get_categories_cache()->has_categories()) $article->set_id_category($this->form->get_value('id_category')->get_raw_value()); . . .