|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* AnimeDb package. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Peter Gribanov <[email protected]> |
|
6
|
|
|
* @copyright Copyright (c) 2011, Peter Gribanov |
|
7
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 GPL v3 |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace AnimeDb\Bundle\AppBundle\DQL; |
|
10
|
|
|
|
|
11
|
|
|
use Doctrine\ORM\Query\AST\Functions\FunctionNode; |
|
12
|
|
|
use Doctrine\ORM\Query\AST\SimpleArithmeticExpression; |
|
13
|
|
|
use Doctrine\ORM\Query\Lexer; |
|
14
|
|
|
use Doctrine\ORM\Query\SqlWalker; |
|
15
|
|
|
use Doctrine\ORM\Query\Parser; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Datetime. |
|
19
|
|
|
* |
|
20
|
|
|
* Datetime ::= "DATETIME" "(" ArithmeticPrimary "," ArithmeticPrimary ")" |
|
21
|
|
|
*/ |
|
22
|
|
|
class Datetime extends FunctionNode |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* First date expression. |
|
26
|
|
|
* |
|
27
|
|
|
* @var SimpleArithmeticExpression |
|
28
|
|
|
*/ |
|
29
|
|
|
private $firstDateExpression = null; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Second date expression. |
|
33
|
|
|
* |
|
34
|
|
|
* @var SimpleArithmeticExpression |
|
35
|
|
|
*/ |
|
36
|
|
|
private $secondDateExpression = null; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param Parser $parser |
|
40
|
|
|
*/ |
|
41
|
|
|
public function parse(Parser $parser) |
|
42
|
|
|
{ |
|
43
|
|
|
$parser->match(Lexer::T_IDENTIFIER); |
|
44
|
|
|
$parser->match(Lexer::T_OPEN_PARENTHESIS); |
|
45
|
|
|
$this->firstDateExpression = $parser->ArithmeticPrimary(); |
|
46
|
|
|
$parser->match(Lexer::T_COMMA); |
|
47
|
|
|
$this->secondDateExpression = $parser->ArithmeticPrimary(); |
|
48
|
|
|
$parser->match(Lexer::T_CLOSE_PARENTHESIS); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param SqlWalker $sqlWalker |
|
53
|
|
|
* |
|
54
|
|
|
* @return string |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getSql(SqlWalker $sqlWalker) |
|
57
|
|
|
{ |
|
58
|
|
|
return sprintf( |
|
59
|
|
|
'DATETIME(%s, %s)', |
|
60
|
|
|
$this->firstDateExpression->dispatch($sqlWalker), |
|
61
|
|
|
$this->secondDateExpression->dispatch($sqlWalker) |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|