1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Phuria SQL Builder package. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2016 Beniamin Jonatan Šimko |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Phuria\QueryBuilder\ExprBuilder; |
13
|
|
|
|
14
|
|
|
use Phuria\QueryBuilder\ExprBuilder; |
15
|
|
|
use Phuria\QueryBuilder\Expression\ExpressionInterface; |
16
|
|
|
use Phuria\QueryBuilder\Expression\FunctionCallContext; |
17
|
|
|
use Phuria\QueryBuilder\Expression\FunctionExpression; |
18
|
|
|
use Phuria\QueryBuilder\ExprNormalizer; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Beniamin Jonatan Šimko <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
trait DateTimeTrait |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @param string $functionName |
27
|
|
|
* @param FunctionCallContext|null $context |
28
|
|
|
* |
29
|
|
|
* @return ExprBuilder |
30
|
|
|
*/ |
31
|
|
|
abstract public function func($functionName, FunctionCallContext $context = null); |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return ExpressionInterface |
35
|
|
|
*/ |
36
|
|
|
abstract public function getWrappedExpression(); |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param mixed $expression |
40
|
|
|
* |
41
|
|
|
* @return ExprBuilder |
42
|
|
|
*/ |
43
|
|
|
public function addDate($expression) |
44
|
|
|
{ |
45
|
|
|
return new ExprBuilder(new FunctionExpression( |
46
|
|
|
FunctionExpression::FUNC_ADDDATE, |
47
|
|
|
ExprNormalizer::normalizeExpression([$this->getWrappedExpression(), $expression]) |
48
|
|
|
)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param mixed $expression |
53
|
|
|
* |
54
|
|
|
* @return ExprBuilder |
55
|
|
|
*/ |
56
|
|
|
public function addTime($expression) |
57
|
|
|
{ |
58
|
|
|
return new ExprBuilder(new FunctionExpression( |
59
|
|
|
FunctionExpression::FUNC_ADDTIME, |
60
|
|
|
ExprNormalizer::normalizeExpression([$this->getWrappedExpression(), $expression]) |
61
|
|
|
)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return ExprBuilder |
66
|
|
|
*/ |
67
|
1 |
|
public function year() |
68
|
|
|
{ |
69
|
1 |
|
return $this->func(FunctionExpression::FUNC_YEAR); |
70
|
|
|
} |
71
|
|
|
} |