lottery.class.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 deleteLottery(int $_id)
  107. {
  108. db::query("DELETE FROM " . DB_T_LOTTERY . " WHERE id = :id");
  109. db::bind(':id', $_id);
  110. return db::execute();
  111. }
  112. public static function deleteInscriptionLottery(int $_id)
  113. {
  114. db::query("DELETE FROM " . DB_T_LOTTERY_INSCRITS . " WHERE id_lottery = :id_lottery");
  115. db::bind(':id_lottery', $_id);
  116. return db::execute();
  117. }
  118. public static function setDateLottery(int $_id, int $_nb)
  119. {
  120. db::query("UPDATE " . DB_T_LOTTERY . " "
  121. . "SET " . DB_T_LOTTERY . ".sortDate = CURRENT_TIMESTAMP(), "
  122. . DB_T_LOTTERY . ".sortNb = :sortNb, "
  123. . DB_T_LOTTERY . ".sortBy = :sortBy "
  124. . "WHERE " . DB_T_LOTTERY . ".id = :id");
  125. db::bind(':sortNb', $_nb);
  126. db::bind(':sortBy', session::getId());
  127. db::bind(':id', $_id);
  128. try {
  129. db::execute();
  130. return TRUE;
  131. } catch (Exception $ex) {
  132. alert::recError("ERREUR TECHNIQUE : Au niveau de l'écriture en base de données lors de la datation");
  133. return FALSE;
  134. }
  135. }
  136. public static function getInscriptionData(int $_id)
  137. {
  138. db::query("SELECT "
  139. . "COUNT(" . DB_T_LOTTERY_INSCRITS . ".login) AS inscrits, "
  140. . "SUM(IF(" . DB_T_LOTTERY_INSCRITS . ".valide = 1, 1, 0)) AS eligible, "
  141. . "SUM(IF(" . DB_T_LOTTERY_INSCRITS . ".valide = 0, 1, 0)) AS ineligible "
  142. . "FROM " . DB_T_LOTTERY_INSCRITS . " "
  143. . "WHERE " . DB_T_LOTTERY_INSCRITS . ".id_lottery = :id_lottery");
  144. db::bind(':id_lottery', $_id);
  145. return db::single();
  146. }
  147. public static function getFiche(int $_id)
  148. {
  149. db::query("SELECT * FROM " . DB_T_LOTTERY . " WHERE id = :id");
  150. db::bind(':id', $_id);
  151. return db::single();
  152. }
  153. public static function lastLottery()
  154. {
  155. db::query("SELECT MAX(id) AS id FROM " . DB_T_LOTTERY);
  156. return db::single()["id"];
  157. }
  158. }