comparison msite.inc.php @ 511:6fe66ea0e954

Move most of the results code to site module, remove the support for HTML type output.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 08 Dec 2013 02:16:26 +0200
parents b6fe46c86ff3
children 998a09b332f1
comparison
equal deleted inserted replaced
510:25bc2087869e 511:6fe66ea0e954
386 386
387 return $str; 387 return $str;
388 } 388 }
389 389
390 390
391 function stStrKludge($str)
392 {
393 $tmp = $str;
394 foreach (array("ä" => "ae", "ö" => "oe", "Ä" => "Ae", "Ö" => "Oe") as $sfrom => $sto)
395 $tmp = str_replace($sfrom, $sto, $tmp);
396
397 return $tmp;
398 }
399
400
401 function stGetNumberSuffix($val)
402 {
403 switch ($val)
404 {
405 case 1: return "st";
406 case 2: return "nd";
407 case 3: return "rd";
408 case 4: case 5: case 6:
409 case 7: case 8: case 9: return "th";
410 default: return "th";
411 }
412 }
413
414
415 function stGetCompoResultsASCIIStr($showAuthors)
416 {
417 if (($res = stExecSQL("SELECT * FROM compos WHERE visible<>0 ORDER BY name DESC")) === false)
418 return "";
419
420 $voteKeyMode = stGetSetting("voteKeyMode");
421 $out = "";
422
423 // For each compo that has been set visible
424 foreach ($res as $compo)
425 {
426 // Check if there are any entries for it
427 $sql =
428 "SELECT COUNT(*) FROM entries ".
429 "WHERE compo_id=".$compo["id"];
430
431 if (($nentries = stFetchSQLColumn($sql)) !== FALSE && $nentries > 0)
432 {
433 // Get voting results by mode
434 switch ($voteKeyMode)
435 {
436 case VOTE_FREELY:
437 $sql =
438 "SELECT entries.*,SUM(votes.value) AS votesum FROM entries ".
439 "LEFT JOIN votes ON votes.entry_id=entries.id ".
440 "WHERE entries.compo_id=".$compo["id"];
441 break;
442
443 case VOTE_ACTIVATE:
444 $sql =
445 "SELECT entries.*, ".
446 "(SELECT SUM(votes.value) FROM votes ".
447 "LEFT JOIN votekeys ON votes.key_id=votekeys.id ".
448 "WHERE votes.entry_id=entries.id AND votekeys.active<>0) ".
449 "AS votesum ".
450 "FROM entries ".
451 "WHERE entries.compo_id=".$compo["id"];
452 break;
453
454 case VOTE_ASSIGN:
455 $sql =
456 "SELECT entries.*,SUM(votes.value) AS votesum FROM entries ".
457 "LEFT JOIN votes ON votes.entry_id=entries.id ".
458 "LEFT JOIN attendees ON votes.key_id=attendees.key_id ".
459 "WHERE entries.compo_id=".$compo["id"]." ".
460 "AND attendees.key_id<>0";
461
462 $sql =
463 "SELECT entries.*, ".
464 "(SELECT SUM(votes.value) FROM votes ".
465 "LEFT JOIN votekeys ON votes.key_id=votekeys.id ".
466 "LEFT JOIN attendees ON votekeys.id=attendees.key_id ".
467 "WHERE votes.entry_id=entries.id AND attendees.key_id<>0) ".
468 "AS votesum ".
469 "FROM entries ".
470 "WHERE entries.compo_id=".$compo["id"];
471 break;
472 }
473
474 $sql .= " ".
475 "GROUP BY entries.id ".
476 "ORDER BY votesum DESC";
477
478 // List results
479 $prev = FALSE;
480 $index = 0;
481
482 $out .=
483 "<pre>\n".
484 "<b> ".chentities($compo["name"])." </b>\n".
485 str_repeat("=", strlen($compo["name"]) + 2)."-- - .\n\n";
486
487 foreach (stExecSQL($sql) as $entry)
488 {
489 if ($entry["votesum"] !== $prev)
490 {
491 $index++;
492 $out .= sprintf("%3d%s.", $index, stGetNumberSuffix($index));
493 }
494 else
495 $out .= " -''-";
496
497 $out .= sprintf(" %s by %s (%d pts)\n",
498 chentities(stStrChop(stStrKludge($entry["name"]), 30)),
499 chentities(stStrChop($showAuthors ? stStrKludge($entry["author"]) : "-", 30)),
500 $entry["votesum"]);
501
502 $prev = $entry["votesum"];
503 }
504 $out .= "\n\n</pre>\n";
505 }
506 }
507
508 return $out;
509 }
510
511
512
391 function stNormalizeListSlideOrder($list_id) 513 function stNormalizeListSlideOrder($list_id)
392 { 514 {
393 } 515 }
394 516
395 517