3 namespace DataAccess\DataMapper\Helpers
;
14 public function __construct($voName, $accessor, $tableName)
16 $this->_voName
= $voName;
19 $this->_tableName
= $tableName;
21 $this->_tableName
= strtolower($voName);
26 $this->_accessor
= $accessor;
29 $this->_accessor
= 'get'. str_replace('_', '', $voName);
33 public function getAccessor()
35 return $this->_accessor
;
38 public function getVOName()
40 return $this->_voName
;
43 public function getTableName()
45 return $this->_tableName
;
48 public function populate($maps, $db, $parent, $row)
50 $className = $maps[$this->_voName
]['class'];
51 $table = $maps[$this->_voName
]['table'];
53 // If the table we already have contains the id of a row we need in
55 //if(isset($row[$this->_tableName . '_id'])) {
56 if($row && array_key_exists($this->_tableName
. '_id', $row)) { //this is a better choice as somtimes the array key is set, but is equal to null, and isset doesn't like that
57 $join_id = $row[$this->_tableName
. '_id'];
58 $statement = $db->prepare(sprintf('SELECT * from %s WHERE id=%u',
62 $statement->execute();
63 $row = $statement->fetch();
64 } elseif($maps[$this->_voName
]['table'] != $maps[$parent]['table']) {
65 // in this case we look in another table for this row's id
66 $join_id = $row['id'];
67 $statement = $db->prepare(sprintf('SELECT * from %s WHERE %s=%u',
69 strtolower($parent . '_id'),
73 $statement->execute();
74 $row = $statement->fetch();
77 $constructors = AbstractPopulationHelper
::getConstrutorArray($maps, $this->_voName
, $row, $db);
79 if(count($constructors) == 0)
81 return new $className;
84 $r = new ReflectionClass($className);
85 return $r->newInstanceArgs($constructors);
86 } catch (Exception
$e) {