MyButtonHelper.php 2.04 KB
<?php

/* src/View/Helper/ButtonHelper.php */
namespace App\View\Helper;

use Cake\View\Helper;
use phpDocumentor\Reflection\Types\Void_;

class MyButtonHelper extends Helper {
    
    // On a besoin du HtmlHelper
    public $helpers = ['Html'];
    
    public function initialize(array $config) { 
        //debug($config);
    }
    
    public function getActionButton($icon_class, $buttonStyle, $title, $controller, $action, $id, $other_args=[], $tip='', $confirmMessage='', $moreButtonStyle='') {
        if ($controller=='') $controller='materiels';
        $controllerArgs = [];
        $controllerArgs['controller'] = $controller;
        $controllerArgs['action'] = $action;
        $controllerArgs[] = $id;
        foreach ($other_args as $other_arg) $controllerArgs[] = $other_arg;
        return $this->Html->link(
            __("<i class=$icon_class></i>$title"),
            $controllerArgs,
            /*
             [
             'controller' => $controller,
             'action' => $action,
             $id,
             $other_args
             ],
             */
            [
                'title' => $tip,
                'escape' => false,
                'onclick' => 'return true;',
                //'style' => 'margin-right: 10px'.$moreButtonStyle,
                'style' => $buttonStyle,
                'confirm' => $confirmMessage
            ]
        );
    }
    
    public function displayElement($nom, $valeur, $params = "") {
        $TD = ($params=="") ? 'TD' : "TD $params";
        //$TD = ($params=="") ? '<TD>' : '<TD '.$params.'>';
        //$tdstyle = $params!="" ? $params : '';
        // Ca c'est parce que sinon y'a au moins deux tests qui passent pas, a cause de l'espace dans la balise ...
        //if ($valeur != "") echo '<tr> <td><strong>'.$nom.' </strong></td>' . $TD.$valeur.'</td></tr>';
        //if ($valeur != "") echo '<tr><td><strong>' . $nom . ' </strong></td>' . $balise . $valeur . '</td></tr>';
        if ($valeur!="") echo "<TR> <TD><strong>".__($nom)."</strong></TD> <$TD>".h($valeur)."</TD> </TR>";
    }
    
}