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