1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Phossa Project |
4
|
|
|
* |
5
|
|
|
* PHP version 5.4 |
6
|
|
|
* |
7
|
|
|
* @category Library |
8
|
|
|
* @package Phossa2\Query |
9
|
|
|
* @copyright Copyright (c) 2016 phossa.com |
10
|
|
|
* @license http://mit-license.org/ MIT License |
11
|
|
|
* @link http://www.phossa.com/ |
12
|
|
|
*/ |
13
|
|
|
/*# declare(strict_types=1); */ |
14
|
|
|
|
15
|
|
|
namespace Phossa2\Query\Traits\Clause; |
16
|
|
|
|
17
|
|
|
use Phossa2\Query\Misc\Template; |
18
|
|
|
use Phossa2\Query\Interfaces\Clause\WhereInterface; |
19
|
|
|
use Phossa2\Query\Interfaces\Clause\HavingInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* HavingTrait |
23
|
|
|
* |
24
|
|
|
* Implementation of HavingInterface |
25
|
|
|
* |
26
|
|
|
* @package Phossa2\Query |
27
|
|
|
* @author Hong Zhang <[email protected]> |
28
|
|
|
* @see HavingInterface |
29
|
|
|
* @version 2.0.0 |
30
|
|
|
* @since 2.0.0 added |
31
|
|
|
*/ |
32
|
|
|
trait HavingTrait |
33
|
|
|
{ |
34
|
|
|
use AbstractTrait; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritDoc} |
38
|
|
|
*/ |
39
|
|
|
public function having( |
40
|
|
|
$col, |
41
|
|
|
$operator = WhereInterface::NO_OPERATOR, |
42
|
|
|
$value = WhereInterface::NO_VALUE |
43
|
|
|
) { |
44
|
|
|
return $this->realWhere($col, $operator, $value, true, false, false, 'HAVING'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritDoc} |
49
|
|
|
*/ |
50
|
|
View Code Duplication |
public function havingTpl(/*# string */ $template, $col, array $params = []) |
51
|
|
|
{ |
52
|
|
|
$template = $this->positionedParam($template, $params); |
53
|
|
|
return $this->realWhere( |
54
|
|
|
new Template($template, $col), |
55
|
|
|
WhereInterface::NO_OPERATOR, |
56
|
|
|
WhereInterface::NO_VALUE, |
57
|
|
|
true, |
58
|
|
|
false, |
59
|
|
|
true, |
60
|
|
|
'HAVING' |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritDoc} |
66
|
|
|
*/ |
67
|
|
View Code Duplication |
public function havingRaw(/*# string */ $rawString, array $params = []) |
68
|
|
|
{ |
69
|
|
|
$rawString = $this->positionedParam($rawString, $params); |
70
|
|
|
return $this->realWhere( |
71
|
|
|
$rawString, |
72
|
|
|
WhereInterface::NO_OPERATOR, |
73
|
|
|
WhereInterface::NO_VALUE, |
74
|
|
|
true, |
75
|
|
|
false, |
76
|
|
|
true, |
77
|
|
|
'HAVING' |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Build HAVING |
83
|
|
|
* |
84
|
|
|
* @param string $prefix |
85
|
|
|
* @param array $settings |
86
|
|
|
* @return string |
87
|
|
|
* @access protected |
88
|
|
|
*/ |
89
|
|
|
protected function buildHaving( |
90
|
|
|
/*# string */ $prefix, |
91
|
|
|
array $settings |
92
|
|
|
)/*# : string */ { |
93
|
|
|
return $this->buildWhere($prefix, $settings); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
// in WhereTrait |
97
|
|
|
abstract protected function buildWhere( |
98
|
|
|
/*# string */ $prefix, |
99
|
|
|
array $settings |
100
|
|
|
)/*# : string */; |
101
|
|
|
abstract protected function realWhere( |
102
|
|
|
$col, |
103
|
|
|
$operator = WhereInterface::NO_OPERATOR, |
104
|
|
|
$value = WhereInterface::NO_VALUE, |
105
|
|
|
/*# bool */ $logicAnd = true, |
106
|
|
|
/*# bool */ $whereNot = false, |
107
|
|
|
/*# bool */ $rawMode = false, |
108
|
|
|
/*# string */ $clause = 'WHERE' |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|