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.9.0 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Quantum\Libraries\Database\Idiorm\Statements; |
16
|
|
|
|
17
|
|
|
use Quantum\Libraries\Database\DbalInterface; |
18
|
|
|
use Quantum\Exceptions\DatabaseException; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Trait Result |
22
|
|
|
* @package Quantum\Libraries\Database\Idiorm\Statements |
23
|
|
|
*/ |
24
|
|
|
trait Result |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @inheritDoc |
29
|
|
|
* @throws DatabaseException |
30
|
|
|
*/ |
31
|
|
|
public function get() |
32
|
|
|
{ |
33
|
|
|
return $this->getOrmModel()->find_many(); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @inheritDoc |
38
|
|
|
* @throws DatabaseException |
39
|
|
|
*/ |
40
|
|
|
public function findOne(int $id): DbalInterface |
41
|
|
|
{ |
42
|
|
|
$ormObject = $this->getOrmModel()->find_one($id); |
43
|
|
|
|
44
|
|
|
if ($ormObject) { |
45
|
|
|
$this->updateOrmModel($ormObject); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $this; |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @inheritDoc |
53
|
|
|
* @throws DatabaseException |
54
|
|
|
*/ |
55
|
|
|
public function findOneBy(string $column, $value): DbalInterface |
56
|
|
|
{ |
57
|
|
|
$ormObject = $this->getOrmModel()->where($column, $value)->find_one(); |
58
|
|
|
if ($ormObject) { |
59
|
|
|
$this->updateOrmModel($ormObject); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $this; |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @inheritDoc |
67
|
|
|
* @throws DatabaseException |
68
|
|
|
*/ |
69
|
|
|
public function first(): DbalInterface |
70
|
|
|
{ |
71
|
|
|
$ormObject = $this->getOrmModel()->find_one(); |
72
|
|
|
if ($ormObject) { |
73
|
|
|
$this->updateOrmModel($ormObject); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $this; |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @inheritDoc |
81
|
|
|
* @throws DatabaseException |
82
|
|
|
*/ |
83
|
|
|
public function count(): int |
84
|
|
|
{ |
85
|
|
|
return $this->getOrmModel()->count(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @inheritDoc |
90
|
|
|
* @throws DatabaseException |
91
|
|
|
*/ |
92
|
|
|
public function asArray(): array |
93
|
|
|
{ |
94
|
|
|
$result = $this->getOrmModel()->as_array(); |
95
|
|
|
|
96
|
|
|
if (count($this->hidden) > 0) { |
97
|
|
|
$result = $this->setHidden($result); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $result; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @inheritDoc |
105
|
|
|
*/ |
106
|
|
|
public function setHidden($result) |
107
|
|
|
{ |
108
|
|
|
return array_diff_key($result, array_flip($this->hidden)); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|