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