Commit a0beed0a authored by zYne's avatar zYne

--no commit message

--no commit message
parent ac34484c
......@@ -32,7 +32,7 @@ Doctrine::autoload('Doctrine_Access');
* @version $Revision: 1255 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
abstract class Doctrine_Hydrate2 extends Doctrine_Access
class Doctrine_Hydrate2 extends Doctrine_Access
{
/**
* QUERY TYPE CONSTANTS
......@@ -177,12 +177,6 @@ abstract class Doctrine_Hydrate2 extends Doctrine_Access
return $obj;
}
/**
* getQuery
*
* @return string
*/
abstract public function getQuery();
/**
* limitSubqueryUsed
*
......@@ -284,13 +278,12 @@ abstract class Doctrine_Hydrate2 extends Doctrine_Access
$this->params = $params;
}
/**
* execute
* executes the dql query and populates all collections
* _fetch
*
*
* @param string $params
* @return Doctrine_Collection the root collection
*/
public function execute($params = array(), $return = Doctrine::FETCH_RECORD) {
public function _fetch($params = array(), $return = Doctrine::FETCH_RECORD)
{
$params = $this->conn->convertBooleans(array_merge($this->params, $params));
if ( ! $this->view) {
......@@ -306,28 +299,68 @@ abstract class Doctrine_Hydrate2 extends Doctrine_Access
}
$stmt = $this->conn->execute($query, $params);
if (count($this->tables) == 0) {
throw new Doctrine_Query_Exception('No components selected');
}
$keys = array_keys($this->tables);
$root = $keys[0];
$previd = array();
return $this->parseData($stmt);
}
public function setAliasMap($map)
{
$this->_aliasMap = $map;
}
public function getAliasMap()
{
return $this->_aliasMap;
}
/**
* execute
* executes the dql query and populates all collections
*
* @param string $params
* @return Doctrine_Collection the root collection
*/
public function execute($params = array(), $return = Doctrine::FETCH_RECORD)
{
$array = $this->_fetch($params = array(), $return = Doctrine::FETCH_RECORD);
$coll = $this->getCollection($root);
$coll = new Doctrine_Collection(key($this->_aliasMap));
$prev[$root] = $coll;
if ($this->aggregate) {
$return = Doctrine::FETCH_ARRAY;
$previd = array();
/**
* iterate over the fetched data
* here $data is a two dimensional array
*/
foreach ($array as $data) {
/**
* remove duplicated data rows and map data into objects
*/
foreach ($data as $key => $row) {
if (empty($row)) {
continue;
}
}
}
}
/**
* execute
* executes the dql query and populates all collections
*
* @param string $params
* @return Doctrine_Collection the root collection
*/
public function execute2($params = array(), $return = Doctrine::FETCH_RECORD) {
$array = $this->_fetch($params = array(), $return = Doctrine::FETCH_RECORD);
$array = $this->parseData($stmt);
if ($return == Doctrine::FETCH_ARRAY) {
return $array;
}
$keys = array_keys($this->tables);
$root = $keys[0];
$previd = array();
/**
* iterate over the fetched data
* here $data is a two dimensional array
*/
foreach ($array as $data) {
/**
* remove duplicated data rows and map data into objects
......@@ -628,10 +661,10 @@ abstract class Doctrine_Hydrate2 extends Doctrine_Access
foreach ($data as $key => $value) {
$e = explode('__', $key);
$field = strtolower(array_pop($e));
$component = strtolower(implode('__', $e));
$field = strtolower(array_pop($e));
$tableAlias = strtolower(implode('__', $e));
$data[$component][$field] = $value;
$data[$tableAlias][$field] = $value;
unset($data[$key]);
}
......
......@@ -22,7 +22,7 @@
require_once('../draft/new-core/Record.php');
require_once('../draft/new-core/Hydrate.php');
require_once('../draft/new-core/Query.php');
require_once('../draft/new-core/Query.php');
require_once('../draft/new-core/Collection.php');
/**
......@@ -42,7 +42,36 @@ class Doctrine_NewCore_TestCase extends Doctrine_UnitTestCase
{
public function testHydrate()
{
$q = new Doctrine_Query2();
$q->from('User u LEFT JOIN u.Phonenumber p')->execute();
$h = new Doctrine_Hydrate_Mock();
$h->setData(array(
array(
'e' => array('id' => 1, 'name' => 'zYne'),
'p' => array('id' => 1, 'phonenumber' => '123 123', 'user_id' => 1)
),
array(
'e' => array('id' => 2, 'name' => 'John'),
'p' => array('id' => 2, 'phonenumber' => '222 222', 'user_id' => 2)
),
array(
'e' => array('id' => 3, 'name' => 'Arnold'),
'p' => array('id' => 3, 'phonenumber' => '333 333', 'user_id' => 3)
)
)
);
$h->setAliasMap(array('u' => array('table' => $this->conn->getTable('User'))));
}
}
class Doctrine_Hydrate_Mock extends Doctrine_Hydrate2
{
protected $data;
public function setData($data)
{
$this->data = $data;
}
public function _fetch($params = array(), $return = Doctrine::FETCH_RECORD)
{
return $this->data;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment