Adefinir  Finale
AjaxRequest.php
Go to the documentation of this file.
1 <?php
2 
10 
11 use App\Http\Controllers\GameController;
12 
13 
14 class AjaxRequest {
15 
16 
27  public static function request() {
28  // On vérifie ici les données recues dans POST["function"]
29  if( !empty( $_POST["function"] ) ) {
30  $function = $_POST["function"];
31 
32  switch($function) {
33 
34  case "hire":
35  print AjaxRequest::hireORfire( true, $_POST["jobName"] );
36  break;
37 
38  case "fire":
39  print AjaxRequest::hireORfire( false, $_POST["jobName"] );
40  break;
41 
42  case "action":
43  AjaxRequest::actions($_POST);
44  break;
45 
46  case "testGame":
48  break;
49 
50  default:
51  // Rien
52  break;
53  }
54  }
55 
56  }
57 
58 
70  protected static function hireORfire( string $hORf, string $jobName ) : int {
71 
72  $game = $_SESSION["gameController"];
73  $res = -1;
74 
75  if( $hORf == true ) {
76  $res = $game->hire($jobName);
77  }
78  else if ( $hORf == false ) {
79  $res = $game->fire($jobName);
80  }
81 
82  return $res;
83  }
84 
85 
98  protected static function actions( $post ) {
99  $actions;
100  foreach($post as $key => $value) {
101  if( strval($key) == "actions" ) {
102  $actions = json_decode($post[$key]);
103  }
104  }
105 
106  $nbDaysLeft = $_SESSION["gameController"]->nbDay($actions);
107  print $nbDaysLeft;
108  }
109 
110 
111 
121  protected static function testGame() {
122  $nbDaysLeft = $_SESSION["gameController"]->substractDay();
123  print $nbDaysLeft;
124  }
125 
126 }
App\Models\scripts\AjaxRequest\testGame
static testGame()
Definition: AjaxRequest.php:121
App\Models\scripts\AjaxRequest\actions
static actions( $post)
Definition: AjaxRequest.php:98
App\Models\scripts\AjaxRequest
Definition: AjaxRequest.php:14
$game
$game
Definition: results.blade.php:7
App\Models\scripts
Definition: AjaxRequest.php:9
App\Models\scripts\AjaxRequest\request
static request()
Definition: AjaxRequest.php:27
App\Models\scripts\AjaxRequest\hireORfire
static hireORfire(string $hORf, string $jobName)
Definition: AjaxRequest.php:70