Example #1
0
 public function killlist($request)
 {
     if (empty($request['ownerType']) || empty($request['ownerID'])) {
         return $this->error("type / id not given");
     }
     $ownerType = $request['ownerType'];
     $ownerID = $request['ownerID'];
     $currentPage = 1;
     if (!empty($request['page'])) {
         $currentPage = (int) $request['page'] < 1 ? 1 : (int) $request['page'];
     }
     $templateVars = array();
     // kill list
     $killList = new KillList($ownerType, $ownerID);
     $templateVars['killstats'] = $killList->getKillStats();
     $templateVars['lossstats'] = $killList->getLossStats();
     $templateVars['totalstats'] = $killList->getTotalStats();
     $paginator = new Paginator($currentPage, $killList->getCount());
     // fetch kill data
     $templateVars['data'] = $killList->getKills($paginator->getSkip(), $paginator->getKillsPerPage());
     // merge in pagination data
     $templateVars = array_merge($templateVars, $paginator->getNavArray());
     $templateVars['count'] = $killList->getCount();
     $info = null;
     $template = null;
     switch ($ownerType) {
         case "character":
         case "char":
         case "pilot":
             $template = "pilot/index.html";
             $info = KillModel::getPilotInfoFromId($ownerID);
             break;
         case "corp":
         case "corporation":
             $template = "corporation/index.html";
             $info = KillModel::getCorporationInfoFromId($ownerID);
             break;
         case "faction":
             $template = "faction/index.html";
             $info = KillModel::getFactionInfoFromId($ownerID);
             break;
         case "alliance":
             $template = "alliance/index.html";
             $info = KillModel::getAllianceInfoFromId($ownerID);
             break;
     }
     if (is_null($template) || is_null($info)) {
         return $this->error("unknown ownerType: " . $ownerType);
     }
     $templateVars['info'] = $info;
     // we replace the defaults with the ones of the current look
     $templateVars['ownerID'] = $ownerID;
     $templateVars['ownerType'] = $ownerType;
     $templateVars['action'] = "/details/{$ownerType}/{$ownerID}";
     return $this->render($template, $templateVars);
 }
Example #2
0
 /**
  * display a list of battles
  * @param array $request
  * @return string
  */
 public function index(array $request)
 {
     $templateVars = array();
     $currentPage = 1;
     if (!empty($request['page'])) {
         $currentPage = (int) $request['page'] < 1 ? 1 : (int) $request['page'];
     }
     $count = BattleSettings::find()->count();
     $paginator = new Paginator($currentPage, $count);
     // merge in pagination data
     $templateVars = array_merge($templateVars, $paginator->getNavArray());
     // battles
     $templateVars['reports'] = BattleSettings::find()->skip($paginator->getSkip())->limit($paginator->getKillsPerPage())->sort(array('enddate' => -1));
     $templateVars['action'] = "/battles";
     return $this->render("battle/index.html", $templateVars);
 }
Example #3
0
 public function index(array $params)
 {
     $context = array();
     if (!isset($params['date'])) {
         $context["date"] = date("Y-m-d");
     } else {
         $context["date"] = $params['date'];
     }
     // get previous day
     $dt = new DateTime($context['date']);
     $context["previousDate"] = date("Y-m-d", $dt->sub(new \DateInterval("P1D"))->getTimestamp());
     $dt = new DateTime($context['date']);
     $ts = $dt->add(new \DateInterval("P1D"))->getTimestamp();
     if ($ts < time()) {
         $context["nextDate"] = date("Y-m-d", $ts);
     } else {
         $context["nextDate"] = date("Y-m-d");
     }
     if (!isset($params['page']) || empty($params['page'])) {
         $page = 1;
     } else {
         $page = (int) $params['page'];
     }
     // reset date
     $dt = new DateTime($context['date']);
     $mdt = new MongoDate($dt->getTimestamp());
     if ($this->_context['ownerID']) {
         $stats = KillsByDayByEntity::findOne($dt->getTimestamp(), $this->_context['ownerID']);
     } else {
         $stats = KillsByDay::findOne($mdt);
     }
     $context['stats'] = $stats['value'];
     $paginator = new Paginator($page, $context['stats']['total']);
     $context['page'] = $paginator->getNavArray();
     // reset date
     $dt = new DateTime($context['date']);
     if ($this->_context['ownerID']) {
         switch ($this->_context['ownerType']) {
             case "alliance":
                 $involvedType = "involvedAlliances";
                 break;
             case "faction":
                 $involvedType = "involvedFactions";
                 break;
             case "corp":
             case "corporation":
                 $involvedType = "involvedCorporations";
                 break;
             case "char":
             case "character":
             case "pilot":
                 $involvedType = "involvedCharacters";
                 break;
             default:
                 throw new \Exception("Configuration has set unknown ownerType!");
                 return;
         }
         $kills = KillModel::find(array('$and' => array(array("killTime" => array('$gt' => new MongoDate($dt->getTimestamp()))), array("killTime" => array('$lt' => new MongoDate($dt->add(new \DateInterval("P1D"))->getTimestamp()))), array($involvedType => $this->_context['ownerID']))))->hint(array("killTime" => 1))->sort(array("killTime" => -1))->skip($paginator->getSkip())->limit(10);
     } else {
         $kills = KillModel::find(array('$and' => array(array("killTime" => array('$gt' => new MongoDate($dt->getTimestamp()))), array("killTime" => array('$lt' => new MongoDate($dt->add(new \DateInterval("P1D"))->getTimestamp()))))))->hint(array("killTime" => 1))->sort(array("killTime" => -1))->skip($paginator->getSkip())->limit(10);
     }
     $context['kills'] = $kills;
     $context['action'] = "/day/" . $context['date'];
     $dt = new DateTime($context['date']);
     $criteria = array('$and' => array(array("startdate" => array('$gt' => new MongoDate($dt->getTimestamp() - 1))), array("startdate" => array('$lt' => new MongoDate($dt->add(new \DateInterval("P1D"))->getTimestamp())))));
     if ($this->_context['ownerID']) {
         $criteria['$or'] = array(array("ownerCharacter" => $this->_context['ownerID']), array("ownerCorporation" => $this->_context['ownerID']), array("ownerAlliance" => $this->_context['ownerID']), array("ownerFaction" => $this->_context['ownerID']));
     }
     $battles = BattleSettings::find($criteria);
     // resolve collection to avoid count() of doom
     $context["battles"] = array();
     foreach ($battles as $battle) {
         $context["battles"][] = $battle->toArray();
     }
     $this->render("date/daily.html", $context);
 }