comparison msite.inc.php @ 792:b42b23073209

Improve printing of results with more options (in the admin interface).
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 21 Nov 2014 21:42:47 +0200
parents 7735f97b2bbf
children 589cb2d88332
comparison
equal deleted inserted replaced
791:771057e1cef1 792:b42b23073209
65 $entryFlagsList = array( 65 $entryFlagsList = array(
66 EFLAG_DISQUALIFIED => array("Disqualified", "img/disqualified.png"), 66 EFLAG_DISQUALIFIED => array("Disqualified", "img/disqualified.png"),
67 EFLAG_PROBLEMS => array("Has problems", "img/problems.png"), 67 EFLAG_PROBLEMS => array("Has problems", "img/problems.png"),
68 ); 68 );
69 69
70
71 //
72 // Results output flags
73 //
74 define("RFLAG_NORMAL", 0);
75 define("RFLAG_DISQUALIFIED", 1);
76 define("RFLAG_HIDDEN_COMPOS", 2);
70 77
71 // 78 //
72 // Competition types 79 // Competition types
73 // 80 //
74 define("COMPO_NORMAL", 0); // Normal voting compo, points determine placement 81 define("COMPO_NORMAL", 0); // Normal voting compo, points determine placement
455 default: return "th"; 462 default: return "th";
456 } 463 }
457 } 464 }
458 465
459 466
460 function stGetCompoResultsSQL($mode, $compo) 467 function stGetCompoResultsSQL($mode, $compo, $flags)
461 { 468 {
462 // 469 //
463 // Act based on competition type 470 // Act based on competition type
464 // 471 //
465 switch ($compo["ctype"]) 472 switch ($compo["ctype"])
522 break; 529 break;
523 } 530 }
524 531
525 return $sql." ". 532 return $sql." ".
526 "WHERE entries.compo_id=".$compo["id"]." ". 533 "WHERE entries.compo_id=".$compo["id"]." ".
527 "AND (entries.flags & ".EFLAG_DISQUALIFIED.")=0 ". 534 (($flags & RFLAG_DISQUALIFIED) ? "" : "AND (entries.flags & ".EFLAG_DISQUALIFIED.")=0 ").
528 $extra; 535 $extra;
529 } 536 }
530 537
531 538
532 function stGetCompoResults() 539 function stGetCompoResults($flags)
533 { 540 {
534 $voteKeyMode = stGetSetting("voteKeyMode"); 541 $voteKeyMode = stGetSetting("voteKeyMode");
535 $out = array(); 542 $out = array();
536 $sql = "SELECT * FROM compos WHERE visible<>0 ORDER BY name DESC"; 543 $sql = "SELECT * FROM compos ".(($flags & RFLAG_HIDDEN_COMPOS) ? "" : "WHERE visible<>0 ")."ORDER BY name DESC";
537 if (($res = stExecSQL($sql)) === false) 544 if (($res = stExecSQL($sql)) === false)
538 return $out; 545 return $out;
539 546
540 // For each compo that has been set visible 547 // For each compo that has been set visible
541 foreach ($res as $compo) 548 foreach ($res as $compo)
542 { 549 {
543 // Check if there are any entries for it 550 // Check if there are any entries for it
544 $sql = 551 $sql =
545 "SELECT COUNT(*) FROM entries ". 552 "SELECT COUNT(*) FROM entries ".
546 "WHERE compo_id=".$compo["id"]." ". 553 "WHERE compo_id=".$compo["id"].
547 "AND (entries.flags & ".EFLAG_DISQUALIFIED.")=0"; 554 (($flags & RFLAG_DISQUALIFIED) ? "" : " AND (entries.flags & ".EFLAG_DISQUALIFIED.")=0");
548 555
549 if (($nentries = stFetchSQLColumn($sql)) !== FALSE && $nentries > 0) 556 if (($nentries = stFetchSQLColumn($sql)) !== FALSE && $nentries > 0)
550 { 557 {
551 // Get voting results by mode 558 // Get voting results by mode
552 $sql = stGetCompoResultsSQL($voteKeyMode, $compo); 559 $sql = stGetCompoResultsSQL($voteKeyMode, $compo, $flags);
553 560
554 $out[$compo["id"]] = $compo; 561 $out[$compo["id"]] = $compo;
555 $out[$compo["id"]]["results"] = array(); 562 $out[$compo["id"]]["results"] = array();
556 $prev = FALSE; 563 $prev = FALSE;
557 $index = 0; 564 $index = 0;
578 $name = stStrChopPad($entry["name"], 30); 585 $name = stStrChopPad($entry["name"], 30);
579 $author = stStrChopPad($entry["author"], 30); 586 $author = stStrChopPad($entry["author"], 30);
580 587
581 $out = sprintf(" %s", $html ? chentities($name) : $name); 588 $out = sprintf(" %s", $html ? chentities($name) : $name);
582 589
590 // Author?
583 if ($showAuthor) 591 if ($showAuthor)
584 $out .= sprintf(" by %s", $html ? chentities($author) : $author); 592 $out .= sprintf(" by %s", $html ? chentities($author) : $author);
585 593
594 // Points?
586 if ($points !== FALSE) 595 if ($points !== FALSE)
587 $out .= sprintf(" (%d pts)", $points); 596 $out .= sprintf(" (%d pts)", $points);
588 597
598 // Add disqualified flag etc.
599 if ($entry["flags"] & EFLAG_DISQUALIFIED)
600 $out .= " [DISQ]";
601
589 return $out."\n"; 602 return $out."\n";
590 } 603 }
591 604
592 605
593 function stGetCompoResultsASCIIStr($html) 606 function stGetCompoResultsASCIIStr($html, $flags)
594 { 607 {
595 $out = ""; 608 $out = "";
596 foreach (stGetCompoResults() as $compo) 609 foreach (stGetCompoResults($flags) as $compo)
597 { 610 {
598 // Output compo title / header 611 // Output compo title / header
599 if ($html) 612 if ($html)
600 { 613 {
601 $out .= 614 $out .=