quizz.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. class Period {
  3. public function Period($data) {
  4. $this->id = $data["id"];
  5. $this->start = strtotime($data["start"]);
  6. $this->end = strtotime($data["end"]);
  7. $this->host = $data["host"];
  8. }
  9. }
  10. function getLastQuizzPeriod() {
  11. require_once("./.htconfig.php");
  12. $dblink = getlink();
  13. $result = array();
  14. $userCountPerChan = $dblink->prepare("SELECT * FROM `knackizz_period` ORDER BY `id` DESC LIMIT 1");
  15. $userCountPerChan->execute();
  16. if ($row = $userCountPerChan->fetch(PDO::FETCH_ASSOC))
  17. return new Period($row);
  18. return null;
  19. }
  20. function getCurrentOrLastQuizzPeriod($periodId)
  21. {
  22. if ($periodId == null)
  23. return getLastQuizzPeriod();
  24. require_once("./.htconfig.php");
  25. $dblink = getlink();
  26. $result = array();
  27. $userCountPerChan = $dblink->prepare("SELECT * FROM `knackizz_period` WHERE `id`=:id");
  28. $userCountPerChan->execute([ "id" => $periodId ]);
  29. if ($row = $userCountPerChan->fetch(PDO::FETCH_ASSOC))
  30. return new Period($row);
  31. return getLastQuizzPeriod();
  32. }
  33. function getPreviousQuizzPeriod($periodId) {
  34. require_once("./.htconfig.php");
  35. $dblink = getlink();
  36. $result = array();
  37. $userCountPerChan = $dblink->prepare("SELECT * FROM `knackizz_period` WHERE `id` < :id ORDER BY `id` DESC LIMIT 1");
  38. $userCountPerChan->execute([ "id" => $periodId ]);
  39. if ($row = $userCountPerChan->fetch(PDO::FETCH_ASSOC))
  40. return new Period($row);
  41. return null;
  42. }
  43. function getNextQuizzPeriod($periodId) {
  44. require_once("./.htconfig.php");
  45. $dblink = getlink();
  46. $result = array();
  47. $userCountPerChan = $dblink->prepare("SELECT * FROM `knackizz_period` WHERE `id` > :id ORDER BY `id` DESC LIMIT 1");
  48. $userCountPerChan->execute([ "id" => $periodId ]);
  49. if ($row = $userCountPerChan->fetch(PDO::FETCH_ASSOC))
  50. return new Period($row);
  51. return null;
  52. }
  53. function getQuizzScores($periodId) {
  54. $result = [];
  55. require_once("./.htconfig.php");
  56. $dblink = getlink();
  57. $result = array();
  58. $userCountPerChan = $dblink->prepare("SELECT * FROM `knackizz_scores` WHERE `period_id`=:pid ORDER BY `score` DESC");
  59. $userCountPerChan->execute([ "pid" => $periodId ]);
  60. $i = 0;
  61. while ($row = $userCountPerChan->fetch(PDO::FETCH_ASSOC))
  62. $result[] = array(
  63. "rank" => ++$i,
  64. "pseudo" => $row["pseudo"],
  65. "score" => $row["score"]
  66. );
  67. return $result;
  68. }
  69. ?>