namibia
df0489e1eeeeab5a9bd44e1d84fce49924fe1bac
namibia / module / Utility / src / Utility / DoctrineFunction / DateFormat.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
<?php namespace UVd\DoctrineFunction; use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\AST\Functions\FunctionNode; /** * DateFormat * * Allows Doctrine 2.0 Query Language to execute a MySQL DATE_FORMAT function * You must boostrap this function in your ORM as a DQLFunction. * * * DATE_FORMAT(TIMESTAMP,'%format') : @link http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format * * * PLEASE REMEMBER TO CHECK YOUR NAMESPACE * * @link labs.ultravioletdesign.co.uk * @author Rob Squires <rob@ultravioletdesign.co.uk> * * */ class DateFormat extends FunctionNode { /* * holds the timestamp of the DATE_FORMAT DQL statement * @var mixed */ protected $dateExpression; /** * holds the '%format' parameter of the DATE_FORMAT DQL statement * @var string */ protected $formatChar; /** * getSql - allows ORM to inject a DATE_FORMAT() statement into an SQL string being constructed * @param \Doctrine\ORM\Query\SqlWalker $sqlWalker * @return void */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { return 'DATE_FORMAT(' . $sqlWalker->walkArithmeticExpression($this->dateExpression) . ','. $sqlWalker->walkStringPrimary($this->formatChar) . ')'; } /** * parse - allows DQL to breakdown the DQL string into a processable structure * @param \Doctrine\ORM\Query\Parser $parser */ public function parse(\Doctrine\ORM\Query\Parser $parser) { $parser->match(Lexer::T_IDENTIFIER); $parser->match(Lexer::T_OPEN_PARENTHESIS); $this->dateExpression = $parser->ArithmeticExpression(); $parser->match(Lexer::T_COMMA); $this->formatChar = $parser->StringPrimary(); $parser->match(Lexer::T_CLOSE_PARENTHESIS); } } |
Commits for namibiamodule/Utility/src/Utility/DoctrineFunction/DateFormat.php
Revision | Author | Commited | Message |
---|---|---|---|
df0489 ... | Mark | Fri 14 Oct, 2016 10:01:00 +0000 | initial commit |