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 DATE_FORMAT function
12 * You must boostrap this function in your ORM as a DQLFunction.
15 * DATE_FORMAT(TIMESTAMP,'%format') : @link http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format
18 * PLEASE REMEMBER TO CHECK YOUR NAMESPACE
20 * @link labs.ultravioletdesign.co.uk
21 * @author Rob Squires <rob@ultravioletdesign.co.uk>
25 class DateFormat extends FunctionNode {
28 * holds the timestamp of the DATE_FORMAT DQL statement
31 protected $dateExpression;
34 * holds the '%format' parameter of the DATE_FORMAT DQL statement
37 protected $formatChar;
40 * getSql - allows ORM to inject a DATE_FORMAT() statement into an SQL string being constructed
41 * @param \Doctrine\ORM\Query\SqlWalker $sqlWalker
44 public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
46 return 'DATE_FORMAT(' .
47 $sqlWalker->walkArithmeticExpression($this->dateExpression) .
49 $sqlWalker->walkStringPrimary($this->formatChar) .
55 * parse - allows DQL to breakdown the DQL string into a processable structure
56 * @param \Doctrine\ORM\Query\Parser $parser
58 public function parse(\Doctrine\ORM\Query\Parser $parser)
61 $parser->match(Lexer::T_IDENTIFIER);
62 $parser->match(Lexer::T_OPEN_PARENTHESIS);
64 $this->dateExpression = $parser->ArithmeticExpression();
65 $parser->match(Lexer::T_COMMA);
68 $this->formatChar = $parser->StringPrimary();
69 $parser->match(Lexer::T_CLOSE_PARENTHESIS);