Exemplo n.º 1
0
 /**
  * display a certain battle
  * @param array $parameters
  * @return string
  */
 public function show(array $parameters)
 {
     $battleSetting = BattleSettings::getById($parameters['id']);
     if (is_null($battleSetting)) {
         return $this->error("Battle with Id " . $parameters['id'] . " does not exist");
     }
     $battle = BattleData::getByBattleSettings($battleSetting);
     $this->_context['battleSetting'] = $battleSetting;
     return $this->render("battle/details.html", $battle->data);
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
 public function battle_updates(array $options)
 {
     $log = Registry::getInstance()->getLogger();
     $hours = 168;
     if (isset($options[0]) && $options[0] > 0) {
         $hours = $options[0];
     }
     $log->info("updating battles for the last {$hours} hours");
     $settings = BattleSettings::getActiveSettings($hours);
     foreach ($settings as $battleSetting) {
         $log->info("Generating battle for " . $battleSetting->_id);
         Battle::generateForSettings($battleSetting);
     }
     $log->info("done updating battles");
 }