/** * calculate() * * Al primo errore termina con false! * * @Override * * (non-PHPdoc) * @see ianseo/Common/Rank/Obj_Rank#calculate() */ public function calculate() { if (count($this->opts['eventsC']) > 0) { foreach ($this->opts['eventsC'] as $c) { list($event, $phase) = explode('@', $c); $x = true; switch ($phase) { case -3: $x = $this->calcFromAbs($event); break; case -2: $x = $this->calcFromElim2($event); break; case -1: $x = $this->calcFromElim1($event); break; default: /* * Qui devo ciclare a partire dalla fase passata fino agli ori. * Il primo errore mi fa terminare il metodo con false */ foreach (getPhasesId() as $p) { // se sono in una fase > di quella passata ignoro if ($p > $phase) { continue; } $x = $this->calcFromPhase($event, $p); if ($x === false) { return false; } } break; } if ($x === false) { return false; } } } return true; }
/** * read() * * @Override * * (non-PHPdoc) * @see ianseo/Common/Rank/Obj_Rank#read() */ public function read() { $f = $this->safeFilterR(); $filter = ""; if ($f !== false) { $filter = $f; } if (array_key_exists('cutRank', $this->opts) && is_numeric($this->opts['cutRank']) && $this->opts['cutRank'] > 0) { $filter .= "AND IF(EvFinalFirstPhase=0, TeRank, TeRankFinal)<={$this->opts['cutRank']} "; } $EnFilter = empty($this->opts['enid']) ? '' : " AND EnId=" . intval($this->opts['enid']); $EnFilter .= empty($this->opts['coid']) ? '' : " AND EnCountry=" . intval($this->opts['coid']); $phases = null; /* * prima passata per costruire la struttura del vettore. * Tiro fuori le posizioni di qualifica e le posizioni finali con i nomi. * La query è divisa in due: la prima parte tira fuori le squadre che sono andate in finale * e la seconda quelle che si son fermate prima. * Devo far così perchè i nomi dei membri dei team provengono da due tabelle diverse. */ $q = "\r\n\t\t\t/* parte delle finali */\r\n\t\t\t\t(\r\n\t\t\t\t\tSELECT 1,\r\n\t\t\t\t\t\tCoId, TeSubTeam, CoCode, CoName,\r\n\t\t\t\t\t\tEvProgr, TeEvent, EvEventName, EvMaxTeamPerson,\r\n\t\t\t\t\t\tEvFinalPrintHead as PrintHeader,\r\n\t\t\t\t\t\tEvFinalFirstPhase, EvMatchMode, EvMedals,\r\n\t\t\t\t\t\tEnId,EnCode,EnFirstName,upper(EnFirstName) EnFirstNameUpper,EnName,tc.TfcOrder AS personOrder,\r\n\t\t\t\t\t\tTeRank as QualRank, IF(EvFinalFirstPhase=0, TeRank, TeRankFinal) as FinalRank, TeScore,\r\n\t\t\t\t\t\tTeTimestamp,TeTimestampFinal/*,'0' AS rowType*/\r\n\t\t\t\t\tFROM\r\n\t\t\t\t\t\tTournament\r\n\r\n\t\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\t\tTeams\r\n\t\t\t\t\t\tON ToId=TeTournament AND TeFinEvent=1\r\n\r\n\t\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\t\tCountries\r\n\t\t\t\t\t\tON TeCoId=CoId AND TeTournament=CoTournament\r\n\r\n\t\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\t\tTeamFinComponent AS tc\r\n\t\t\t\t\t\tON Teams.TeCoId=tc.TfcCoId AND Teams.TeSubTeam=tc.TfcSubTeam AND Teams.TeEvent=tc.TfcEvent AND Teams.TeTournament=tc.TfcTournament AND Teams.TeFinEvent=1\r\n\r\n\t\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\t\tEntries\r\n\t\t\t\t\t\tON TfcId=EnId\r\n\r\n\t\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\t\tEvents\r\n\t\t\t\t\t\tON TeEvent=EvCode AND ToId=EvTournament AND EvTeamEvent=1\r\n\t\t\t\t\tWHERE\r\n\t\t\t\t\t\tIF(EvFinalFirstPhase=0, TeRank, TeRankFinal)<=(EvFinalFirstPhase*2) AND TeScore != 0 AND ToId = {$this->tournament}\r\n\t\t\t\t\t\t{$filter}\r\n\t\t\t\t\t\t{$EnFilter}\r\n\r\n\t\t\t\t)\r\n\t\t\t\tUNION ALL\r\n\t\t\t\t(\r\n\t\t\t\t\tSELECT 2,\r\n\t\t\t\t\t\tCoId,TeSubTeam,CoCode,CoName,\r\n\t\t\t\t\t\tEvProgr,TeEvent,EvEventName,EvMaxTeamPerson,\r\n\t\t\t\t\t\tEvFinalPrintHead as PrintHeader,\r\n\t\t\t\t\t\tEvFinalFirstPhase,EvMatchMode,EvMedals,\r\n\t\t\t\t\t\tEnId,EnCode,EnFirstName,upper(EnFirstName) EnFirstNameUpper,EnName,tc.TcOrder,\r\n\t\t\t\t\t\tTeRank as QualRank, IF(EvFinalFirstPhase=0, TeRank, TeRankFinal) as FinalRank, TeScore,\r\n\t\t\t\t\t\tTeTimestamp,TeTimestampFinal\r\n\t\t\t\t\tFROM\r\n\t\t\t\t\t\tTournament\r\n\r\n\t\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\t\tTeams\r\n\t\t\t\t\t\tON ToId=TeTournament AND TeFinEvent=1\r\n\r\n\t\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\t\tCountries\r\n\t\t\t\t\t\tON TeCoId=CoId AND TeTournament=CoTournament\r\n\r\n\t\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\t\tTeamComponent AS tc\r\n\t\t\t\t\t\tON Teams.TeCoId=tc.TcCoId AND Teams.TeSubTeam=tc.TcSubTeam AND Teams.TeEvent=tc.TcEvent AND Teams.TeTournament=tc.TcTournament AND Teams.TeFinEvent=tc.TcFinEvent AND Teams.TeFinEvent=1\r\n\r\n\t\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\t\tEntries\r\n\t\t\t\t\t\tON TcId=EnId\r\n\r\n\t\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\t\tEvents\r\n\t\t\t\t\t\tON TeEvent=EvCode AND ToId=EvTournament AND EvTeamEvent=1\r\n\t\t\t\t\tWHERE\r\n\t\t\t\t\t\tIF(EvFinalFirstPhase=0, TeRank, TeRankFinal)>(EvFinalFirstPhase*2) AND TeScore != 0 AND ToId = {$this->tournament}\r\n\t\t\t\t\t\t/*AND CONCAT(TeCoId,'_',TeSubTeam) NOT IN (SELECT DISTINCT CONCAT(TfTeam,'_',TfSubTeam) FROM TeamFinals WHERE TfTournament={$this->tournament})*/\r\n\t\t\t\t\t\t{$filter}\r\n\t\t\t\t\t\t{$EnFilter}\r\n\t\t\t\t)\r\n\t\t\t\tORDER BY\r\n\t\t\t\t\tEvProgr, TeEvent,/*rowType ASC,*/ FinalRank ASC, CoCode ASC, TeSubTeam, personOrder ASC, EnFirstName, EnName\r\n\t\t\t"; // print $q;exit; // debug_svela($q, true); $r = safe_r_sql($q); $this->data['meta']['title'] = get_text('TeamFinEvent', 'Tournament'); $this->data['meta']['lastUpdate'] = '0000-00-00 00:00:00'; $this->data['sections'] = array(); $myEv = ''; $myTeam = ''; if (safe_num_rows($r) > 0) { $section = null; while ($myRow = safe_fetch($r)) { if ($myEv != $myRow->TeEvent) { if ($myEv != '') { $this->data['sections'][$myEv] = $section; $section = null; } $myEv = $myRow->TeEvent; $phases = getPhasesId($myRow->EvFinalFirstPhase); $fields = array('id' => 'Id', 'countryCode' => '', 'countryName' => get_text('Country'), 'subteam' => get_text('PartialTeam'), 'athletes' => array('name' => get_text('Name', 'Tournament'), 'fields' => array('id' => 'Id', 'bib' => get_text('Code', 'Tournament'), 'athlete' => get_text('Athlete'), 'familyname' => get_text('FamilyName', 'Tournament'), 'givenname' => get_text('Name', 'Tournament'))), 'qualRank' => get_text('RankScoreShort'), 'qualScore' => get_text('PositionShort'), 'rank' => get_text('PositionShort'), 'finals' => array()); foreach ($phases as $k => $v) { if ($v <= valueFirstPhase($myRow->EvFinalFirstPhase)) { $fields['finals'][$v] = get_text(namePhase($myRow->EvFinalFirstPhase, $v) . "_Phase"); } } $fields['finals']['fields'] = array('score' => get_text('TotalShort', 'Tournament'), 'setScore' => get_text('SetTotal', 'Tournament'), 'setPoints' => get_text('SetPoints', 'Tournament'), 'tie' => 'S.O.', 'arrowstring' => get_text('Arrows', 'Tournament'), 'tiebreak' => get_text('TieArrows')); $section = array('meta' => array('event' => $myEv, 'descr' => get_text($myRow->EvEventName, '', '', true), 'printHeader' => get_text($myRow->PrintHeader, '', '', true), 'firstPhase' => $myRow->EvFinalFirstPhase, 'matchMode' => $myRow->EvMatchMode, 'maxTeamPerson' => $myRow->EvMaxTeamPerson, 'order' => $myRow->EvProgr, 'lastUpdate' => '0000-00-00 00:00:00', 'fields' => $fields, 'medals' => $myRow->EvMedals), 'items' => array()); } if ($myTeam != $myRow->CoId . $myRow->TeSubTeam . $myRow->TeEvent) { $item = array('id' => $myRow->CoId, 'countryCode' => $myRow->CoCode, 'countryName' => $myRow->CoName, 'subteam' => $myRow->TeSubTeam, 'athletes' => array(), 'qualScore' => $myRow->TeScore, 'qualRank' => $myRow->QualRank, 'rank' => $myRow->FinalRank == 9999 ? 'DSQ' : $myRow->FinalRank, 'finals' => array()); $section['items'][$myRow->CoId . '_' . $myRow->TeSubTeam] = $item; if ($myRow->TeTimestampFinal > $section['meta']['lastUpdate']) { $section['meta']['lastUpdate'] = $myRow->TeTimestampFinal; } if ($myRow->TeTimestampFinal > $this->data['meta']['lastUpdate']) { $this->data['meta']['lastUpdate'] = $myRow->TeTimestampFinal; } $myTeam = $myRow->CoId . $myRow->TeSubTeam . $myRow->TeEvent; } if (!array_key_exists('components', $this->opts) || $this->opts['components']) { $athlete = array('id' => $myRow->EnId, 'bib' => $myRow->EnCode, 'athlete' => $myRow->EnFirstNameUpper . ' ' . $myRow->EnName, 'familyname' => $myRow->EnFirstName, 'familynameUpper' => $myRow->EnFirstNameUpper, 'givenname' => $myRow->EnName); //$section['items'][count($section['items'])-1]['athletes'][]=$athlete; $section['items'][$myRow->CoId . '_' . $myRow->TeSubTeam]['athletes'][] = $athlete; } } // ultimo giro $this->data['sections'][$myEv] = $section; } // print count($this->data['sections']['OLMT']['items']);exit; /* * A questo punto ho i nomi e le qualifiche * e punti+rank delle precedenti. * Mi mancano le finali. * */ $q = "\r\n\t\t\t\tSELECT\r\n\t\t\t\t\tf1.TfEvent AS `event`,CONCAT(f1.TfTeam,'_',f1.TfSubTeam) AS `athlete`,f1.TfMatchNo AS `matchNo`,f1.TfScore AS `score`,f1.TfSetScore AS `setScore`,f1.TfSetPoints AS `setPoints`,f1.TfTie AS `tie`,f1.TfArrowstring AS `arrowstring`,f1.TfTiebreak AS `tiebreak`,\r\n\t\t\t\t\tCONCAT(f2.TfTeam,'_',f2.TfSubTeam) AS `oppAthlete`,f2.TfMatchNo AS `oppMatchNo`,f2.TfScore AS `oppScore`,f2.TfSetScore AS `oppSetScore`,f2.TfSetPoints AS `oppSetPoints`,f2.TfTie AS `oppTie`,f2.TfArrowstring AS `oppArrowstring`,f2.TfTiebreak AS `oppTiebreak`,\r\n\t\t\t\t\tGrPhase, EvMaxTeamPerson\r\n\t\t\t\tFROM\r\n\t\t\t\t\tTeams\r\n\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\tTeamFinals AS f1\r\n\t\t\t\t\tON TeTournament=f1.TfTournament AND TeEvent=f1.TfEvent AND CONCAT(TeCoId,'_',TeSubTeam)=CONCAT(f1.TfTeam,'_',f1.TfSubTeam)\r\n\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\tTeamFinals AS f2\r\n\t\t\t\t\tON f1.TfEvent=f2.TfEvent AND f1.TfMatchNo=IF((f1.TfMatchNo % 2)=0,f2.TfMatchNo-1,f2.TfMatchNo+1) AND f1.TfTournament=f2.TfTournament\r\n\r\n\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\tGrids\r\n\t\t\t\t\tON f1.TfMatchNo=GrMatchNo\r\n\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\tEvents\r\n\t\t\t\t\tON f1.TfTournament=EvTournament AND f1.TfEvent=EvCode AND EvTeamEvent=1\r\n\t\t\t\tWHERE\r\n\t\t\t\t\tf1.TfTournament={$this->tournament}\r\n\t\t\t\t\t{$filter}\r\n\t\t\t\tORDER BY\r\n\t\t\t\t\tEvProgr ASC,EvCode,TeRankFinal ASC,GrPhase DESC\r\n\t\t\t"; $rr = safe_r_sql($q); if (safe_num_rows($rr) > 0) { while ($row = safe_fetch($rr)) { $arrowstring = array(); for ($i = 0; $i < strlen($row->arrowstring); ++$i) { if (trim($row->arrowstring[$i]) != '') { $arrowstring[] = DecodeFromLetter($row->arrowstring[$i]); } } $tiebreak = array(); for ($i = 0; $i < strlen($row->tiebreak); ++$i) { if (trim($row->tiebreak[$i]) != '') { $tiebreak[] = DecodeFromLetter($row->tiebreak[$i]); } } $oppArrowstring = array(); for ($i = 0; $i < strlen($row->oppArrowstring); ++$i) { if (trim($row->oppArrowstring[$i]) != '') { $oppArrowstring[] = DecodeFromLetter($row->oppArrowstring[$i]); } } $oppTiebreak = array(); for ($i = 0; $i < strlen($row->oppTiebreak); ++$i) { if (trim($row->oppTiebreak[$i]) != '') { $oppTiebreak[] = DecodeFromLetter($row->oppTiebreak[$i]); } } $tmpArr = array(); $oppArr = array(); if ($row->tiebreak) { for ($countArr = 0; $countArr < strlen(trim($row->tiebreak)); $countArr += $row->EvMaxTeamPerson) { $tmp = ValutaArrowString(substr(trim($row->tiebreak), $countArr, $row->EvMaxTeamPerson)); if (!ctype_upper(trim($row->tiebreak))) { $tmp .= "*"; } $tmpArr[] = $tmp; } //debug_svela($myRow); } if ($row->oppTiebreak) { for ($countArr = 0; $countArr < strlen(trim($row->oppTiebreak)); $countArr += $row->EvMaxTeamPerson) { $tmp = ValutaArrowString(substr(trim($row->oppTiebreak), $countArr, $row->EvMaxTeamPerson)); if (!ctype_upper(trim($row->oppTiebreak))) { $tmp .= "*"; } $oppArr[] = $tmp; } } if (isset($this->data['sections'][$row->event]['items'][$row->athlete]['finals'])) { $this->data['sections'][$row->event]['items'][$row->athlete]['finals'][$row->GrPhase] = array('score' => $row->score, 'setScore' => $row->setScore, 'setPoints' => $row->setPoints, 'tie' => $row->tie, 'arrowstring' => implode('|', $arrowstring), 'tiebreak' => implode('|', $tiebreak), 'tiebreakDecoded' => implode(',', $tmpArr), 'oppAthlete' => $row->oppAthlete, 'oppScore' => $row->oppScore, 'oppSetScore' => $row->oppSetScore, 'oppSetPoints' => $row->oppSetPoints, 'oppTie' => $row->oppTie, 'oppArrowstring' => implode('|', $oppArrowstring), 'oppTiebreak' => implode('|', $oppTiebreak), 'oppTiebreakDecoded' => implode(',', $oppArr)); } } } }
/** * trainingAndFinal() * Popola le righe che riguardano il warmup e le finali (se richieste) * * @return void */ protected function trainingAndFinal() { $queries = array(); /* * Se sono state richieste le righe di FinTraining e il filtro sul tipo di righe * è F oppure * allora le metto */ if (($this->opts['sessionType'] == '*' || $this->opts['sessionType'] == 'F') && $this->opts['training']) { $warmup = get_text('WarmUp', 'Tournament'); $caseTeam = "(CASE FteTeamEvent "; $caseTeam .= "WHEN 0 THEN '" . get_text('Individual') . "' "; $caseTeam .= "WHEN 1 THEN '" . get_text('Team') . "' "; $caseTeam .= "END) "; $queries[] = "\r\n\t\t\t\t(\r\n\t\t\t\t\tSELECT\r\n\t\t\t\t\t\t1 AS `schOrder`,CONCAT(FtScheduledDate,' ',FtScheduledTime) AS `dateStart`, ADDDATE(CONCAT(FtScheduledDate,' ',FtScheduledTime), INTERVAL FtScheduledLen MINUTE) AS `dateEnd`,\r\n\t\t\t\t\t\t'W' AS `sessionType`,\r\n\t\t\t\t\t\tCONCAT('{$warmup}',' ',CONCAT({$caseTeam},' ',group_concat(FteEvent separator '-'))) AS `descr`\r\n\t\t\t\t\tFROM\r\n\t\t\t\t\t\tFinTraining\r\n\t\t\t\t\t\tLEFT JOIN\r\n\t\t\t\t\t\t\tFinTrainingEvent\r\n\t\t\t\t\t\tON FteTournament=FtTournament and FteScheduledDate=FtScheduledDate and FteScheduledTime=FtScheduledTime and FteTargetFrom=FtTargetFrom\r\n\t\t\t\t\tWHERE\r\n\t\t\t\t\t\tFtTournament={$this->tourId} AND FtScheduledDate!='0000-00-00' \r\n\t\t\t\t\tGROUP BY \r\n\t\t\t\t\t\tFtTournament, FtScheduledDate, FtScheduledTime/*, FtTargetFrom*/ \r\n\t\t\t\t)\r\n\t\t\t\t/*ORDER BY \r\n\t\t\t\tFtScheduledDate ASC, FtScheduledTime ASC*/\r\n\t\t\t"; } /* * Se sono state richieste le righe di FinSchedule e il filtro sul tipo di righe * è F oppure * allora le metto */ if (($this->opts['sessionType'] == '*' || $this->opts['sessionType'] == 'F') && $this->opts['final']) { $phases = getPhasesId(-1); $casePhase = "(CASE GrPhase "; foreach ($phases as $p) { if (in_array($p, array(64, 32))) { $txt1 = get_text($p . '_Phase'); $txt2 = ''; if ($p == 64) { $txt2 = get_text('48_Phase'); } elseif ($p == 32) { $txt2 = get_text('24_Phase'); } if ($p == 64) { $casePhase .= " WHEN {$p} THEN IF( EvFinalFirstPhase=64,'{$txt1}','{$txt2}' ) "; } elseif ($p == 32) { $casePhase .= " WHEN {$p} THEN IF( EvFinalFirstPhase=32,'{$txt1}','{$txt2}' ) "; } } else { $txt = get_text($p . '_Phase'); $casePhase .= " WHEN {$p} THEN '{$txt}' "; } } $casePhase .= "END) "; //print '<br>'.$casePhase.'<br><br>'; $caseTeam = "(CASE FSTeamEvent "; $caseTeam .= "WHEN 0 THEN '" . get_text('Individual') . "' "; $caseTeam .= "WHEN 1 THEN '" . get_text('Team') . "' "; $caseTeam .= "END) "; $final = get_text('MenuLM_Final Rounds'); $queries[] = "\r\n\t\t\t\t(\r\n\t\t\t\t\tSELECT DISTINCT\r\n\t\t\t\t\t\t1 AS `schOrder`,CONCAT(FSScheduledDate,' ',FSScheduledTime) AS `dateStart`, ADDDATE(CONCAT(FSScheduledDate,' ',FSScheduledTime), INTERVAL FSScheduledLen MINUTE) AS `dateEnd`,\r\n\t\t\t\t\t\t'F' AS `sessionType`,\r\n\t\t\t\t\t\tCONCAT('{$final}',' ',group_concat(DISTINCT CONCAT({$caseTeam},' ',FSEvent,' (',{$casePhase},')' ) separator ' - ')) AS `descr`\r\n\t\t\t\t\tFROM\r\n\t\t\t\t\t\tFinSchedule\r\n\t\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\t\tEvents\r\n\t\t\t\t\t\tON EvCode=FSEvent AND EvTeamEvent=FSTeamEvent AND EvTournament=FSTournament\r\n\t\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\t\tGrids\r\n\t\t\t\t\t\tON FSMatchNo=GrMatchNo AND GrPhase<=(IF(EvFinalFirstPhase=24,32, IF(EvFinalFirstPhase=48,64,EvFinalFirstPhase )))\r\n\t\t\t\t\tWHERE\r\n\t\t\t\t\t\tFSTournament={$this->tourId} AND FSScheduledDate!='0000-00-00'\r\n\t\t\t\t\tGROUP BY\r\n\t\t\t\t\t\tschOrder,dateStart/*,FSMatchNo, GrPhase*/ \r\n\t\t\t\t)\r\n\t\t\t\t\r\n\t\t\t\t/*ORDER BY\r\n\t\t\t\t\tFSScheduledDate ASC, FSScheduledTime ASC*/\r\n\t\t\t"; } // se ho query parto se no termino if (count($queries) > 0) { $q = implode(' UNION ALL ', $queries) . " ORDER BY dateStart ASC "; //print $q;exit; $r = safe_r_sql($q); if ($r) { while ($row = safe_fetch_assoc($r)) { $row['timeLabel'] = dateRenderer($row['dateStart'], 'H:i'); if ($row['dateEnd'] != '0000-00-00 00:00:00' && $row['dateStart'] != $row['dateEnd']) { $row['timeLabel'] .= ' - ' . dateRenderer($row['dateEnd'], 'H:i'); } // cerco dove infilare la riga $day = substr($row['dateStart'], 0, 10); $found = false; // print '<pre>'; // print_r($this->data); // print '</pre>'; if (array_key_exists($day, $this->data['days'])) { foreach ($this->data['days'][$day]['items'] as &$v) { if ($v['sessionType'] == 'F') { if ($row['dateStart'] >= $v['dateStart'] && $row['dateStart'] < $v['dateEnd']) { $found = true; /* * ... e metto la riga nel giorno * Se il padre ha il Follow=0 * - la timeLabel è quella preparata prima * Se il padre ha il Follow=1 * - se il figlio precedente è di tipo diverso oppure non ci sono precedenti, * la timeLabel è quella preparata prima * - se il figlio precedente è dello stesso tipo * la timeLabel cambia */ if ($v['follow'] == 1) { if (count($v['children']) != 0 && $v['children'][count($v['children']) - 1]['sessionType'] == $row['sessionType']) { $row['timeLabel'] = get_text('ToFollow', 'Tournament'); } } $v['children'][] = $row; break; } } } } if (!$found && ($this->opts['trainingOrphans'] && $row['sessionType'] == 'W' || $this->opts['finalOrphans'] && $row['sessionType'] == 'F')) { //$day=substr($row['dateStart'],0,10); if (!array_key_exists($day, $this->data['days'])) { $this->data['days'][$day] = array('dateLabel' => dateRenderer($day, get_text('DateFmt')), 'items' => array()); } $this->data['days'][$day]['items'][] = $row; } $this->sortDayItems($day); } } } }
public function read() { $f = $this->safeFilterR(); $filter = ""; if ($f !== false) { $filter = $f; } if (array_key_exists('cutRank', $this->opts) && is_numeric($this->opts['cutRank']) && $this->opts['cutRank'] > 0) { $filter .= "AND IndRankFinal<={$this->opts['cutRank']} "; } $EnFilter = empty($this->opts['enid']) ? '' : " AND EnId=" . intval($this->opts['enid']); $EnFilter .= empty($this->opts['coid']) ? '' : " AND EnCountry=" . intval($this->opts['coid']); $phases = null; /* * prima passata per costruire la struttura del vettore. * Tiro fuori le qualifiche, le posizioni finali e le eliminatorie (se ci sono) */ $q = "\r\n\t\t\t\tSELECT\r\n\t\t\t\t\tEnId,EnCode, upper(EnIocCode) EnIocCode, EnName AS Name, EnFirstName AS FirstName, upper(EnFirstName) AS FirstNameUpper, CoId, CoCode, CoName,\r\n\t\t\t\t\tEvCode,EvEventName,EvProgr,\r\n\t\t\t\t\tEvFinalPrintHead as PrintHeader,\r\n\t\t\t\t\tEvFinalFirstPhase,\tEvElim1, \tEvElim2,EvMatchMode, EvMedals,\r\n\t\t\t\t\tIndRank as QualRank, IF(EvShootOff+EvE1ShootOff+EvE2ShootOff=0, IndRank, IndRankFinal) as FinalRank, QuScore AS QualScore,\r\n\t\t\t\t\te1.ElRank AS E1Rank,e1.ElScore AS E1Score,\r\n\t\t\t\t\te2.ElRank AS E2Rank,e2.ElScore AS E2Score,\r\n\t\t\t\t\tIndTimestamp,IndTimestampFinal\r\n\t\t\t\tFROM\r\n\t\t\t\t\tTournament\r\n\r\n\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\tEntries\r\n\t\t\t\t\tON ToId=EnTournament\r\n\r\n\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\tCountries\r\n\t\t\t\t\tON EnCountry=CoId AND EnTournament=CoTournament AND EnTournament={$this->tournament}\r\n\r\n\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\tQualifications\r\n\t\t\t\t\tON EnId=QuId\r\n\r\n\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\tIndividuals\r\n\t\t\t\t\tON EnTournament=IndTournament AND EnId=IndId\r\n\r\n\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\tEvents\r\n\t\t\t\t\tON EvCode=IndEvent AND EvTeamEvent=0 AND EvTournament=IndTournament\r\n\r\n\t\t\t\t\tLEFT JOIN\r\n\t\t\t\t\t\tEliminations AS e1\r\n\t\t\t\t\tON IndId=e1.ElId AND IndTournament=e1.ElTournament AND IndEvent=e1.ElEventCode AND e1.ElElimPhase=0\r\n\r\n\t\t\t\t\tLEFT JOIN\r\n\t\t\t\t\t\tEliminations AS e2\r\n\t\t\t\t\tON IndId=e2.ElId AND IndTournament=e2.ElTournament AND IndEvent=e2.ElEventCode AND e2.ElElimPhase=1\r\n\r\n\t\t\t\tWHERE\r\n\t\t\t\t\tEnAthlete=1 AND EnIndFEvent=1 AND EnStatus <= 1 AND QuScore != 0 AND ToId = {$this->tournament}\r\n\t\t\t\t\t{$filter}\r\n\t\t\t\t\t{$EnFilter}\r\n\t\t\t\tORDER BY\r\n\t\t\t\t\t\tEvProgr, EvCode, IF(EvShootOff+EvE1ShootOff+EvE2ShootOff=0, IndRank, IndRankFinal) ASC, EnFirstName, EnName\r\n\t\t\t"; //print $q;exit; $r = safe_r_sql($q); $this->data['meta']['title'] = get_text('IndFinEvent', 'Tournament'); // $this->data['meta']['printHeader']=''; // $this->data['meta']['firstPhase']=-1; // $this->data['meta']['elim1']=-1; // $this->data['meta']['elim2']=-1; // $this->data['meta']['matchMode']=-1; $this->data['meta']['lastUpdate'] = '0000-00-00 00:00:00'; $this->data['sections'] = array(); if (safe_num_rows($r) > 0) { $curEvent = ''; $section = null; while ($myRow = safe_fetch($r)) { if ($curEvent != $myRow->EvCode) { /* * se non sono all'inizio, prima di iniziare una sezione devo prendere quella appena fatta * e accodarla alle altre */ if ($curEvent != '') { $this->data['sections'][$curEvent] = $section; $section = null; } // al cambio creo una nuova sezione $curEvent = $myRow->EvCode; $phases = getPhasesId($myRow->EvFinalFirstPhase); // qui ci sono le descrizioni dei campi $fields = array('id' => 'Id', 'bib' => get_text('Code', 'Tournament'), 'athlete' => get_text('Athlete'), 'familyname' => get_text('FamilyName', 'Tournament'), 'givenname' => get_text('Name', 'Tournament'), 'countryCode' => '', 'countryName' => get_text('Country'), 'countryIocCode' => '', 'qualRank' => get_text('RankScoreShort'), 'qualScore' => get_text('PositionShort'), 'rank' => get_text('PositionShort'), 'elims' => array('e1' => get_text('Eliminations_1'), 'e2' => get_text('Eliminations_2'), 'fields' => array('score' => get_text('Total'), 'rank' => get_text('PositionShort'))), 'finals' => array()); foreach ($phases as $k => $v) { if ($v <= valueFirstPhase($myRow->EvFinalFirstPhase)) { if (!($v == 32 && ($myRow->EvFinalFirstPhase == 24 || $myRow->EvFinalFirstPhase == 48))) { $fields['finals'][$v] = get_text(namePhase($myRow->EvFinalFirstPhase, $v) . "_Phase"); } } } $fields['finals']['fields'] = array('score' => get_text('TotalShort', 'Tournament'), 'setScore' => get_text('SetTotal', 'Tournament'), 'setPoints' => get_text('SetPoints', 'Tournament'), 'tie' => 'S.O.', 'arrowstring' => get_text('Arrows', 'Tournament'), 'tiebreak' => get_text('TieArrows')); $section = array('meta' => array('event' => $curEvent, 'descr' => get_text($myRow->EvEventName, '', '', true), 'printHeader' => get_text($myRow->PrintHeader, '', '', true), 'firstPhase' => $myRow->EvFinalFirstPhase, 'elim1' => $myRow->EvElim1 != 0, 'elim2' => $myRow->EvElim2 != 0, 'matchMode' => $myRow->EvMatchMode, 'order' => $myRow->EvProgr, 'lastUpdate' => '0000-00-00 00:00:00', 'fields' => $fields, 'medals' => $myRow->EvMedals), 'items' => array()); } $item = array('id' => $myRow->EnId, 'bib' => $myRow->EnCode, 'athlete' => $myRow->FirstNameUpper . ' ' . $myRow->Name, 'familyname' => $myRow->FirstName, 'familynameUpper' => $myRow->FirstNameUpper, 'givenname' => $myRow->Name, 'countryId' => $myRow->CoId, 'countryCode' => $myRow->CoCode, 'countryIocCode' => $myRow->EnIocCode, 'countryName' => $myRow->CoName, 'qualScore' => $myRow->QualScore, 'qualRank' => $myRow->QualRank, 'rank' => $myRow->FinalRank == 9999 ? 'DSQ' : $myRow->FinalRank, 'preseed' => ($myRow->EvFinalFirstPhase == 48 or $myRow->EvFinalFirstPhase == 24) and $myRow->QualRank <= 8 ? '1' : '', 'elims' => array(), 'finals' => array()); if ($myRow->E1Rank !== null && $myRow->E1Score !== null) { $item['elims']['e1']['score'] = $myRow->E1Score; $item['elims']['e1']['rank'] = $myRow->E1Rank; } if ($myRow->E2Rank !== null && $myRow->E2Score !== null) { $item['elims']['e2']['score'] = $myRow->E2Score; $item['elims']['e2']['rank'] = $myRow->E2Rank; } $section['items'][$myRow->EnId] = $item; if ($myRow->IndTimestampFinal > $section['meta']['lastUpdate']) { $section['meta']['lastUpdate'] = $myRow->IndTimestampFinal; } if ($myRow->IndTimestampFinal > $this->data['meta']['lastUpdate']) { $this->data['meta']['lastUpdate'] = $myRow->IndTimestampFinal; } } // ultimo giro $this->data['sections'][$curEvent] = $section; } /* * A questo punto ho i nomi, le qualifiche,le eliminatorie (se ci sono) * e punti+rank delle precedenti. * Mi mancano le finali. Che prendo SOLO se lo shootoff è risolto * */ $q = "(\r\n\t\t\t\tSELECT\r\n\t\t\t\t\tf1.FinEvent AS `event`,f1.FinAthlete AS `athlete`,f1.FinMatchNo AS `matchNo`,f1.FinScore AS `score`,f1.FinSetScore AS `setScore`,f1.FinSetPoints AS `setPoints`,f1.FinTie AS `tie`,f1.FinArrowstring AS `arrowstring`,f1.FinTiebreak AS `tiebreak`,\r\n\t\t\t\t\tf2.FinAthlete AS `oppAthlete`,f2.FinMatchNo AS `oppMatchNo`,f2.FinScore AS `oppScore`,f2.FinSetScore AS `oppSetScore`,f2.FinSetPoints AS `oppSetPoints`,f2.FinTie AS `oppTie`,f2.FinArrowstring AS `oppArrowstring`,f2.FinTiebreak AS `oppTiebreak`,\r\n\t\t\t\t\tGrPhase, EvProgr, IndRankFinal\r\n\t\t\t\t\tFROM Finals AS f1\r\n\t\t\t\t\tINNER JOIN Events\r\n\t\t\t\t\t\tON EvTournament=f1.FinTournament AND EvCode=f1.FinEvent AND EvTeamEvent=0 AND EvShootOff=1\r\n\t\t\t\t\tINNER JOIN Finals AS f2\r\n\t\t\t\t\t\tON f2.FinEvent=f1.FinEvent AND f2.FinTournament=f1.FinTournament AND f2.FinMatchNo=f1.FinMatchNo+1\r\n\t\t\t\t\tINNER JOIN Grids\r\n\t\t\t\t\t\tON GrMatchNo=f1.FinMatchNo\r\n\t\t\t\t\tINNER JOIN Individuals\r\n\t\t\t\t\t\tON IndTournament={$this->tournament} AND IndEvent=f1.FinEvent AND IndId=f1.FinAthlete\r\n\t\t\t\t\tWHERE\r\n\t\t\t\t\t\tf1.FinTournament={$this->tournament} and f1.FinMatchNo%2=0\r\n\t\t\t\t\t\t{$filter}\r\n\t\t\t\t) union (\r\n\t\t\t\tSELECT\r\n\t\t\t\t\tf1.FinEvent AS `event`,f1.FinAthlete AS `athlete`,f1.FinMatchNo AS `matchNo`,f1.FinScore AS `score`,f1.FinSetScore AS `setScore`,f1.FinSetPoints AS `setPoints`,f1.FinTie AS `tie`,f1.FinArrowstring AS `arrowstring`,f1.FinTiebreak AS `tiebreak`,\r\n\t\t\t\t\tf2.FinAthlete AS `oppAthlete`,f2.FinMatchNo AS `oppMatchNo`,f2.FinScore AS `oppScore`,f2.FinSetScore AS `oppSetScore`,f2.FinSetPoints AS `oppSetPoints`,f2.FinTie AS `oppTie`,f2.FinArrowstring AS `oppArrowstring`,f2.FinTiebreak AS `oppTiebreak`,\r\n\t\t\t\t\tGrPhase, EvProgr, IndRankFinal\r\n\t\t\t\t\tFROM Finals AS f1\r\n\t\t\t\t\tINNER JOIN Events\r\n\t\t\t\t\t\tON EvTournament=f1.FinTournament AND EvCode=f1.FinEvent AND EvTeamEvent=0 AND EvShootOff=1\r\n\t\t\t\t\tINNER JOIN Finals AS f2\r\n\t\t\t\t\t\tON f2.FinEvent=f1.FinEvent AND f2.FinTournament=f1.FinTournament AND f2.FinMatchNo=f1.FinMatchNo-1\r\n\t\t\t\t\tINNER JOIN Grids\r\n\t\t\t\t\t\tON GrMatchNo=f1.FinMatchNo\r\n\t\t\t\t\tINNER JOIN Individuals\r\n\t\t\t\t\t\tON IndTournament={$this->tournament} AND IndEvent=f1.FinEvent AND IndId=f1.FinAthlete\r\n\t\t\t\t\tWHERE\r\n\t\t\t\t\t\tf1.FinTournament={$this->tournament} and f1.FinMatchNo%2=1\r\n\t\t\t\t\t\t{$filter}\r\n \t\t\t\t)\r\n \t\t\t\tORDER BY\r\n \t\t\t\t\tEvProgr ASC, IndRankFinal ASC, GrPhase DESC\r\n\t\t\t"; //print $q;exit; //return; $rr = safe_r_sql($q); if (safe_num_rows($rr) > 0) { while ($row = safe_fetch($rr)) { $arrowstring = array(); for ($i = 0; $i < strlen($row->arrowstring); ++$i) { if (trim($row->arrowstring[$i]) != '') { $arrowstring[] = DecodeFromLetter($row->arrowstring[$i]); } } $tiebreak = array(); for ($i = 0; $i < strlen($row->tiebreak); ++$i) { if (trim($row->tiebreak[$i]) != '') { $tiebreak[] = DecodeFromLetter($row->tiebreak[$i]); } } $oppArrowstring = array(); for ($i = 0; $i < strlen($row->oppArrowstring); ++$i) { if (trim($row->oppArrowstring[$i]) != '') { $oppArrowstring[] = DecodeFromLetter($row->oppArrowstring[$i]); } } $oppTiebreak = array(); for ($i = 0; $i < strlen($row->oppTiebreak); ++$i) { if (trim($row->oppTiebreak[$i]) != '') { $oppTiebreak[] = DecodeFromLetter($row->oppTiebreak[$i]); } } if (!empty($this->data['sections'][$row->event]['items'][$row->athlete])) { $this->data['sections'][$row->event]['items'][$row->athlete]['finals'][$row->GrPhase] = array('score' => $row->score, 'setScore' => $row->setScore, 'setPoints' => $row->setPoints, 'tie' => $row->tie, 'arrowstring' => implode('|', $arrowstring), 'tiebreak' => implode('|', $tiebreak), 'oppAthlete' => $row->oppAthlete, 'oppScore' => $row->oppScore, 'oppSetScore' => $row->oppSetScore, 'oppSetPoints' => $row->oppSetPoints, 'oppTie' => $row->oppTie, 'oppArrowstring' => implode('|', $oppArrowstring), 'oppTiebreak' => implode('|', $oppTiebreak)); } } } }
case 'T': $SQL = "SELECT EvCode, EvEventName, EvFinalFirstPhase FROM Events WHERE EvTournament={$CompId} AND EvTeamEvent=1 AND EvFinalFirstPhase!=0 order by EvProgr"; break; case 'E1': $SQL = "SELECT EvCode, EvEventName, EvFinalFirstPhase FROM Events WHERE EvTournament={$CompId} AND EvTeamEvent=0 and EvElim1>0 AND EvFinalFirstPhase!=0 order by EvProgr"; break; case 'E2': $SQL = "SELECT EvCode, EvEventName, EvFinalFirstPhase FROM Events WHERE EvTournament={$CompId} AND EvTeamEvent=0 and EvElim2>0 AND EvFinalFirstPhase!=0 order by EvProgr"; break; default: $SQL = "SELECT EvCode, EvEventName, EvFinalFirstPhase FROM Events WHERE EvTournament={$CompId} AND EvTeamEvent=0 AND EvFinalFirstPhase!=0 order by EvProgr"; } // Retrieve the Event List $q = safe_r_sql($SQL); while ($r = safe_fetch($q)) { $tmpPhases = array(); if ($EventType[0] == 'E') { $t = safe_r_sql("select distinct left(ElTargetNo, 3) TargetNo\r\n\t\t\t\tfrom Eliminations\r\n\t\t\t\twhere ElTournament={$CompId}\r\n\t\t\t\t\tand ElElimPhase=" . ($EventType[1] - 1) . "\r\n\t\t\t\t\tand ElEventCode='{$r->EvCode}'\r\n\t\t\t\t\tand ElTargetNo>''\r\n\t\t\t\torder by TargetNo"); while ($u = safe_fetch($t)) { $tmpPhases[] = array("code" => "{$EventType}|{$r->EvCode}|{$u->TargetNo}", "name" => (int) $u->TargetNo); } } else { $phases = getPhasesId($r->EvFinalFirstPhase); foreach ($phases as $ph) { $tmpPhases[] = array("code" => bitwisePhaseId($ph), "name" => $ph . "_Phase"); } } $json_array[] = array("code" => $r->EvCode, "name" => $r->EvEventName, "phases" => $tmpPhases); } // Return the json structure with the callback function that is needed by the app SendResult($json_array);