/**
  * export/download top 10 player into pdf
  * role: administrator
  */
 public function get_player_top_10()
 {
     if (authenticate::is_authorized()) {
         $model_report = new ReportGenerator();
         $model_leaderboard = Leaderboard::getInstance();
         $model_report->get_report_top_10($model_leaderboard->get_top10_ranking());
         $model_report->print_report();
     } else {
         transport("administrator");
     }
 }
 /**
  * after user has logged in, player will redirected this page.
  * if the player session exist then player click home in navigation then redirected here too.
  * role: player
  * redirected from: Controller.Page.index() if user session is exist
  *                  Controller.Player.login() if credential is granted
  *                  Controller.Player.logout() if destroy current session is failed
  *                  Controller.Player.update_profile() if profile is updated
  *                  Controller.Player.update_avatar() if avatar is changed
  */
 public function sign()
 {
     if (Authenticate::is_player()) {
         $model_leaderboard = Leaderboard::getInstance();
         $this->framework->view->page = "index";
         $this->framework->view->section = PageController::SIGN;
         $this->framework->view->content = "/frontend/pages/index";
         $this->framework->view->summary = $model_leaderboard->get_player_ranking();
         $this->framework->view->show("frontend/template");
     } else {
         transport("page");
     }
 }
 /**
  * export/download overall report into pdf
  * role: administrator
  */
 public function get_overall()
 {
     if (Authenticate::is_authorized()) {
         $model_player = Player::getInstance();
         $model_feedback = Feedback::getInstance();
         $model_administrator = Administrator::getInstance();
         $model_leaderboard = Leaderboard::getInstance();
         $model_report = new ReportGenerator();
         $model_report->get_report_overall($model_player->get_player_report(), $model_feedback->retrieve_feedback_report(), $model_administrator->retrieve_traffic_report(), $model_leaderboard->get_top10_ranking());
         $model_report->print_report();
     } else {
         transport("administrator");
     }
 }
 /**
  * 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);
     }
 }
 /**
  * load game data every play game.
  * role: player
  * @return string
  */
 public function load_data()
 {
     if (Authenticate::is_player()) {
         if (true || isset($_POST['token']) && Authenticate::is_valid_token($_POST['token'])) {
             $this->model_product = Product::getInstance();
             $this->model_material = Material::getInstance();
             $this->model_asset = Asset::getInstance();
             $this->model_supplier = Supplier::getInstance();
             $this->model_employee = Employee::getInstance();
             $this->model_achievement = Achievement::getInstance();
             $this->model_journal = Journal::getInstance();
             $this->model_memorycard = Memorycard::getInstance();
             $this->model_leaderboard = Leaderboard::getInstance();
             /*
              * retrieve data each component.
              * log this event, wrap it up and convert to json format.
              */
             $game = $this->model_memorycard->load_game_data();
             $work_history = $this->model_memorycard->get_work_stress_history();
             $total_work = $this->model_memorycard->get_total_work();
             $candidate = $this->model_employee->get_candidate();
             $employee = $this->model_employee->get_player_employee();
             $material = $this->model_material->get_material_data();
             $player_material = $this->model_material->get_player_material();
             $asset = $this->model_asset->get_asset_data();
             $player_asset = $this->model_asset->get_player_asset();
             $product = $this->model_product->get_product_data();
             $player_product = $this->model_product->get_player_product();
             $product_material = $this->model_product->get_product_material();
             $supplier = $this->model_supplier->get_supplier_data();
             $achievement = $this->model_achievement->get_achievement();
             $account = $this->model_journal->get_account();
             $simulation = $this->model_memorycard->get_simulation();
             $star = $this->model_leaderboard->get_player_ranking();
             $binding = array("result_var" => "session_ready", "game_var" => json_encode($game, JSON_PRETTY_PRINT), "candidate_var" => json_encode($candidate, JSON_PRETTY_PRINT), "employee_var" => json_encode($employee, JSON_PRETTY_PRINT), "product_var" => json_encode($product, JSON_PRETTY_PRINT), "player_product_var" => json_encode($player_product, JSON_PRETTY_PRINT), "product_material_var" => json_encode($product_material, JSON_PRETTY_PRINT), "material_var" => json_encode($material, JSON_PRETTY_PRINT), "player_material_var" => json_encode($player_material, JSON_PRETTY_PRINT), "asset_var" => json_encode($asset, JSON_PRETTY_PRINT), "player_asset_var" => json_encode($player_asset, JSON_PRETTY_PRINT), "supplier_var" => json_encode($supplier, JSON_PRETTY_PRINT), "achievement_var" => json_encode($achievement, JSON_PRETTY_PRINT), "account_var" => json_encode($account, JSON_PRETTY_PRINT), "simulation_var" => json_encode($simulation, JSON_PRETTY_PRINT), "work_history_var" => json_encode($work_history, JSON_PRETTY_PRINT), "work_total_var" => $total_work, "star" => $star["star"]);
             $log = Log::getInstance();
             $log->logging_game_load(json_encode($binding));
             binding_data($binding);
         } else {
             transport("error404");
         }
     } else {
         $binding = array("result_var" => "no_session");
         binding_data($binding);
     }
 }