From 4031d439708b38d4e431242f3fbf5d18bbcbfa16 Mon Sep 17 00:00:00 2001 From: emkael Date: Mon, 29 Jan 2018 23:23:32 +0100 Subject: Anchors and anchored links to specified tables --- tdd-bootstrap.php | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tdd-bootstrap.php b/tdd-bootstrap.php index f85a786..2af5ac1 100644 --- a/tdd-bootstrap.php +++ b/tdd-bootstrap.php @@ -13,11 +13,11 @@ class Protocol { throw new Exception('file not found: ' . $this->get_filename()); } } - + function get_filename() { return $this->prefix . $this->round . 'b-' . $this->board . '.html'; } - + function set_deal($table, $deal) { $this->deals_by_tables[$table] = $deal; } @@ -43,10 +43,10 @@ class Protocol { // 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) + if(($score1 !== '' || strpos($contract1, 'A') === 0) && ($score2 !== '' || strpos($contract2, 'A') === 0)) { $deal = $this->deals_by_tables[$table]; - $insert = "

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

" . $deal->html(); + $insert = "

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

" . $deal->html(); $modified = 1; } else { $insert = '

...

'; @@ -56,17 +56,17 @@ class Protocol { } $tr = @$tr->next_sibling(); } - + if($modified) { $header_tr2 = $header_tr->next_sibling(); $header_tr->outertext = ''; $header_tr2->outertext = ''; $dom->find('/html/body/table/tr', 0)->outertext = ''; } - + print $dom->outertext; } - + } class NoSuchDealNumber extends Exception { @@ -78,23 +78,23 @@ class Deal { $this->deal_num = $num_in_pbn; $this->_parse($filename, $num_in_pbn); } - + function _parse($filename, $num_in_pbn) { $pbn = file_get_contents($filename); $start = strpos($pbn, '[Board "' . $num_in_pbn . '"]'); if($start === false) { throw new NoSuchDealNumber($num_in_pbn); } - + $pbn = substr($pbn, $start + 5); $stop = strpos($pbn,'[Board "'); if($stop != false) { $pbn = substr($pbn, 0, $stop); } - + preg_match('|Dealer "([NESW])"|', $pbn, $m); $this->dealer = $m[1]; - + preg_match('|Vulnerable "([^"]+)"|', $pbn, $m); $this->vuln = $m[1]; if($this->vuln == 'None') { @@ -102,25 +102,25 @@ class Deal { } else if($this->vuln == 'All') { $this->vuln = 'Obie'; } - + preg_match('|Ability "([^"]+)"|', $pbn, $m); if($m[1]) { $this->ability = explode(' ',$m[1]); } - + preg_match('|Minimax "([^"]+)"|', $pbn, $m); $this->minimax = $m[1]; - + preg_match('|Deal "(N:)?([^"]+)"|', $pbn, $m); $this->hands = explode(' ',$m[2]); } - + function html() { ob_start(); include('tdd-handrecord-tpl.php'); return ob_get_clean(); } - + function format_hand($hand_num) { $hand = $this->hands[$hand_num]; $hand = str_replace('T','10',$hand); @@ -150,7 +150,7 @@ class Deal { {$ab[4]} {$ab[5]}"; } - + function format_minimax() { $minimax = $this->minimax; $minimax = preg_replace('|^(..)D(.+)|','$1x$2', $minimax); @@ -164,17 +164,17 @@ class Deal { function load_deals_for_tables($prefix, $round, $board_in_teamy) { $deals_by_tables = array(); - + $prefix = preg_quote($prefix); $filename_regex = "/$prefix-r$round-t(\d+)-b(\d+).pbn/"; foreach(scandir('.') as $filename) { if(preg_match($filename_regex, $filename, $match)) { $file_table = $match[1]; $file_start_board = $match[2]; - + // 1 in teamy -> 1 in pbn; 24 in teamy -> 1 in pbn; 25 in teamy -> 1 in pbn $num_in_pbn = $board_in_teamy - $file_start_board + 1; - + try { $deal = new Deal($filename, $num_in_pbn); $deals_by_tables[$file_table] = $deal; -- cgit v1.2.3