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