point-tools/src/Doctrine/DQL/Day.php

29 lines
692 B
PHP
Raw Normal View History

<?php
2023-03-28 20:01:56 +00:00
declare(strict_types=1);
2023-03-28 20:01:56 +00:00
namespace App\Doctrine\DQL;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
2023-03-28 20:01:56 +00:00
use Doctrine\ORM\Query\{Lexer, Parser, SqlWalker};
2023-03-28 20:01:56 +00:00
/** TODO: check if still needed */
class Day extends FunctionNode
{
public $dateExpression;
2023-03-28 20:01:56 +00:00
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->dateExpression = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
2023-03-28 20:01:56 +00:00
public function getSql(SqlWalker $sqlWalker): string
{
return 'date_trunc(\'day\', '.$this->dateExpression->dispatch($sqlWalker).')';
}
2023-03-28 20:01:56 +00:00
}