Commit 8b21311c authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Support des fonctions Doctrine compriseEntre() et pasHistorise()

parent cf7d3aa3
Loading
Loading
Loading
Loading
Loading
+10
Changes for config/module.config.php: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@ use UnicaenApp\HostLocalization\HostLocalization;
use UnicaenApp\HostLocalization\HostLocalizationFactory;
use UnicaenApp\Message\View\Helper\MessageHelper;
use UnicaenApp\Message\View\Helper\MessageHelperFactory;
use UnicaenApp\ORM\Query\Functions\CompriseEntre;
use UnicaenApp\ORM\Query\Functions\PasHistorise;
use UnicaenApp\Service\InstadiaServiceFactory;
use UnicaenApp\Service\Mailer\MailerService;
use UnicaenApp\Service\Mailer\MailerServiceFactory;
@@ -477,6 +479,14 @@ return [
                ],
            ],
        ],
        'configuration' => [
            'orm_default' => [
                'string_functions' => [
                    'compriseEntre' => CompriseEntre::class,
                    'pasHistorise' => PasHistorise::class,
                ],
            ],
        ],
    ],

    'view_manager' => [
+51
Changes for src/UnicaenApp/ORM/Query/Functions/CompriseEntre.php: 51 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace UnicaenApp\ORM\Query\Functions;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;

class CompriseEntre extends FunctionNode
{
    public $histoCreation;
    public $histoDestruction;
    public $dateObs;

    public function getSql(SqlWalker $sqlWalker)
    {
        $sql = sprintf('comprise_entre(%s, %s',
                $this->histoCreation->dispatch($sqlWalker),
                $this->histoDestruction->dispatch($sqlWalker));
        
        if ($this->dateObs){
            $sql .= ','.$this->dateObs->dispatch($sqlWalker);
        }
        $sql .= ')';
        return $sql;
    }

    /**
     * NB: le format DQL attendu est "compriseEntre"
     * (et non pas "UNICAEN_ORACLE.COMPRISE_ENTRE").
     * 
     * @param Parser $parser
     */
    public function parse(Parser $parser)
    {
        $lexer = $parser->getLexer();
        $parser->match(Lexer::T_IDENTIFIER);
        $parser->match(Lexer::T_OPEN_PARENTHESIS);
        $this->histoCreation = $parser->ArithmeticPrimary();
        if(Lexer::T_COMMA === $lexer->lookahead['type']){
            $parser->match(Lexer::T_COMMA);
            $this->histoDestruction = $parser->ArithmeticPrimary();
        }
        if(Lexer::T_COMMA === $lexer->lookahead['type']){
            $parser->match(Lexer::T_COMMA);
            $this->dateObs = $parser->ArithmeticPrimary();
        }
        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
    }
}
 No newline at end of file
+71
Changes for src/UnicaenApp/ORM/Query/Functions/PasHistorise.php: 71 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace UnicaenApp\ORM\Query\Functions;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;

/**
 * Fonction DQL maison "pasHistorise()".
 * 
 * NB: le format DQL attendu est "pasHistorise(EntityExpression)". 
 * Exemples :
 * <pre>
 * $qb->andWhere("1 = pasHistorise(sr)")
 * $qb->andWhere("1 = pasHistorise(int.serviceReferentiel)")
 * </pre>
 * 
 * Fait appel à la fonction Oracle UNICAEN_ORACLE.COMPRISE_ENTRE().
 */
class PasHistorise extends FunctionNode
{
    public $alias;
    public $dateObservation;

    /**
     * Parsing.
     * 
     * NB: le format DQL attendu est "pasHistorise(EntityExpression)".
     * Exemple :
     *  pasHistorise(s)
     *  pasHistorise(int.serviceReferentiel)
     * 
     * @param Parser $parser
     */
    public function parse(Parser $parser)
    {
        $lexer = $parser->getLexer();
        $parser->match(Lexer::T_IDENTIFIER);
        $parser->match(Lexer::T_OPEN_PARENTHESIS);
        $this->alias = $parser->EntityExpression();
        if(Lexer::T_COMMA === $lexer->lookahead['type']){
            $parser->match(Lexer::T_COMMA);
            $this->dateObservation = $parser->ArithmeticPrimary();
        }
        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
    }

    /**
     * Génère le code SQL.
     * 
     * @param SqlWalker $sqlWalker
     * @return string
     */
    public function getSql(SqlWalker $sqlWalker)
    {
        $expr1 = clone($this->alias);
        $expr2 = clone($this->alias);
        
        $expr1->field = 'histoCreation';
        $expr2->field = 'histoDestruction';
        
        $sql = sprintf('comprise_entre(%s, %s, %s)',
                $expr1->dispatch($sqlWalker),
                $expr2->dispatch($sqlWalker),
                $this->dateObservation ? $this->dateObservation->dispatch($sqlWalker) : 'null');
        
        return $sql;
    }
}
 No newline at end of file