Skip to content

Instantly share code, notes, and snippets.

@cdunca
Created September 5, 2015 11:45
Show Gist options
  • Save cdunca/e657e4679c9dde6d5c09 to your computer and use it in GitHub Desktop.
Save cdunca/e657e4679c9dde6d5c09 to your computer and use it in GitHub Desktop.
Symfony - Doctrine dql extension for from_unixtime()
<?php
namespace AppBundle\DQL;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
/**
* FromUnixtimeFunction ::=
* "unix_timestamp" "(" ArithmeticPrimary "," ArithmeticPrimary ")"
*/
class FromUnixtimeFunction extends FunctionNode {
public $firstDateExpression = null;
public $secondDateExpression = null;
public function parse(\Doctrine\ORM\Query\Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->firstDateExpression = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$this->secondDateExpression = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
return 'from_unixtime(' .
$this->firstDateExpression->dispatch($sqlWalker) . ', ' .
$this->secondDateExpression->dispatch($sqlWalker) .
')';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment