Change_Game_Mode_Action.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * File for changing the game mode.
  4. *
  5. * Implements an action function to be called from the {@see Controller}.
  6. *
  7. * @category Action
  8. */
  9. require_once(PATH::ACTION . "Action.php");
  10. /**
  11. * Sets the score for a team.
  12. *
  13. * Reads the POST parameters looking for the following KEYS:
  14. * player
  15. * team
  16. * score
  17. * Validates the data and sets the score.
  18. */
  19. class Change_Game_Mode_Action extends Action{
  20. /**
  21. * Executes the action.
  22. * @todo: secure
  23. */
  24. public function execute(){
  25. $player = filter_input(INPUT_GET, "player");
  26. $mode = filter_input(INPUT_GET, "mode");
  27. if ($mode != GAME_MODE_ID::NORMAL && $mode != GAME_MODE_ID::RTA){
  28. $this->code = 400;
  29. $this->message = "POST parameter 'mode' not specified or invalid.";
  30. return;
  31. }
  32. $statement = get_context()->get_db()->prepare("
  33. UPDATE player
  34. SET mode = :mode
  35. WHERE id = :id;
  36. ");
  37. $statement->bindValue(":mode", $mode, SQLITE3_TEXT);
  38. $statement->bindValue(":id", $player, SQLITE3_TEXT);
  39. $statement->execute();
  40. $this->code = 204;
  41. $this->message = "No content.";
  42. return;
  43. }
  44. }