MessageHelper.php 970 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
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
okhin committed
23 24 25

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