MyHelperHelper.php 4.2 KB
<?php

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

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

//class MyButtonHelper extends Helper {
class MyHelperHelper 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>";
    }
    
    
    //function displaySectionShowHide($controller_name, $entity_type_name, $title, $id_name, $is_masculine, $name_field_name, $entities) {
    //function displaySectionShowHide($controller_name, $entity_type_name, $title, $is_masculine, $name_field_name, $entities) {
    function displayAssociatedEntitiesAsSectionShowHide($controller_name, $entity_type_name, $title, $is_masculine, $name_field_name, $entities) {
        $id_name = $controller_name;
        $id_h3 = 't_'.$id_name;
        $id_i = 'i_'.$id_name;
        $title = ucfirst($title).' associé'. ($is_masculine ? 's' : 'es');
        
        echo "<h3 id='$id_h3' class='toggle' style='cursor: pointer;'>";
        echo "<i class='icon-chevron-down' style='font-size: 14px;' id='$id_i'></i>";
        echo " <span style='text-decoration: underline;'>$title (".$entities->count().")</span>";
        echo "</h3>";
        
        echo "<div id='$id_name' style='margin-bottom: 20px;'>";
        //if (true) {
        if (empty($entities)) {
            //echo "Aucune $entity_name liée à ce domaine.";
            echo ($is_masculine ? "Aucun $entity_type_name associé" : "Aucune $entity_type_name associée");
        }
        else {
            echo "<table>";
            /*
             <tr>
             <th><= __('Nom') ?></th>
             <th style="width: 50px;"><= __('Détail') ?></th>
             </tr>
             */
            foreach ($entities as $entity) {
                echo "<tr>";
                    echo "<td>";
                    echo '&nbsp;&nbsp;&nbsp;'.$this->Html->link(h($entity->$name_field_name), ['controller' => $controller_name, 'action' => 'view', h($entity->id)]);
                    echo "</td>";
                    /*
                     <td class="actions">
                     <= $this->Html->link(__('<i class="icon-search"></i>'), ['controller' => $controller, 'action' => 'view', $entity->id], ['escape' => false, 'style' => 'margin:0']) ?>
                     </td>
                     */
                echo "</tr>";
            }
            echo "</table>";
        }
        echo "</div>";
    } // displaySectionShowHide()
    
    
}