|
1
|
|
|
<?php |
|
2
|
|
|
namespace Ubiquity\orm\core\prepared; |
|
3
|
|
|
|
|
4
|
|
|
use Ubiquity\events\DAOEvents; |
|
5
|
|
|
use Ubiquity\events\EventsManager; |
|
6
|
|
|
use Ubiquity\orm\OrmUtils; |
|
7
|
|
|
use Ubiquity\orm\DAO; |
|
8
|
|
|
use Ubiquity\cache\database\DbCache; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Ubiquity\orm\core\prepared$DAOPreparedQueryAll |
|
12
|
|
|
* This class is part of Ubiquity |
|
13
|
|
|
* |
|
14
|
|
|
* @author jcheron <[email protected]> |
|
15
|
|
|
* @version 1.0.6 |
|
16
|
|
|
* |
|
17
|
|
|
*/ |
|
18
|
|
|
class DAOPreparedQueryAll extends DAOPreparedQuery { |
|
19
|
|
|
|
|
20
|
28 |
|
protected function prepare(?DbCache $cache = null) { |
|
21
|
28 |
|
$this->conditionParser->setCondition($this->condition); |
|
22
|
28 |
|
parent::prepare($cache); |
|
23
|
28 |
|
$this->updatePrepareStatement(); |
|
24
|
28 |
|
} |
|
25
|
|
|
|
|
26
|
1 |
|
public function execute($params = [], $useCache = false) { |
|
27
|
1 |
|
if ($useCache) { |
|
28
|
|
|
$rows = $this->db->_optExecuteAndFetch($this->statement, $this->tableName, $this->preparedCondition, $params, $useCache); |
|
29
|
|
|
} else { |
|
30
|
1 |
|
$rows = $this->db->_optExecuteAndFetchNoCache($this->statement, $params); |
|
31
|
|
|
} |
|
32
|
1 |
|
if ($this->hasIncluded || ! $this->allPublic) { |
|
33
|
1 |
|
return $this->_parseQueryResponseWithIncluded($rows, $this->className, $useCache); |
|
34
|
|
|
} |
|
35
|
|
|
return $this->_parseQueryResponse($rows, $this->className); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
protected function _parseQueryResponse($rows, $className) { |
|
39
|
|
|
$objects = []; |
|
40
|
|
|
if ($this->additionalMembers) { |
|
41
|
|
|
foreach ($rows as $row) { |
|
42
|
|
|
$object = DAO::_loadSimpleObjectFromRow($this->db, $row, $className, $this->memberList, $this->transformers); |
|
43
|
|
|
$this->addAditionnalMembers($object, $row); |
|
44
|
|
|
$objects[OrmUtils::getPropKeyValues($object, $this->propsKeys)] = $object; |
|
45
|
|
|
} |
|
46
|
|
|
} else { |
|
47
|
|
|
foreach ($rows as $row) { |
|
48
|
|
|
$object = DAO::_loadSimpleObjectFromRow($this->db, $row, $className, $this->memberList, $this->transformers); |
|
49
|
|
|
$objects[OrmUtils::getPropKeyValues($object, $this->propsKeys)] = $object; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
EventsManager::trigger(DAOEvents::GET_ALL, $objects, $className); |
|
53
|
|
|
return $objects; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
1 |
|
protected function _parseQueryResponseWithIncluded($rows, $className, $useCache) { |
|
57
|
1 |
|
$objects = []; |
|
58
|
1 |
|
$invertedJoinColumns = null; |
|
59
|
|
|
|
|
60
|
1 |
|
$oneToManyQueries = $manyToOneQueries = $manyToManyParsers = []; |
|
61
|
1 |
|
foreach ($rows as $row) { |
|
62
|
1 |
|
$object = DAO::_loadObjectFromRow($this->db, $row, $className, $invertedJoinColumns, $manyToOneQueries, $this->oneToManyFields, $this->manyToManyFields, $oneToManyQueries, $manyToManyParsers, $this->memberList, $this->accessors, $this->transformers); |
|
63
|
1 |
|
$key = OrmUtils::getPropKeyValues($object, $this->propsKeys); |
|
64
|
1 |
|
if ($this->additionalMembers) { |
|
65
|
|
|
$this->addAditionnalMembers($object, $row); |
|
66
|
|
|
} |
|
67
|
1 |
|
$objects[$key] = $object; |
|
68
|
|
|
} |
|
69
|
1 |
|
DAO::_affectsRelationObjects($className, $this->firstPropKey, $manyToOneQueries, $oneToManyQueries, $manyToManyParsers, $objects, $this->included, $useCache); |
|
70
|
1 |
|
EventsManager::trigger(DAOEvents::GET_ALL, $objects, $className); |
|
71
|
1 |
|
return $objects; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|