Test Failed
Pull Request — master (#96)
by Jean-Christophe
13:01
created

DAOPreparedQueryAll::execute()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 21
rs 9.7
cc 3
nc 4
nop 2
1
<?php
2
3
namespace Ubiquity\orm\core\prepared;
4
5
use Ubiquity\db\SqlUtils;
6
use Ubiquity\events\DAOEvents;
7
use Ubiquity\events\EventsManager;
8
use Ubiquity\orm\OrmUtils;
9
use Ubiquity\orm\DAO;
10
11
/**
12
 * Ubiquity\orm\core\prepared$DAOPreparedQueryOne
13
 * This class is part of Ubiquity
14
 *
15
 * @author jcheron <[email protected]>
16
 * @version 1.0.0
17
 *
18
 */
19
class DAOPreparedQueryAll extends DAOPreparedQuery {
20
21
	protected function prepare() {
22
		$this->conditionParser->setCondition ( $this->condition );
23
		parent::prepare ();
24
	}
25
26
	public function execute($params = [], $useCache = false) {
27
		$objects = array ();
28
		$invertedJoinColumns = null;
29
30
		$cp = $this->conditionParser;
31
		$cp->setParams ( $params );
32
		$className = $this->className;
33
		$query = $this->db->prepareAndExecute ( $this->tableName, SqlUtils::checkWhere ( $cp->getCondition () ), $this->fieldList, $cp->getParams (), $useCache );
34
		$oneToManyQueries = [ ];
35
		$manyToOneQueries = [ ];
36
		$manyToManyParsers = [ ];
37
		foreach ( $query as $row ) {
38
			$object = DAO::_loadObjectFromRow ( $row, $className, $invertedJoinColumns, $manyToOneQueries, $this->oneToManyFields, $this->manyToManyFields, $oneToManyQueries, $manyToManyParsers, $this->accessors, $this->transformers );
39
			$key = OrmUtils::getPropKeyValues ( $object, $this->propsKeys );
40
			$objects [$key] = $object;
41
		}
42
		if ($this->hasIncluded) {
43
			DAO::_affectsRelationObjects ( $className, $this->firstPropKey, $manyToOneQueries, $oneToManyQueries, $manyToManyParsers, $objects, $this->included, $useCache );
44
		}
45
		EventsManager::trigger ( DAOEvents::GET_ALL, $objects, $className );
46
		return $objects;
47
	}
48
}
49
50