Commit d211f8a4 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Améliorations : création de Display pour faciliter le debug & centralisation...

Améliorations : création de Display pour faciliter le debug & centralisation de toutes les conversions HTML dedans
parent c966bf0e
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
CHANGELOG
=========

6.0.4
------------------
- Améliorations : création de Display pour faciliter le debug & centralisation de toutes les conversions HTML dedans

6.0.3
------------------
- [FIX] Correction de détection des numéros de lignes

src/Calc/Display.php

0 → 100644
+92 −0
Original line number Diff line number Diff line
<?php

namespace Unicaen\OpenDocument\Calc;

use Unicaen\OpenDocument\Calc;

class Display
{

    static public function sheet(Sheet $sheet): string
    {
        $h = '<table class="table table-bordered table-condensed">';
        $h .= '<tr><th></th>';
        for ($c = 1; $c <= $sheet->getMaxCol(); $c++) {
            $h .= '<th>' . (Calc::numberToLetter($c)) . '</th>';
        }
        $h .= '</tr>';
        for ($r = 1; $r <= $sheet->getMaxRow(); $r++) {
            $h .= '<tr><th>' . $r . '</th>';
            for ($c = 1; $c <= $sheet->getMaxCol(); $c++) {
                $cell = $sheet->getCellByCoords($c, $r);
                if ($cell && $cell->getRow() == $r && $cell->getCol() == $c) {
                    $h .= '<td rowspan="' . $cell->getRowSpan() . '" colspan="' . $cell->getColSpan() . '">' . ($cell ? $cell->getValue() : '') . '</td>';
                } elseif (!$cell) {
                    $h .= '<td></td>';
                }
            }
            $h .= '</tr>';
        }

        $h .= '</table>';

        return $h;
    }



    static public function formule(Formule $formule)
    {
        $h = '';
        $h .= '<div style="clear: both"><code>' . htmlentities($formule->text()) . '</code></div>';

        $expr = $formule->analyse();

        $h .= self::formuleExpr($expr);

        return $h;
    }



    static public function formuleExpr(array $expr, $inFunction=false): string
    {
        $h = '';

        if (isset($expr['type'])){

            // sous-expression
            $h .= '        <table class="table table-bordered table-condensed table-xs" style="width:auto">';
            foreach ($expr as $t => $v) {
                if ($t == 'level'){
                    continue;
                }
                if (is_array($v)){
                    $v = self::formuleExpr($v, $expr['type'] == 'function');
                }else{
                    $v = htmlentities($v);
                }

                $h .= '        <tr>';
                $h .= '            <th>' . $t . '</th>';
                $h .= '            <td>' . $v . '</td>';
                $h .= '        </tr>';
            }
            $h .= '        </table>';
        }else{
            // liste de sous-expressions
            $h .= '<table class="table-xs"><tr>';
            $first = true;
            foreach ($expr as $index => $term) {
                if ($inFunction && !$first){
                    $h .= '<td style="vertical-align: top">&nbsp;;&nbsp;</td>';
                }
                $h .= '<td style="vertical-align: top">'.self::formuleExpr($term).'</td>';
                $first = false;
            }
            $h .= '</tr></table>';
        }

        return $h;
    }
}
 No newline at end of file
+7 −44
Original line number Diff line number Diff line
@@ -45,6 +45,13 @@ class Formule



    public function text(): string
    {
        return $this->formule;
    }



    public function analyse(): array
    {
        if (empty($this->terms)) {
@@ -87,42 +94,6 @@ class Formule



    public function displayTerms()
    {
        echo '<div style="clear: both"><code>' . htmlentities($this->formule) . '</code></div>';
        echo '<div>';
        foreach ($this->terms as $index => $term) {
            $this->displayTerm($index, $term);
        }
        echo '</div>';
    }



    private function displayTerm(int $index, array $term)
    {
        $type = $term['type'];
        unset($term['type']);

        ?>
        <div style="width:120px;float:left;margin:2px">
            <div class="panel panel-default">
                <div class="panel-heading"><b><?= $index ?></b>&nbsp;<?= $type ?: '<span style="color:red">IND</span>' ?></div>
                <table class="table table-bordered table-condensed table-extra-condensed">
                    <?php foreach ($term as $t => $v): ?>
                        <tr>
                            <th><?= $t ?></th>
                            <td><?= htmlentities($v) ?></td>
                        </tr>
                    <?php endforeach; ?>
                </table>
            </div>
        </div>
        <?php
    }



    private function lexing()
    {
        $lexers = [
@@ -445,12 +416,4 @@ class Formule
        $expr     = array_values($expr);
    }



    public function displayExprs()
    {
        echo '<div style="clear:both">';
        phpDump($this->expr);
        echo '</div>';
    }
}
 No newline at end of file
+0 −28
Original line number Diff line number Diff line
@@ -236,32 +236,4 @@ class Sheet
        return $this->getCellByCoords($col, $row);
    }



    public function html(): string
    {
        $h = '<table class="table table-bordered table-condensed">';
        $h .= '<tr><th></th>';
        for ($c = 1; $c <= $this->getMaxCol(); $c++) {
            $h .= '<th>' . (Calc::numberToLetter($c)) . '</th>';
        }
        $h .= '</tr>';
        for ($r = 1; $r <= $this->getMaxRow(); $r++) {
            $h .= '<tr><th>' . $r . '</th>';
            for ($c = 1; $c <= $this->getMaxCol(); $c++) {
                $cell = $this->getCellByCoords($c, $r);
                if ($cell && $cell->getRow() == $r && $cell->getCol() == $c) {
                    $h .= '<td rowspan="' . $cell->getRowSpan() . '" colspan="' . $cell->getColSpan() . '">' . ($cell ? $cell->getValue() : '') . '</td>';
                }elseif(!$cell){
                    $h .= '<td></td>';
                }
            }
            $h .= '</tr>';
        }

        $h .= '</table>';

        return $h;
    }

}
 No newline at end of file