[TYPO3-dev] Gathering data from different domains in one query

Marcus Budzyn marcus at budzyn.de
Tue Sep 16 22:25:18 CEST 2014


Extbase-Development, TYPO3 Version 6.2

Currently I am adapting my own extension (from pibase to ExtBase). The extension displays chess tournament results (exported by SwissChess).

Here is a small fraction of the underlying model:
Domains: tournament, round, game and player:
Relations: A tournament has (n) rounds, every round consists of (n) games. Each game has exactly two players, WhitePlayer and BlackPlayer.

I've written a function called "findGamesOfPlayer" which finds all games of the player, either as WhitePlayer or BlackPlayer.

/**
* Finds games by the specified round and player
*
* @param \MPB\Scsuite\Domain\Model\Player $player
* @return \TYPO3\Flow\Persistence\QueryResultInterface
*/
public function findGamesOfPlayer(\MPB\Scsuite\Domain\Model\Player $player )
{
$query = $this->createQuery();
return $query->matching(
$query->logicalOr(
$query->equals('relPlayerBlack', $player),
$query->equals('relPlayerWhite', $player)
)
)
->execute();
}

My problem:
This all works fine, but I would also return round related data, like the date of the round (I would prefer not to store that redundant piece of information in the game domain!)

Solution 1)
Add a 1:1 relation in the game domain which links back to the matching round. By doing this it is easy to access round related information in Fluid by using the point operator:
{Game.RelRound.EventDate}

Solution 2)
Create a SQL statement which contains all the necessary joins and returns all the fields that are needed.
By using the datamapper I could convert the query results into round and game objects and store these in an array?!

I am sure that the first solution works just fine, the second solution needs more fine tuning (or it is a dumb idea :-))..).

Is there a better way that meets my requirements?

Thanks in advance for your time and patience.

Marcus

P. S: Bonus question: Is it possible to "pretty print" code here (in this post)? The tag [php] doesn't seem to work here



More information about the TYPO3-dev mailing list