mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
exports: fix activity DateAggregator; add customs DQL Date/Time functions
This commit is contained in:
47
src/Bundle/ChillMainBundle/Doctrine/DQL/Extract.php
Normal file
47
src/Bundle/ChillMainBundle/Doctrine/DQL/Extract.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Doctrine\DQL;
|
||||
|
||||
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
|
||||
use Doctrine\ORM\Query\AST\PathExpression;
|
||||
use Doctrine\ORM\Query\Lexer;
|
||||
use Doctrine\ORM\Query\Parser;
|
||||
use Doctrine\ORM\Query\SqlWalker;
|
||||
|
||||
/**
|
||||
* Extract postgresql function
|
||||
* https://www.postgresql.org/docs/current/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
|
||||
*
|
||||
* Usage : EXTRACT(field FROM value)
|
||||
*/
|
||||
class Extract extends FunctionNode
|
||||
{
|
||||
private string $field;
|
||||
|
||||
private PathExpression $value;
|
||||
|
||||
public function getSql(SqlWalker $sqlWalker)
|
||||
{
|
||||
return sprintf(
|
||||
'EXTRACT(%s FROM %s)',
|
||||
$this->field,
|
||||
$this->value->dispatch($sqlWalker)
|
||||
);
|
||||
}
|
||||
|
||||
public function parse(Parser $parser)
|
||||
{
|
||||
$parser->match(Lexer::T_IDENTIFIER);
|
||||
$parser->match(Lexer::T_OPEN_PARENTHESIS);
|
||||
|
||||
$parser->match(Lexer::T_IDENTIFIER);
|
||||
$this->field = $parser->getLexer()->token['value'];
|
||||
|
||||
$parser->match(Lexer::T_FROM);
|
||||
|
||||
$this->value = $parser->ScalarExpression();
|
||||
|
||||
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user