Throwing tracks into the mix because I can,lol
Dumby array:
$arrResult = array(
array('albums_id'=>2,'artists_name'=>'One-X','artists_id'=>4,'albums_name'=>'Three Days Grace','tracks_id'=>23,'title'=>'It\\'s All Over')
,array('albums_id'=>2,'artists_name'=>'One-X','artists_id'=>4,'albums_name'=>'Three Days Grace','tracks_id'=>455,'title'=>'Pain')
,array('albums_id'=>2,'artists_name'=>'One-X','artists_id'=>4,'albums_name'=>'Three Days Grace','tracks_id'=>67,'title'=>'Animal I Have Become')
,array('albums_id'=>2,'artists_name'=>'One-X','artists_id'=>4,'albums_name'=>'Three Days Grace','tracks_id'=>390,'title'=>'Never Too Late')
,array('albums_id'=>2,'artists_name'=>'One-X','artists_id'=>4,'albums_name'=>'Three Days Grace','tracks_id'=>43789,'title'=>'On My Own')
,array('albums_id'=>2,'artists_name'=>'One-X','artists_id'=>4,'albums_name'=>'Three Days Grace','tracks_id'=>123,'title'=>'Riot')
,array('albums_id'=>2,'artists_name'=>'One-X','artists_id'=>4,'albums_name'=>'Three Days Grace','tracks_id'=>54,'title'=>'Get Out Alive')
,array('albums_id'=>2,'artists_name'=>'One-X','artists_id'=>4,'albums_name'=>'Three Days Grace','tracks_id'=>14,'title'=>'Let it Die')
,array('albums_id'=>2,'artists_name'=>'One-X','artists_id'=>4,'albums_name'=>'Three Days Grace','tracks_id'=>3400,'title'=>'Over and Over')
,array('albums_id'=>2,'artists_name'=>'One-X','artists_id'=>4,'albums_name'=>'Three Days Grace','tracks_id'=>4678,'title'=>'Gone Forever')
,array('albums_id'=>2,'artists_name'=>'One-X','artists_id'=>4,'albums_name'=>'Three Days Grace','tracks_id'=>4278,'title'=>'One X')
,array('albums_id'=>56,'artists_name'=>'Sum 41','artists_id'=>57,'albums_name'=>'Underclass Hero','tracks_id'=>78,'title'=>'March of the Dogs')
,array('albums_id'=>412,'artists_name'=>'Taproot','artists_id'=>32,'albums_name'=>'Blue-Sky Research','tracks_id'=>1,'title'=>'I Will Not Fall For You')
,array('albums_id'=>412,'artists_name'=>'Taproot','artists_id'=>32,'albums_name'=>'Blue-Sky Research','tracks_id'=>3,'title'=>'Violent Seas')
,array('albums_id'=>412,'artists_name'=>'Taproot','artists_id'=>32,'albums_name'=>'Blue-Sky Research','tracks_id'=>7,'title'=>'Birthday')
,array('albums_id'=>412,'artists_name'=>'Taproot','artists_id'=>32,'albums_name'=>'Blue-Sky Research','tracks_id'=>9,'title'=>'Facepeeler')
,array('albums_id'=>412,'artists_name'=>'Taproot','artists_id'=>32,'albums_name'=>'Blue-Sky Research','tracks_id'=>11,'title'=>'Calling')
,array('albums_id'=>412,'artists_name'=>'Taproot','artists_id'=>32,'albums_name'=>'Blue-Sky Research','tracks_id'=>13,'title'=>'Forever Endevor')
,array('albums_id'=>412,'artists_name'=>'Taproot','artists_id'=>32,'albums_name'=>'Blue-Sky Research','tracks_id'=>17,'title'=>'Lost In The Woods')
,array('albums_id'=>412,'artists_name'=>'Taproot','artists_id'=>32,'albums_name'=>'Blue-Sky Research','tracks_id'=>19,'title'=>'So Eager')
,array('albums_id'=>412,'artists_name'=>'Taproot','artists_id'=>32,'albums_name'=>'Blue-Sky Research','tracks_id'=>21,'title'=>'She')
,array('albums_id'=>412,'artists_name'=>'Taproot','artists_id'=>32,'albums_name'=>'Blue-Sky Research','tracks_id'=>267,'title'=>'Promise')
,array('albums_id'=>412,'artists_name'=>'Taproot','artists_id'=>32,'albums_name'=>'Blue-Sky Research','tracks_id'=>25,'title'=>'Nightmare')
,array('albums_id'=>412,'artists_name'=>'Taproot','artists_id'=>32,'albums_name'=>'Blue-Sky Research','tracks_id'=>27,'title'=>'Bly-Sky Research')
,array('albums_id'=>56,'artists_name'=>'Sum 41','artists_id'=>57,'albums_name'=>'Underclass Hero','tracks_id'=>29,'title'=>'Underclass Hero')
,array('albums_id'=>56,'artists_name'=>'Sum 41','artists_id'=>57,'albums_name'=>'Underclass Hero','tracks_id'=>31,'title'=>'Walking Disaster')
,array('albums_id'=>56,'artists_name'=>'Sum 41','artists_id'=>57,'albums_name'=>'Underclass Hero','tracks_id'=>33,'title'=>'Speak of The Devil')
,array('albums_id'=>56,'artists_name'=>'Sum 41','artists_id'=>57,'albums_name'=>'Underclass Hero','tracks_id'=>36,'title'=>'Dear Father')
,array('albums_id'=>56,'artists_name'=>'Sum 41','artists_id'=>57,'albums_name'=>'Underclass Hero','tracks_id'=>37,'title'=>'Count Your Blessings')
,array('albums_id'=>56,'artists_name'=>'Sum 41','artists_id'=>57,'albums_name'=>'Underclass Hero','tracks_id'=>78,'title'=>'Ma Poubelle')
,array('albums_id'=>56,'artists_name'=>'Sum 41','artists_id'=>57,'albums_name'=>'Underclass Hero','tracks_id'=>20,'title'=>'The Jester')
,array('albums_id'=>56,'artists_name'=>'Sum 41','artists_id'=>57,'albums_name'=>'Underclass Hero','tracks_id'=>18,'title'=>'With Me')
,array('albums_id'=>56,'artists_name'=>'Sum 41','artists_id'=>57,'albums_name'=>'Underclass Hero','tracks_id'=>10,'title'=>'Pull The Curtain')
,array('albums_id'=>56,'artists_name'=>'Sum 41','artists_id'=>57,'albums_name'=>'Underclass Hero','tracks_id'=>6,'title'=>'King of Contridication')
,array('albums_id'=>56,'artists_name'=>'Sum 41','artists_id'=>57,'albums_name'=>'Underclass Hero','tracks_id'=>6,'title'=>'Best of Me')
,array('albums_id'=>412,'artists_name'=>'Taproot','artists_id'=>32,'albums_name'=>'Blue-Sky Research','tracks_id'=>15,'title'=>'April Suits')
);
Query Mapper logic
$objQueryMapper = new QueryMapper();
$objTable1Node = $objQueryMapper->createNode();
$objTable1Node
->setPrimaryKey('id')
->addMapping('artists_id','id')
->addMapping('artists_name','name');
$objTable2Node = $objQueryMapper->createNode();
$objTable2Node->setPrimaryKey('id')
->setName('albums')
->addMapping('albums_id','id')
->addMapping('albums_name','name');
$objTable3Node = $objQueryMapper->createNode();
$objTable3Node->setPrimaryKey('id')
->setName('tracks')
->addMapping('tracks_id','id')
->addMapping('title','title');
$objTable1Node->addChild($objTable2Node);
$objTable2Node->addChild($objTable3Node);
/*
* Create QueryMapper collection to collect result rows
*/
$objQueryMapperCollection = $objQueryMapper->createCollection();
/*
* Create parser
* @arg 1: QueryMapperCollection
* @arg 2: QueryMapper
*/
$objQueryMapperParser = $objQueryMapper->createParser(
$objQueryMapperCollection
,$objQueryMapper
);
foreach($arrResult as $row) {
$objQueryMapperParser->parse($row,$objTable1Node);
}
echo '<pre>',print_r($objQueryMapperCollection),'</pre>';
Result
QueryMapperCollection Object
(
[_collection:private] => Array
(
[0] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 4
[name] => One-X
[albums] => QueryMapperCollection Object
(
[_collection:private] => Array
(
[0] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 2
[name] => Three Days Grace
[tracks] => QueryMapperCollection Object
(
[_collection:private] => Array
(
[0] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 23
[title] => It's All Over
)
)
[1] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 455
[title] => Pain
)
)
[2] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 67
[title] => Animal I Have Become
)
)
[3] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 390
[title] => Never Too Late
)
)
[4] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 43789
[title] => On My Own
)
)
[5] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 123
[title] => Riot
)
)
[6] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 54
[title] => Get Out Alive
)
)
[7] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 14
[title] => Let it Die
)
)
[8] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 3400
[title] => Over and Over
)
)
[9] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 4678
[title] => Gone Forever
)
)
[10] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 4278
[title] => One X
)
)
)
)
)
)
)
)
)
)
[1] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 57
[name] => Sum 41
[albums] => QueryMapperCollection Object
(
[_collection:private] => Array
(
[0] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 56
[name] => Underclass Hero
[tracks] => QueryMapperCollection Object
(
[_collection:private] => Array
(
[0] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 78
[title] => March of the Dogs
)
)
[1] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 29
[title] => Underclass Hero
)
)
[2] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 31
[title] => Walking Disaster
)
)
[3] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 33
[title] => Speak of The Devil
)
)
[4] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 36
[title] => Dear Father
)
)
[5] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 37
[title] => Count Your Blessings
)
)
[6] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 20
[title] => The Jester
)
)
[7] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 18
[title] => With Me
)
)
[8] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 10
[title] => Pull The Curtain
)
)
[9] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 6
[title] => King of Contridication
)
)
)
)
)
)
)
)
)
)
[2] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 32
[name] => Taproot
[albums] => QueryMapperCollection Object
(
[_collection:private] => Array
(
[0] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 412
[name] => Blue-Sky Research
[tracks] => QueryMapperCollection Object
(
[_collection:private] => Array
(
[0] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 1
[title] => I Will Not Fall For You
)
)
[1] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 3
[title] => Violent Seas
)
)
[2] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 7
[title] => Birthday
)
)
[3] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 9
[title] => Facepeeler
)
)
[4] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 11
[title] => Calling
)
)
[5] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 13
[title] => Forever Endevor
)
)
[6] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 17
[title] => Lost In The Woods
)
)
[7] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 19
[title] => So Eager
)
)
[8] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 21
[title] => She
)
)
[9] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 267
[title] => Promise
)
)
[10] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 25
[title] => Nightmare
)
)
[11] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 27
[title] => Bly-Sky Research
)
)
[12] => QueryMapperEntity Object
(
[_vars:private] => Array
(
[id] => 15
[title] => April Suits
)
)
)
)
)
)
)
)
)
)
)
)
So as you can see the algorithm itself is pretty powerful and heavily reduces the amount of time it would take to achieve the above on a case by case basis.