public function index($request)
 {
     $currentPage = 1;
     if (!empty($request['page'])) {
         $currentPage = (int) preg_replace('/[^0-9]+/', '', $request['page']);
         if ($currentPage < 1) {
             $this->sendErrorAndQuit('Page must be a positive value larger than one');
         }
     }
     $killsPerPage = 20;
     $skip = ($currentPage - 1) * $killsPerPage;
     $count = Kingboard_Kill::count();
     $lastPage = ceil($count / $killsPerPage);
     if ($currentPage > $lastPage) {
         $this->sendErrorAndQuit('Page does not exist');
     }
     $data = Kingboard_Kill::find()->sort(array('killTime' => -1))->skip($skip)->limit($killsPerPage);
     $templateVars = array('data' => $data, 'next' => $skip + $killsPerPage < $count ? $currentPage + 1 : false, 'prev' => $currentPage > 1 ? $currentPage - 1 : false, 'currentPage' => $currentPage, 'lastPage' => $lastPage, 'action' => '/home');
     if (!empty($request['ajax'])) {
         return $this->render('home_killspage.html', $templateVars);
     }
     $stats = Kingboard_Kill_MapReduce_KillsByShip::find();
     $info = array();
     $template = "index.html";
     $stats = $stats->sort(array("value.value" => -1));
     $templateVars['count'] = $count;
     $templateVars['stats'] = $stats;
     $templateVars['info'] = $info;
     $templateVars['reports'] = Kingboard_BattleSettings::find()->limit(20)->sort(array('enddate' => -1));
     return $this->render($template, $templateVars);
 }
 /**
  * @param array $options
  * @return void
  */
 public function update_stats(array $options)
 {
     $this->cli->header('updating stats');
     $this->cli->message('updating Kills by Shiptype');
     // stats table of how often all ships have been killed
     Kingboard_Kill_MapReduce_KillsByShip::mapReduce();
     $this->cli->positive('update of stats done.');
 }