MessageHelper.php 904 Bytes
Newer Older
Okhin's avatar
Okhin committed
1 2
<?php

Okhin's avatar
Okhin committed
3
class MessageHelper extends \Prefab
Okhin's avatar
Okhin committed
4 5 6 7 8
{
    /**
     * Cette classe sert à afficher le code HTML stocké dans un tableau passé en argument
     * et avec une classe éventuelle ajoutée en CSS
     */
Okhin's avatar
Okhin committed
9
    public static function render($node)
Okhin's avatar
Okhin committed
10
    {
Okhin's avatar
Okhin committed
11 12 13 14
        $attr = $node['@attrib'];
        if (!isset($attr['messages'])) {
            return;
        }
Okhin's avatar
Okhin committed
15

Okhin's avatar
Okhin committed
16
        $html = '';
Okhin's avatar
WIP  
Okhin committed
17 18
        $class = isset($attr['class']) ? $attr['class'] : "";
        $messages = \Template::instance()->token($attr['messages']);
Okhin's avatar
Okhin committed
19
        $html .= '<?php \MessageHelper::instance()->build('.$messages.', "'.$class.'"); ?>';
Okhin's avatar
Okhin committed
20 21 22

        return sprintf($html);
    }
Okhin's avatar
WIP  
Okhin committed
23 24 25

    public function build($messages, $class)
    {
Okhin's avatar
Okhin committed
26 27 28 29 30 31 32
        $html = '';
        foreach ($messages as $message) {
            $html .= "<div class=\"$class\">";
            $html .= $message;
            $html .= "</div>";
        }
        echo $html;
Okhin's avatar
WIP  
Okhin committed
33
    }
Okhin's avatar
Okhin committed
34
}