1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Quantum PHP Framework |
5
|
|
|
* |
6
|
|
|
* An open source software development framework for PHP |
7
|
|
|
* |
8
|
|
|
* @package Quantum |
9
|
|
|
* @author Arman Ag. <[email protected]> |
10
|
|
|
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) |
11
|
|
|
* @link http://quantum.softberg.org/ |
12
|
|
|
* @since 2.6.0 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Quantum\Libraries\Database\Idiorm\Statements; |
16
|
|
|
|
17
|
|
|
use Quantum\Libraries\Database\Idiorm\IdiormPatch; |
18
|
|
|
use Quantum\Mvc\QtModel; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Trait Join |
22
|
|
|
* @package Quantum\Libraries\Database\Idiorm\Statements |
23
|
|
|
*/ |
24
|
|
|
trait Join |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @inheritDoc |
29
|
|
|
*/ |
30
|
|
|
public function join(string $table, array $constraint, string $tableAlias = null): object |
31
|
|
|
{ |
32
|
|
|
return $this->getOrmModel()->join($table, $constraint, $tableAlias); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @inheritDoc |
37
|
|
|
*/ |
38
|
|
|
public function innerJoin(string $table, array $constraint, ?string $tableAlias = null): object |
39
|
|
|
{ |
40
|
|
|
return $this->getOrmModel()->inner_join($table, $constraint, $tableAlias); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @inheritDoc |
45
|
|
|
*/ |
46
|
|
|
public function leftJoin(string $table, array $constraint, ?string $tableAlias = null): object |
47
|
|
|
{ |
48
|
|
|
return IdiormPatch::getInstance()->use($this->getOrmModel())->leftJoin($table, $constraint, $tableAlias); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @inheritDoc |
53
|
|
|
*/ |
54
|
|
|
public function rightJoin(string $table, array $constraint, ?string $tableAlias = null): object |
55
|
|
|
{ |
56
|
|
|
return IdiormPatch::getInstance()->use($this->getOrmModel())->rightJoin($table, $constraint, $tableAlias); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @inheritDoc |
61
|
|
|
*/ |
62
|
|
|
public function joinTo(QtModel $model, bool $switch = true): object |
63
|
|
|
{ |
64
|
|
|
$resultObject = $this->getOrmModel()->join($model->table, |
65
|
|
|
[ |
66
|
|
|
$model->table . '.' . $model->foreignKeys[$this->table], |
67
|
|
|
'=', |
68
|
|
|
$this->table . '.' . $this->idColumn |
69
|
|
|
] |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
if ($switch) { |
73
|
|
|
$this->table = $model->table; |
|
|
|
|
74
|
|
|
$this->idColumn = $model->idColumn; |
|
|
|
|
75
|
|
|
$this->foreignKeys = $model->foreignKeys; |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $resultObject; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @inheritDoc |
83
|
|
|
*/ |
84
|
|
|
public function joinThrough(QtModel $model, bool $switch = true): object |
85
|
|
|
{ |
86
|
|
|
$resultObject = $this->getOrmModel()->join($model->table, |
87
|
|
|
[ |
88
|
|
|
$model->table . '.' . $model->idColumn, |
89
|
|
|
'=', |
90
|
|
|
$this->table . '.' . $this->foreignKeys[$model->table] |
91
|
|
|
] |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
if ($switch) { |
95
|
|
|
$this->table = $model->table; |
|
|
|
|
96
|
|
|
$this->idColumn = $model->idColumn; |
|
|
|
|
97
|
|
|
$this->foreignKeys = $model->foreignKeys; |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $resultObject; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
} |