Commit 67437dec authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Possibilité de gérer les IF imbriqués dans des paramètres de fonctions

(cherry picked from commit 2c5aef7f)
parent 790f1b5f
Loading
Loading
Loading
Loading
Loading
+35 −0
Changes for module/Formule/src/Service/TraducteurService.php: 35 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ class TraducteurService
        'transfoStructureAffectation',
        'transfoStructureUniv',
        'transfoIfPlus',
        'transfoIfInFunction',
        'transfoSumIf',
        'transfoAbsRange',
        'transfoSimplify',
@@ -428,6 +429,40 @@ class TraducteurService



    protected function transfoIfInFunction(array &$expr, int $i): void
    {
        if ($expr[$i]['type'] == 'function' && $expr[$i]['name'] != 'IF') {
            $params = $expr[$i]['exprs'];
            $if = null;
            foreach( $params as $pi => $param ) {
                foreach($param as $ppi => $pexpr){
                    if ($pexpr && $pexpr['type'] == 'function' && $pexpr['name'] == 'IF') {
                        if ($if != null) {
                            throw new \Exception('Expression trop complexe et intraduisible en l\'état');
                        }
                        $if = $pexpr;
                    }
                }
            }
            if ($if){
                foreach( $if['exprs'] as $eid => $ifRes){
                    if ($eid > 0){
                        $nexpr = $expr;
                        if (count($ifRes) == 1 || count($nexpr) == 1){
                            $nexpr[$i] = current($ifRes);
                        }else{
                            $nexpr[$i] = ['type' => 'expr', 'expr' => $ifRes];
                        }
                        $if['exprs'][$eid] = $nexpr;
                    }
                }
                $expr = [0 => $if];
            }
        }
    }



    protected function transfoSumIf(array &$expr, int $i): void
    {
        $term = $expr[$i];