delete_team.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * File for the team deletion 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. * Deletes a team.
  13. *
  14. * Reads the POST parameters looking for the following KEYS:
  15. * player: the team owner's player id.
  16. * id: the team id.
  17. *
  18. * @return int 201 on success, HTTP error status codes on failure.
  19. * @category Action
  20. */
  21. function action(){
  22. $player = filter_input(INPUT_POST, 'player');
  23. $id = filter_input(INPUT_POST, 'id');
  24. $statement = get_context()->get_db()->prepare('DELETE FROM team WHERE player = :player AND id = :id;');
  25. $statement->bindValue(':player', $player, SQLITE3_TEXT);
  26. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  27. $statement->execute();
  28. $statement = get_context()->get_db()->prepare('DELETE FROM team_unit WHERE team = :id;');
  29. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  30. $statement->execute();
  31. return 201;
  32. }