lottery.class.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. class lottery
  3. {
  4. public static function getLotterys()
  5. {
  6. db::query("SELECT "
  7. . "" . DB_T_LOTTERY . ".id, "
  8. . "" . DB_T_LOTTERY . ".md5, "
  9. . "" . DB_T_LOTTERY . ".titre, "
  10. . "" . DB_T_LOTTERY . ".description, "
  11. . "" . DB_T_LOTTERY . ".sortDate, "
  12. . "COUNT(" . DB_T_LOTTERY_INSCRITS . ".login) AS m_inscrits, "
  13. . "SUM(IF(" . DB_T_LOTTERY_INSCRITS . ".valide = 1, 1, 0)) AS m_eligible, "
  14. . "SUM(IF(" . DB_T_LOTTERY_INSCRITS . ".valide = 0, 1, 0)) AS m_ineligible, "
  15. . "COUNT(" . DB_T_LOTTERY_INSCRITS . ".selected) AS m_selected, "
  16. . "" . DB_T_LOTTERY . ".cree, "
  17. . "" . DB_T_LOTTERY . ".maj, "
  18. . "CONCAT (" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS 'user' "
  19. . "FROM " . DB_T_LOTTERY . " "
  20. . "LEFT JOIN " . DB_T_LOTTERY_INSCRITS . " ON " . DB_T_LOTTERY_INSCRITS . ".id_lottery = " . DB_T_LOTTERY . ".id "
  21. . "INNER JOIN " . DB_T_USER . " ON " . DB_T_LOTTERY . ".id_user = " . DB_T_USER . ".id "
  22. . "GROUP BY 1");
  23. return db::resultset();
  24. }
  25. public static function getInscription(int $_id){
  26. db::query("SELECT "
  27. . "" . DB_T_LOTTERY_INSCRITS . ".id_lottery, "
  28. . "" . DB_T_LOTTERY_INSCRITS . ".id_salarie, "
  29. . "" . DB_T_LOTTERY_INSCRITS . ".id_presta, "
  30. . "" . DB_T_LOTTERY_INSCRITS . ".id_dossier, "
  31. . "IF(" . DB_T_SALARIES . ".actif = 1, 'ACTIF', IF(" . DB_T_SALARIES . ".actif = 0, 'INACTIF', 'ABSENT')) AS actif , "
  32. . "UCASE(" . DB_T_LOTTERY_INSCRITS . ".login) AS login, "
  33. . "UCASE(" . DB_T_LOTTERY_INSCRITS . ".prenom) AS prenom, "
  34. . "UCASE(" . DB_T_LOTTERY_INSCRITS . ".nom) AS nom, "
  35. . "IF(" . DB_T_LOTTERY_INSCRITS . ".valide = 1, 'OUI', 'NON') AS valide, "
  36. . "" . DB_T_LOTTERY_INSCRITS . ".selected, "
  37. . "" . DB_T_LOTTERY_INSCRITS . ".cree, "
  38. . "" . DB_T_LOTTERY_INSCRITS . ".id_user, "
  39. . "CONCAT(" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom ) AS admin, "
  40. . "" . DB_T_LOTTERY_INSCRITS . ".cree "
  41. . "FROM " . DB_T_LOTTERY_INSCRITS . " "
  42. . "INNER JOIN " . DB_T_USER . " ON " . DB_T_LOTTERY_INSCRITS . ".id_user = " . DB_T_USER . ".id "
  43. . "LEFT JOIN " . DB_T_SALARIES . " ON " . DB_T_LOTTERY_INSCRITS . ".id_salarie = " . DB_T_SALARIES . ".id "
  44. . "WHERE " . DB_T_LOTTERY_INSCRITS . ".id_lottery = :id_lottery");
  45. db::bind(':id_lottery', $_id);
  46. return db::resultset();
  47. }
  48. public static function getWinners(int $_id){
  49. db::query("SELECT "
  50. . "" . DB_T_LOTTERY_INSCRITS . ".id_salarie, "
  51. . "" . DB_T_LOTTERY_INSCRITS . ".id_dossier, "
  52. . "UCASE(" . DB_T_LOTTERY_INSCRITS . ".login) AS login, "
  53. . "UCASE(" . DB_T_LOTTERY_INSCRITS . ".prenom) AS prenom, "
  54. . "UCASE(" . DB_T_LOTTERY_INSCRITS . ".nom) AS nom, "
  55. . "" . DB_T_LOTTERY_INSCRITS . ".selected "
  56. . "FROM " . DB_T_LOTTERY_INSCRITS . " "
  57. . "WHERE " . DB_T_LOTTERY_INSCRITS . ".id_lottery = :id_lottery AND " . DB_T_LOTTERY_INSCRITS . ".selected IS NOT NULL");
  58. db::bind(':id_lottery', $_id);
  59. return db::resultset();
  60. }
  61. public static function getCloture(int $_id){
  62. db::query("SELECT "
  63. . DB_T_LOTTERY . ".sortDate, "
  64. . DB_T_LOTTERY . ".sortNb, "
  65. . "CONCAT (" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS 'sortBy' "
  66. . "FROM " . DB_T_LOTTERY . " "
  67. . "INNER JOIN " . DB_T_USER . " ON " . DB_T_LOTTERY . ".id_user = " . DB_T_USER . ".id "
  68. . "WHERE " . DB_T_LOTTERY . ".id = :id");
  69. db::bind(':id', $_id);
  70. return db::single();
  71. }
  72. public static function getSortInscription(int $_id, int $_sort = 0)
  73. {
  74. if($_sort == 0){
  75. $sqlSort = "";
  76. } else {
  77. $sqlSort = " ORDER BY RAND() LIMIT " . $_sort;
  78. }
  79. db::query("SELECT "
  80. . "" . DB_T_LOTTERY_INSCRITS . ".id_lottery, "
  81. . "" . DB_T_LOTTERY_INSCRITS . ".id_salarie, "
  82. . "" . DB_T_LOTTERY_INSCRITS . ".id_dossier, "
  83. . "UCASE(" . DB_T_LOTTERY_INSCRITS . ".login) AS login, "
  84. . "UCASE(" . DB_T_LOTTERY_INSCRITS . ".prenom) AS prenom, "
  85. . "UCASE(" . DB_T_LOTTERY_INSCRITS . ".nom) AS nom "
  86. . "FROM " . DB_T_LOTTERY_INSCRITS . " "
  87. . "INNER JOIN " . DB_T_SALARIES . " ON " . DB_T_LOTTERY_INSCRITS . ".id_salarie = " . DB_T_SALARIES . ".id "
  88. . "WHERE " . DB_T_LOTTERY_INSCRITS . ".id_lottery = :id_lottery AND " . DB_T_SALARIES . ".actif = 1" . $sqlSort);
  89. db::bind(':id_lottery', $_id);
  90. return db::resultset();
  91. }
  92. public static function setSortLottery(int $_idDossier)
  93. {
  94. db::query("UPDATE " . DB_T_LOTTERY_INSCRITS . " "
  95. . "SET " . DB_T_LOTTERY_INSCRITS . ".selected = CURRENT_TIMESTAMP() "
  96. . "WHERE " . DB_T_LOTTERY_INSCRITS . ".id_dossier = :id_dossier");
  97. db::bind(':id_dossier', $_idDossier);
  98. try {
  99. db::execute();
  100. return TRUE;
  101. } catch (Exception $ex) {
  102. alert::recError("ERREUR TECHNIQUE : Au niveau de l'écriture en base de données lors du tirage au sort");
  103. return FALSE;
  104. }
  105. }
  106. public static function setDateLottery(int $_id, int $_nb)
  107. {
  108. db::query("UPDATE " . DB_T_LOTTERY . " "
  109. . "SET " . DB_T_LOTTERY . ".sortDate = CURRENT_TIMESTAMP(), "
  110. . DB_T_LOTTERY . ".sortNb = :sortNb, "
  111. . DB_T_LOTTERY . ".sortBy = :sortBy "
  112. . "WHERE " . DB_T_LOTTERY . ".id = :id");
  113. db::bind(':sortNb', $_nb);
  114. db::bind(':sortBy', session::getId());
  115. db::bind(':id', $_id);
  116. try {
  117. db::execute();
  118. return TRUE;
  119. } catch (Exception $ex) {
  120. alert::recError("ERREUR TECHNIQUE : Au niveau de l'écriture en base de données lors de la datation");
  121. return FALSE;
  122. }
  123. }
  124. public static function getInscriptionData(int $_id)
  125. {
  126. db::query("SELECT "
  127. . "COUNT(" . DB_T_LOTTERY_INSCRITS . ".login) AS inscrits, "
  128. . "SUM(IF(" . DB_T_LOTTERY_INSCRITS . ".valide = 1, 1, 0)) AS eligible, "
  129. . "SUM(IF(" . DB_T_LOTTERY_INSCRITS . ".valide = 0, 1, 0)) AS ineligible "
  130. . "FROM " . DB_T_LOTTERY_INSCRITS . " "
  131. . "WHERE " . DB_T_LOTTERY_INSCRITS . ".id_lottery = :id_lottery");
  132. db::bind(':id_lottery', $_id);
  133. return db::single();
  134. }
  135. public static function getFiche(int $_id)
  136. {
  137. db::query("SELECT * FROM " . DB_T_LOTTERY . " WHERE id = :id");
  138. db::bind(':id', $_id);
  139. return db::single();
  140. }
  141. public static function lastLottery()
  142. {
  143. db::query("SELECT MAX(id) AS id FROM " . DB_T_LOTTERY);
  144. return db::single()["id"];
  145. }
  146. }