3 namespace DataAccess\DataMapper\Helpers
;
13 public function __construct($voName, $accessor, $tableName)
15 $this->_voName
= $voName;
18 $this->_tableName
= $tableName;
20 $this->_tableName
= strtolower($voName);
25 $this->_accessor
= $accessor;
28 $this->_accessor
= 'get'. str_replace('_', '', $voName);
32 public function getAccessor()
34 return $this->_accessor
;
37 public function getVOName()
39 return $this->_voName
;
42 public function getTableName()
44 return $this->_tableName
;
47 public function populate($maps, $db, $parent, $row)
49 $className = $maps[$this->_voName
]['class'];
50 $table = $maps[$this->_voName
]['table'];
52 // If the table we already have contains the id of a row we need in
54 //if(isset($row[$this->_tableName . '_id'])) {
55 if(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
56 $join_id = $row[$this->_tableName
. '_id'];
57 $statement = $db->prepare(sprintf('SELECT * from %s WHERE id=%u',
61 $statement->execute();
62 $row = $statement->fetch();
63 } elseif($maps[$this->_voName
]['table'] != $maps[$parent]['table']) {
64 // in this case we look in another table for this row's id
65 $join_id = $row['id'];
66 $statement = $db->prepare(sprintf('SELECT * from %s WHERE %s=%u',
68 strtolower($parent . '_id'),
72 $statement->execute();
73 $row = $statement->fetch();
76 $constructors = AbstractPopulationHelper
::getConstrutorArray($maps, $this->_voName
, $row, $db);
78 if(count($constructors) == 0)
80 return new $className;
82 $r = new ReflectionClass($className);
83 return $r->newInstanceArgs($constructors);