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\DAO; |
9
|
|
|
use Ubiquity\orm\OrmUtils; |
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 DAOPreparedQueryById extends DAOPreparedQuery { |
20
|
|
|
|
21
|
|
|
public function __construct($className, $included = false) { |
22
|
|
|
parent::__construct ( $className, '', $included ); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
protected function prepare() { |
26
|
|
|
parent::prepare (); |
27
|
|
|
$keys = OrmUtils::getKeyFields ( $this->className ); |
28
|
|
|
$this->conditionParser->addKeyValues ( \array_fill ( 0, \count ( $keys ), '' ), $this->className ); |
|
|
|
|
29
|
|
|
$this->conditionParser->limitOne (); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function execute($params = [], $useCache = false) { |
33
|
|
|
$cp = $this->conditionParser; |
34
|
|
|
$cp->setKeyValues ( $params ); |
35
|
|
|
$query = $this->db->prepareAndExecute ( $this->tableName, SqlUtils::checkWhere ( $cp->getCondition () ), $this->fieldList, $cp->getParams (), $useCache ); |
36
|
|
|
if ($query && \sizeof ( $query ) > 0) { |
|
|
|
|
37
|
|
|
$oneToManyQueries = [ ]; |
38
|
|
|
$manyToOneQueries = [ ]; |
39
|
|
|
$manyToManyParsers = [ ]; |
40
|
|
|
$className = $this->className; |
41
|
|
|
$object = DAO::_loadObjectFromRow ( \current ( $query ), $className, $this->invertedJoinColumns, $manyToOneQueries, $this->oneToManyFields, $this->manyToManyFields, $oneToManyQueries, $manyToManyParsers, $this->accessors, $this->transformers ); |
42
|
|
|
if ($this->hasIncluded) { |
43
|
|
|
DAO::_affectsRelationObjects ( $className, $this->firstPropKey, $manyToOneQueries, $oneToManyQueries, $manyToManyParsers, [ $object ], $this->included, $useCache ); |
44
|
|
|
} |
45
|
|
|
EventsManager::trigger ( DAOEvents::GET_ONE, $object, $className ); |
46
|
|
|
} |
47
|
|
|
return $object; |
|
|
|
|
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|