Commit 9fb39451 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Support des fonctions Doctrine compriseEntre() et pasHistorise()

parent fda70a0a
Pipeline #9202 failed with stages
in 1 minute and 1 second
......@@ -10,6 +10,8 @@ use UnicaenApp\HostLocalization\HostLocalizationUnicaen;
use UnicaenApp\HostLocalization\HostLocalizationUnicaenFactory;
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' => [
......
<?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
<?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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment