From cfba80260caf8b62515088b2f7bb763c1ace3c14 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 8 Nov 2018 00:36:51 +0100 Subject: Improved detection of score rows and cells Fixes #9 --- tdd/tdd-bootstrap.php | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'tdd') diff --git a/tdd/tdd-bootstrap.php b/tdd/tdd-bootstrap.php index 59abdb6..de78192 100644 --- a/tdd/tdd-bootstrap.php +++ b/tdd/tdd-bootstrap.php @@ -31,27 +31,30 @@ class Protocol { $tr = @$header_tr->next_sibling(); while($tr) { $td = $tr->find('td/a', 0); - $table = trim($td->innertext); - $table = str_replace(' ', '', $table); - $table = (int)$table; - if($table && array_key_exists($table, $this->deals_by_tables)) { - $contract1 = trim(str_replace(' ', '', $tr->find('td[class="bdc"]', 0)->innertext)); - $score1 = trim(str_replace(' ', '', end($tr->find('td'))->innertext)); - $contract2 = trim(str_replace(' ', '', $tr->next_sibling()->find('td[class="bdc"]', 0)->innertext)); - $score2 = trim(str_replace(' ', '', end($tr->next_sibling()->find('td'))->innertext)); - - $deal = $this->deals_by_tables[$table]; - $insert = "

Stół $table – Rozdanie {$deal->deal_num}

"; - // if is played on both tables of a match - // note that the contract field for arbitral scores starts with 'A' (e.g. 'ARB' or 'AAA') - if(($score1 !== '' || strpos($contract1, 'A') === 0) - && ($score2 !== '' || strpos($contract2, 'A') === 0)) { - $insert .= $deal->html(); - } else { - $insert .= '

...

'; + if ($td) { + $table = trim($td->innertext); + $table = str_replace(' ', '', $table); + $table = (int)$table; + if($table && array_key_exists($table, $this->deals_by_tables)) { + $nextTr = $tr->next_sibling(); + $contract1 = trim(str_replace(' ', '', $tr->find('td[class="bdc"]', 0)->innertext)); + $score1 = trim(str_replace(' ', '', $tr->find('td', 6)->innertext)); + $contract2 = trim(str_replace(' ', '', $tr->next_sibling()->find('td[class="bdc"]', 0)->innertext)); + $score2 = trim(str_replace(' ', '', $nextTr->find('td', 5)->innertext)); + + $deal = $this->deals_by_tables[$table]; + $insert = "

Stół $table – Rozdanie {$deal->deal_num}

"; + // if is played on both tables of a match + // note that the contract field for arbitral scores starts with 'A' (e.g. 'ARB' or 'AAA') + if(($score1 !== '' || strpos($contract1, 'A') === 0) + && ($score2 !== '' || strpos($contract2, 'A') === 0)) { + $insert .= $deal->html(); + } else { + $insert .= '

...

'; + } + + $tr->outertext = '' . $insert . '' . $tr->outertext; } - - $tr->outertext = '' . $insert . '' . $tr->outertext; } $tr = @$tr->next_sibling(); } -- cgit v1.2.3