1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BfwSql\Queries\Parts; |
4
|
|
|
|
5
|
|
|
class JoinList extends AbstractList |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* {@inheritdoc} |
9
|
|
|
*/ |
10
|
|
|
protected $separator = "\n"; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* {@inheritdoc} |
14
|
|
|
*/ |
15
|
|
|
protected $usePartPrefix = false; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var boolean $columnsWithValue If columns should have a value |
19
|
|
|
*/ |
20
|
|
|
protected $columnsWithValue = false; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Getter accessor to property columnsWithValue |
24
|
|
|
* |
25
|
|
|
* @return bool |
26
|
|
|
*/ |
27
|
|
|
public function getColumnsWithValue(): bool |
28
|
|
|
{ |
29
|
|
|
return $this->columnsWithValue; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Setter accessor to property columnsWithValue |
34
|
|
|
* |
35
|
|
|
* @param bool $columnsWithValue |
36
|
|
|
* |
37
|
|
|
* @return $this |
38
|
|
|
*/ |
39
|
|
|
public function setColumnsWithValue(bool $columnsWithValue): self |
40
|
|
|
{ |
41
|
|
|
$this->columnsWithValue = $columnsWithValue; |
42
|
|
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Magic method __invoke, used when the user call object like a function |
47
|
|
|
* @link http://php.net/manual/en/language.oop5.magic.php#object.invoke |
48
|
|
|
* |
49
|
|
|
* @param string|array $nameInfos The name (and shortcut) of the table |
50
|
|
|
* @param string $on The ON condition used by the join |
51
|
|
|
* @param string|array|null $columns Columns of this table to use |
52
|
|
|
* into the request |
53
|
|
|
* |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
|
|
public function __invoke($nameInfos, string $on, $columns = null) |
57
|
|
|
{ |
58
|
|
|
$join = new Join($this->querySystem); |
59
|
|
|
$join->setColumnsWithValue($this->columnsWithValue); |
60
|
|
|
$join->__invoke($nameInfos, $columns, $on); |
61
|
|
|
|
62
|
|
|
$this->list[] = $join; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
|
|
public function generate(): string |
69
|
|
|
{ |
70
|
|
|
$sqlPart = ''; |
71
|
|
|
|
72
|
|
|
foreach ($this->list as $index => $join) { |
73
|
|
|
if ($index > 0) { |
74
|
|
|
$sqlPart .= $this->separator; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$sqlPart .= $this->partPrefix.' '.$join->generate(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $sqlPart; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|