/**
  * @TODO Document me!
  */
 private function configure()
 {
     $char = Player::find(SessionFactory::getSession()->get('player_id'));
     $peers = $char ? $this->getNearbyPeers($char->id()) : [];
     $active_ninjas = Player::findActive(5, true);
     $char_info = $char ? $char->data() : [];
     $other_npcs = NpcFactory::npcsData();
     $npcs = NpcFactory::customNpcs();
     $enemy_list = $char ? $this->getCurrentEnemies($char->id()) : [];
     $recent_attackers = $char ? $this->getRecentAttackers($char) : [];
     return ['logged_in' => (bool) $char, 'enemy_list' => $enemy_list, 'char_name' => $char ? $char->name() : '', 'npcs' => $npcs, 'other_npcs' => $other_npcs, 'char_info' => $char_info, 'active_ninjas' => $active_ninjas, 'recent_attackers' => $recent_attackers, 'enemy_list' => $enemy_list, 'peers' => $peers];
 }
Example #2
0
 /**
  * Get the ninja list and display it
  *
  * @param Container
  * @return Response
  */
 public function index(Container $p_dependencies)
 {
     $request = RequestWrapper::$request;
     $session = $p_dependencies['session'];
     $searched = $request->get('searched', null);
     // Don't filter the search setting
     $list_by_rank = $searched && substr_compare($searched, '#', 0, 1) === 0;
     // Whether the search is by rank
     $hide_setting = !$searched && $session->has('hide_dead') ? $session->get('hide_dead') : 'dead';
     // Defaults to hiding dead via session
     $hide = $searched ? 'none' : $request->get('hide', $hide_setting);
     // search override > get setting > session setting
     $alive_only = $hide == 'dead';
     $page = $request->get('page');
     $record_limit = 20;
     // The number of players that gets shown per page
     if (!$searched && $hide_setting != $hide) {
         // Save the toggled state for later
         $session->set('hide_dead', $hide);
     }
     $where_clauses = [];
     // Array to add where clauses to
     $params = [];
     if ($searched) {
         if (strlen($searched) == 1 || !$list_by_rank) {
             $where_clauses[] = " (rankings.uname ilike :searched || '%') ";
             $params[':searched'] = $searched;
         }
         if ($hide == 'dead') {
             $where_clauses[] = " alive = true";
         }
     } else {
         if ($hide == 'dead') {
             $where_clauses[] = " alive";
         }
     }
     $query_count = "SELECT count(player_id) FROM rankings " . (count($where_clauses) ? "WHERE " . implode($where_clauses, ' AND ') : "");
     $totalrows = query_item($query_count, $params);
     // The rankings view automatically filters out inactives, but we have to do it manually when dealing directly with players table.
     $where_clauses[] = " active = 1";
     // ************************ Pagination **************************
     // Determine the current page spot navigated to.
     // If searching, use the page between
     // If no specific rank was requested, use the viewer's rank
     // If a certain rank was requested, use that rank spot.
     // Determine the page, if the dead count is more than the rank spot, default to 1, otherwise use the input page.
     // Determine the number of pages and the limit and offset
     if ($searched && $list_by_rank) {
         $page = ceil(substr($searched, 1) / $record_limit);
     } else {
         if ($page == "searched") {
             $page = $request->get('page', 1);
         } else {
             $page = $page < 1 ? 1 : $page;
             // Prevent the page number from going negative
         }
     }
     $numofpages = ceil($totalrows / $record_limit);
     $offset = (int) max(0, $page * $record_limit - $record_limit);
     $last_page = $totalrows - $record_limit * $page > 0;
     $ninja_rows = $this->getFormattedNinjaRows($where_clauses, $params, $record_limit, $offset);
     $ninja_count = count($ninja_rows);
     $active_ninjas = null;
     if (!$searched) {
         // Will not display active ninja on a search page.
         $active_ninjas = Player::findActive(5, $alive_only);
         // get  the currently active ninjas
     }
     $dead_count = query_item("SELECT count(player_id) FROM rankings WHERE alive = false");
     $parts = ['searched' => $searched, 'ninja_count' => $ninja_count, 'dead_count' => $dead_count, 'active_ninjas' => $active_ninjas, 'hide' => $hide, 'page' => $page, 'numofpages' => $numofpages, 'last_page' => $last_page, 'ninja_rows' => $ninja_rows];
     $options = ['quickstat' => 'player'];
     $title = 'Ninja List';
     $template = 'list.tpl';
     return new StreamedViewResponse($title, $template, $parts, $options);
 }
Example #3
0
 public function testFindActive()
 {
     $result = Player::findActive(5, false);
     $active = true;
     $count = 0;
     foreach ($result as $record) {
         $active = $active && Player::find($record['player_id'])->active;
         $count++;
     }
     $this->assertTrue($active);
     $this->assertLessThan(6, $count);
 }