TVs aren't really designed to store that kind of data. You can do it (possibly with getResources), but it will be slow, inefficient, and difficult to maintain. And it will get worse as the number of entries increases. Using MIGX, might also be an option.
By far the best way to do this is to create custom tables in the DB and make them xPDO-friendly, though that might be overkill if your list of pubs and beers will always be small.
1. The beer table would have information about each beer (but no information about pubs): alcohol content, style, brewery location, etc. Optionally, the brewery field could be the ID of a brewery in the 'brewery' table.
2. The pub table would have information about each pub (but not about its beers): address, phone, url, etc..
3. The pub_beer table would contain records that each have three fields: 'id' (ID of this pub_beer record), 'beer_id' (the ID of some beer) and 'pub_id' (the ID of some pub).
4. (optional) A brewery table with information about the brewery (but not about its beers): address, date founded, etc..
5. (optional) A brewery_beers table with three fields: 'id' (ID of this brewery_beer record), 'beer_id' (the ID of some beer) and 'brewery_id' (the ID of some brewery).
If you need to separate on tap and bottled beer, you'd probably want two tables like the last one: pub_beer_on_tap, and pub_beer_bottles.
This will allow *very* fast searching for the beers a pub has or vice versa.
$beers = $pub->getMany('OnTap');
$beers = $pub->getMany('Bottles');
$pubs = $beer->getMany('Pubs');
$brewery = $beer->getOne('Brewery');
$beers = $brewery->getMany('Beers');
It will also allow searches like "Find pubs near me with Beer X on tap," which would be a very cumbersonme to do with TVs.
*************************************************************************************
That said, you could do it with a checkbox TV called OnTap with Input Options like this: beer1==pageId1||beer2==pageId2||beer3==pageId3 (where pageId is the ID of the beer's Resource.
The selected beers will be rendered the same way by default, so you could display them with a custom snippet.
[[!ShowBeers? $beers=`[[!*OnTap]]`]]
/* Show Beers snippet */
$beers = explode('||', $beers);
$output = "\n<ul>";
foreach ($beers as $beerName => $pageId) {
$url = $modx->makeUrl($pageId, "", "", "full");
$output .= "\n <li>" . '<a href="' . $url . '">' . $beerName . '</a></li>';
}
$output = "\n</ul>";
return $output;
The down side of this method it that it will be very difficult to create a UI to let you update the information and you'll probably end up doing a lot of tedious manual editing.
[ed. note: BobRay last edited this post 13 years, 4 months ago.]