[live627's rants] These trees are [not] simple

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670
[live627's rants] These trees are [not] simple
« on March 10th, 2012, 08:00 AM »
So I needed to get a subset of boards in a category, so I decided to use the data generated by getBoardList(). I've used this function before,, and iterating through $boardList is a snap, so, why not try $boards? It's... a... mess! Much harder to iterate through properly than expected. Not only is the code inside the function confusing, but scanning the output is also confusing!

I suspect that the code dates way back, to 1.0 probably, or even YABBSE.

Seriously, why all thee node subarrays and duplications? It's enough to spend an entire evening just staring and figuring out what the hell it does![1]

And children aren't consistent with graandchildren, either. The former is under 'tree' while the latter isn't. What's the big deal? Either put 'em all under the extra item, or  don't... quite simple, really.
 1. That's where my evening went, in case it wasn't obvious. Add this to an unusually rough day with a headache to boot, yeah, I'm pissed.
A confident man keeps quiet.whereas a frightened man keeps talking, hiding his fear.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
[live627's rants] Re: These trees are [not] simple
« Reply #1, on March 10th, 2012, 11:09 AM »
Which one, exactly, are you looking at? getBoardList() in Subs-MessageIndex.php is rather simple to use, and I'm guessing you mean getBoardIndex() which is an utter mess?
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670
[live627's rants] Re: These trees are [not] simple
« Reply #4, on March 11th, 2012, 02:48 AM »
Here's my code.
Code: [Select]
<?php template_edit_profile_league__r(array($boards[$context['d_board']]));

function 
template_edit_profile_league__r($boards)
{
foreach ($boards as $board)
{
if (isset($board['node']['id']))
$b $board['node'];
else
$b $board;

echo '
<div><input type="text" name="boards['
$b['id'], ']"style="margin-left: ', (($b['level'] * 1.5) + 0.5), 'em;"  value="'$b['name'], '"></div>';

if (!empty($board['tree']['children']))
template_edit_profile_league__r($board['tree']['children']);

if (!empty($board['children']))
template_edit_profile_league__r($board['children']);
}
?>

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278