rate_team.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * File for the team score modification action.
  4. *
  5. * Implements an action function to be called from the {@see Controller}.
  6. *
  7. * @author Iñigo Valentin <i@inigovalentin.com>
  8. * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
  9. * @package SWDB
  10. */
  11. /**
  12. * Sets the score for a team.
  13. *
  14. * Reads the POST parameters looking for the following KEYS:
  15. * player: Owner's player ID.
  16. * team: Team ID.
  17. * score: New score.
  18. * Validates the data and sets the score.
  19. *
  20. * @todo: Check that the user can rate this team.
  21. * @return int 201 on success, HTTP erro status codes on error.
  22. * @category Action
  23. */
  24. function action(){
  25. $player = filter_input(INPUT_GET, "player");
  26. $team = filter_input(INPUT_GET, "team");
  27. $score = intval(filter_input(INPUT_GET, "score"));
  28. $statement = get_context()->get_db()->prepare("
  29. UPDATE team
  30. SET score = :score
  31. WHERE
  32. player = :player AND
  33. id = :team;
  34. ");
  35. $statement->bindValue(":score", $score, SQLITE3_TEXT);
  36. $statement->bindValue(":player", $player, SQLITE3_TEXT);
  37. $statement->bindValue(":team", $team, SQLITE3_TEXT);
  38. $statement->execute();
  39. return 201;
  40. }