/**
  * retrieve player ranking and global ranking.
  * route : player
  */
 public function retrieve_leaderboard()
 {
     if (Authenticate::is_player()) {
         if (isset($_POST['token']) && Authenticate::is_valid_token($_POST['token'])) {
             $this->model_leaderboard = Leaderboard::getInstance();
             $player_ranking = $this->model_leaderboard->get_player_ranking();
             $global_ranking = $this->model_leaderboard->get_global_ranking();
             $binding = array("result_var" => "session_ready", "leaderboard_player_var" => json_encode($player_ranking), "leaderboard_global_var" => json_encode($global_ranking));
             binding_data($binding);
         } else {
             transport("error404");
         }
     } else {
         $binding = array("result_var" => "no_session");
         binding_data($binding);
     }
 }
 /**
  * update product price.
  *
  * role: player
  */
 public function update_product_price()
 {
     if (Authenticate::is_player()) {
         if (isset($_POST['token']) && Authenticate::is_valid_token($_POST['token'])) {
             $this->model_product = Product::getInstance();
             $product = $_POST['product_data'];
             $result = $this->model_product->update_player_product($product);
             $binding = array("result_var" => "session_ready", "status_var" => $result);
             binding_data($binding);
         } else {
             transport("error404");
         }
     } else {
         $binding = array("result_var" => "no_session");
         binding_data($binding);
     }
 }
 /**
  * save new achievement via REST.
  * role: player
  */
 public function unlock_achievement()
 {
     if (Authenticate::is_player()) {
         if (isset($_POST['token']) && Authenticate::is_valid_token($_POST['token'])) {
             $this->model_achievement = Achievement::getInstance();
             /*
              * populate type of achievement.
              * invoke method to unlock the achievement.
              * log this event about achievement earning.
              */
             $achievement = $_POST["achievement"];
             $result = $this->model_achievement->unlock_achievement($achievement);
             $log = Log::getInstance();
             $log->logging_game_earn_achievement("Achievement id {$achievement}");
             $binding = array("result_var" => "session_ready", "unlock_status" => $result);
             binding_data($binding);
         } else {
             transport("error404");
         }
     } else {
         $binding = array("result_var" => "no_session");
         binding_data($binding);
     }
 }
 /**
  * update employee status.
  * role: player
  */
 public function update_employee()
 {
     if (Authenticate::is_player()) {
         if (isset($_POST['token']) && Authenticate::is_valid_token($_POST['token'])) {
             $this->model_employee = Employee::getInstance();
             $employee = $_POST['employee_data'];
             $result = $this->model_employee->update_employee_status($employee);
             $binding = array("result_var" => "session_ready", "status_var" => $result);
             binding_data($binding);
         } else {
             transport("error404");
         }
     } else {
         $binding = array("result_var" => "no_session");
         binding_data($binding);
     }
 }
 /**
  * retrieve balance sheet from database.
  * role: player
  */
 public function retrieve_balance()
 {
     if (Authenticate::is_player()) {
         if (isset($_POST['token']) && Authenticate::is_valid_token($_POST['token'])) {
             $this->model_journal = Journal::getInstance();
             /*
              * invoke method to retrieve balance data.
              * convert into json format and binding these data.
              */
             $result = $this->model_journal->get_balance_sheet();
             $binding = array("result_var" => "session_ready", "balance_var" => json_encode($result, JSON_PRETTY_PRINT));
             binding_data($binding);
         } else {
             transport("error404");
         }
     } else {
         $binding = array("result_var" => "no_session");
         binding_data($binding);
     }
 }
 /**
  * role: player
  */
 public function update_material()
 {
     if (Authenticate::is_player()) {
         if (isset($_POST['token']) && Authenticate::is_valid_token($_POST['token'])) {
             $this->model_material = Material::getInstance();
             $material = $_POST["material_data"];
             $result = true;
             foreach (json_decode($material) as $attribute) {
                 $result = $this->model_material->update_material($attribute->pma_id, $attribute->pma_stock, $attribute->pma_expired_remaining);
             }
             $binding = array("result_var" => "session_ready", "status_var" => $result);
             binding_data($binding);
         } else {
             transport("error404");
         }
     } else {
         $binding = array("result_var" => "no_session");
         binding_data($binding);
     }
 }
 /**
  * retrieve another avatar from another user.
  * role: player
  * @return string
  */
 public function get_simulation_avatar()
 {
     if (Authenticate::is_player()) {
         if (true || isset($_POST['token']) && Authenticate::is_valid_token($_POST['token'])) {
             $this->model_player = Player::getInstance();
             /*
              * retrieve at least 3 avatar except player.
              * wrap it up and convert to json format.
              */
             $avatar = $this->model_player->fetch_simulation_avatar();
             $binding = array("result_var" => "session_ready", "avatar_var" => json_encode($avatar, JSON_PRETTY_PRINT));
             binding_data($binding);
         } else {
             transport("error404");
         }
     } else {
         $binding = array("result_var" => "no_session");
         binding_data($binding);
     }
 }