Chapitre 53. Application
La classe s’appele toujours "nom-du-widget.php" , elle est dérivée de widget et doit avoir les fonctions
-
display : affichage du widget
-
input : affichage de la description et permet son activation (visible dans la box )
-
input-parameter : si des paramètres doivent être sauvées, les paramètres sont par utilisateur et par widget activés,
-
display_parameter
53.1. Paramètres
Certains widgets peuvent être paramétrés, et il est possible d’ajouter plusieurs fois le même widget
Exemple mini-report : choix du mini-report à afficher,
Pour cela, il faut ajouter certaines fonctions :
53.1.1. input_parameter() : création du FORM
création d’un FORM dont le DOMID sera le code widget (wd_code) suivi de "_param"
exemple pour mini_report, on utilise la fonction Widget→make_form , qui enveloppe le code transmis dans une balise FORM, construisant ainsi le code HTML d’un FORM qui sera envoyé correctement en ajax. Les paramètres passés seront sauvés dans user_widget et pourront être récupérés dans un tableau associatif avec Widget->get_parameter.
function input_parameter() {
$select=new \ISelect('simple_report');
$select->value=$this->db->make_array("select fr_id, fr_label from form_definition order by 2");
$this->make_form($select->input());
}
53.1.2. display_parameter : affichage du paramètre
Les paramètres sont toujours sauvés "brut" , comme une chaîne URL par la fonction Widget->make_form(), il faut donc pouvoir l’afficher, en la travaillant avec parse_str, pour cela il faut appeler Widget->get_parameter(), le résultat doit être dans un SPAN avec la classe "widget_param".
Exemple pour mini_report
function display_parameter() {
$aParam=$this->get_parameter();
$name = $this->db->get_value("select fr_label from form_definition where fr_id=$1",[$aParam['simple_report']]);
echo " ";
echo span(_("Rapport") ." ".h($name),' class="widget_param"');
}
53.2. function display
Toujours commencer par un DIV (id=code_widget+uw_id), Widget::open_div et Widget::close_div
Ce DIV doit avoir comme classe box et widget-box , le widget-box permet de numéroter les boites.
53.3. Exemple complet
|
Astuce
|
Toute la documentation du code source est maintenue avec Doxygen, ici on a un exemple. |
/*!
* \file
* \brief display the next invoice to to be paid or late for customer or supplier
*/
namespace Noalyss\Widget;
/*!
* \class
* \brief display the next invoice to to be paid or late for customer or supplier
*/
class Invoice extends Widget
{
function input_parameter()
{
$tiers = new \ISelect('tiers');
$tiers->value[] = array('value' => 'S', 'label' => _("Fournisseurs"));
$tiers->value[] = array('value' => 'C', 'label' => _("Clients"));
$time_limit = new \ISelect('time_limit');
$time_limit->value[] = array('value' => 'P', 'label' => _("Prochaines factures"));
$time_limit->value[] = array('value' => 'R', 'label' => _("Factures en retard"));
$time_limit->value[] = array('value' => 'T', 'label' => _("Factures pour aujourd'hui"));
$input = _("Factures ") . $tiers->input() . " " . _("échéance") . " " . $time_limit->input();
$this->make_form($input);
}
function display_parameter()
{
$aParam = $this->get_parameter();
$aTiers = ['S' => _("Fournisseurs"), "C" => _("Clients")];
$aLimit = ['P' => _("Prochaines"), "R" => "Retard",'T'=>_("Aujourd'hui")];
echo '<span class="widget_param">'.$aTiers[$aParam['tiers']] . " " . $aLimit[$aParam["time_limit"]].'</span>';
}
function display()
{
$this->open_div();
$aParam = $this->get_parameter();
$aTiers = ['S' => _("Fournisseurs"), "C" => _("Clients")];
$aLimit = ['P' => _("Prochaines factures"), "R" => "facture en retard",'T'=>_("Aujourd'hui")];
$title = $aTiers[$aParam['tiers']] . " " . $aLimit[$aParam["time_limit"]];
echo h2($title, 'class="title"');
$acc_ledger = new \Acc_Ledger($this->db, 0);
$ledger_type = 'ACH';
if ($aParam['tiers'] == 'C') {
$ledger_type = 'VEN';
}
switch ($aParam['time_limit']) {
case 'P':
$array = $acc_ledger->get_operation_date(date('d.m.Y'), $ledger_type, '>');
break;
case 'R':
$array = $acc_ledger->get_operation_date(date('d.m.Y'), $ledger_type, '<');
break;
case 'T':
$array = $acc_ledger->get_operation_date(date('d.m.Y'), $ledger_type, '=');
break;
}
include "invoice-display.php";
$this->close_div();
}
Voir aussi "Paramètres"