3 namespace UVd\DoctrineFunction;
5 use Doctrine\ORM\Query\Lexer;
6 use Doctrine\ORM\Query\AST\Functions\FunctionNode;
11 * Allows Doctrine 2.0 Query Language to execute a MySQL UNIX_FORMAT function
12 * You must boostrap this function in your ORM as a DQLFunction.
15 * UNIX_TIMESTAMP(TIMESTAMP) : @link http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_unix-timestamp
18 * PLEASE REMEMBER TO CHECK YOUR NAMESPACE
20 * @link labs.ultravioletdesign.co.uk
21 * @author Rob Squires <rob@ultravioletdesign.co.uk>
25 class UnixTimestamp extends FunctionNode {
28 * holds the timestamp of the UNIX_TIMESTAMP DQL statement
31 protected $dateExpression;
36 * getSql - allows ORM to inject a UNIX_TIMESTAMP() statement into an SQL string being constructed
37 * @param \Doctrine\ORM\Query\SqlWalker $sqlWalker
40 public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
42 return 'UNIX_TIMESTAMP(' .
43 $sqlWalker->walkArithmeticExpression($this->dateExpression) .
49 * parse - allows DQL to breakdown the DQL string into a processable structure
50 * @param \Doctrine\ORM\Query\Parser $parser
52 public function parse(\Doctrine\ORM\Query\Parser $parser)
55 $parser->match(Lexer::T_IDENTIFIER);
56 $parser->match(Lexer::T_OPEN_PARENTHESIS);
58 $this->dateExpression = $parser->ArithmeticExpression();
60 $parser->match(Lexer::T_CLOSE_PARENTHESIS);