Commit 5f6bd636 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Ajout fonction "pasHistorise" au parser DQL.

Ajout dépendance avec UnicaenOracle (car la fonction "pasHistorisée" appelle une fonction du package UNICAEN_ORACLE).
parent 7b1870c8
......@@ -8,7 +8,8 @@
}
],
"require" : {
"unicaen/unicaen-auth": "^1.0"
"unicaen/unicaen-auth": "^1.0",
"unicaen/unicaen-oracle": "^1.0"
},
"require-dev" : {
"phpunit/PHPUnit" : ">=3.7"
......
......@@ -3,6 +3,7 @@
namespace UnicaenImport;
use UnicaenAuth\Guard\PrivilegeController;
use UnicaenImport\ORM\Query\Functions\OseDivers\PasHistorise;
use UnicaenImport\Provider\Privilege\Privileges;
return [
......@@ -63,7 +64,7 @@ return [
],
'doctrine' => [
'driver' => [
'driver' => [
'unicaen_import_driver' => [
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
......@@ -78,6 +79,13 @@ return [
],
],
],
'configuration' => [
'orm_default' => [
'string_functions' => [
'pasHistorise' => PasHistorise::class,
],
],
],
],
'service_manager' => [
......@@ -104,5 +112,4 @@ return [
'import' => __DIR__ . '/../view',
],
],
];
\ No newline at end of file
<?php
namespace UnicaenImport\ORM\Query\Functions\OseDivers;
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 OSE_DIVERS.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('UNICAEN_ORACLE.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