user_action.php 706 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * @var int $id
  4. * @var string $action
  5. */
  6. $controller = new class($id) {
  7. /** @var User */
  8. private $user;
  9. public function __construct(int $id) {
  10. $this->user = User::get($id);
  11. }
  12. public function toggleArchived(): void {
  13. if($this->user->archived) {
  14. $this->user->archived = 0;
  15. Core::addAlert("success", __("User unarchived successfully."));
  16. }
  17. else {
  18. $this->user->archived = 1;
  19. Core::addAlert("success", __("User archived successfully."));
  20. }
  21. $this->user->commit();
  22. Http::redirect($this->user->getURL());
  23. }
  24. };
  25. switch($action) {
  26. case "toggle-archived":
  27. $controller->toggleArchived();
  28. break;
  29. default:
  30. throw new RuntimeException(__("Invalid action."));
  31. }