Пример #1
0
 /**
  * @param Recipe_Database_Select $select
  * @param array $fields
  * @return Recipe_Model_Resource_Abstract
  */
 public function addL10nOverlay(Recipe_Database_Select $select, array $fields)
 {
     $relTableName = current($this->getMainTable()) . "_l10n";
     $primaryKey = $this->getPrimaryKey();
     $tableAlias = key($this->getMainTable());
     $on = "l10n.{$primaryKey} = {$tableAlias}.{$primaryKey} AND l10n.language_id = ?";
     $on = $this->getDb()->quoteInto($on, Core::getLang()->getOpt("languageid"));
     $select->join(array("l10n" => $relTableName), $on);
     $attributes = array();
     foreach ($fields as $field) {
         $expr = "IFNULL(l10n.{$field}, {$tableAlias}.{$field})";
         $attributes[$field] = new Recipe_Database_Expr($expr);
     }
     $select->attributes(array("{$tableAlias}.*", "l10n" => $attributes));
     return $this;
 }
Пример #2
0
 /**
  * Select the ships for jump.
  *
  * @param array $ships
  *
  * @return Bengine_Game_Controller_Mission
  */
 protected function starGateJump($ships)
 {
     $this->noAction = true;
     $data = array();
     Core::getQuery()->delete("temp_fleet", "planetid = ?", null, null, array(Core::getUser()->get("curplanet")));
     $select = array("u2s.unitid", "u2s.quantity", "d.capicity", "d.speed", "d.consume", "b.name");
     $joins = "LEFT JOIN " . PREFIX . "construction b ON (b.buildingid = u2s.unitid)";
     $joins .= "LEFT JOIN " . PREFIX . "ship_datasheet d ON (d.unitid = u2s.unitid)";
     $result = Core::getQuery()->select("unit2shipyard u2s", $select, $joins, Core::getDB()->quoteInto("b.mode = '3' AND u2s.planetid = ?", Core::getUser()->get("curplanet")));
     foreach ($result->fetchAll() as $row) {
         $id = $row["unitid"];
         if (isset($ships[$id])) {
             $quantity = _pos($ships[$id]);
             if ($quantity > $row["quantity"]) {
                 $quantity = $row["quantity"];
             }
             if ($quantity > 0) {
                 $data["ships"][$id]["quantity"] = $quantity;
                 $data["ships"][$id]["name"] = $row["name"];
             }
         }
     }
     $result->closeCursor();
     $result = Core::getQuery()->select("stargate_jump", "time", "", Core::getDB()->quoteInto("planetid = ?", Core::getUser()->get("curplanet")), "time DESC");
     $row = $result->fetchRow();
     $result->closeCursor();
     $requiredReloadTime = (int) Core::getConfig()->get("STAR_GATE_RELOAD_TIME") * 60;
     $reloadTime = $row["time"] + $requiredReloadTime;
     if (count($data) > 0 && $reloadTime < TIME) {
         $moons = array();
         $select = new Recipe_Database_Select();
         $select->from(array("p" => "planet"))->attributes(array("p" => array("planetid", "planetname"), "g" => array("galaxy", "system", "position"), "sj" => array("time")));
         $select->join(array("b2p" => "building2planet"), array("b2p" => "planetid", "p" => "planetid"))->join(array("g" => "galaxy"), array("g" => "moonid", "p" => "planetid"))->join(array("sj" => "stargate_jump"), array("sj" => "planetid", "p" => "planetid"))->where(array("p" => "userid"), Core::getUser()->get("userid"))->where(array("p" => "ismoon"), 1)->where(array("p" => "planetid", "!="), Core::getUser()->get("curplanet"))->where(array("b2p" => "buildingid"), 56)->where("IFNULL(sj.time, 0) + ? < UNIX_TIMESTAMP()", $requiredReloadTime)->group(array("p" => "planetid"))->order(array("g" => "galaxy"))->order(array("g" => "system"))->order(array("g" => "position"));
         $result = $select->getStatement();
         foreach ($result->fetchAll() as $row) {
             $moons[] = $row;
             $data["moons"][] = $row["planetid"];
         }
         $result->closeCursor();
         Hook::event("ShowStarGates", array(&$moons, &$data));
         Core::getTPL()->addLoop("moons", $moons);
         $data = serialize($data);
         Core::getQuery()->insert("temp_fleet", array("planetid" => Core::getUser()->get("curplanet"), "data" => $data));
         $this->setTemplate("mission/stargatejump");
     } else {
         if ($reloadTime < TIME) {
             $reloadTime = TIME;
         }
         Core::getLanguage()->assign("reloadTime", fNumber(($reloadTime - TIME) / 60), 2);
         Logger::addMessage("RELOADING_STAR_GATE");
     }
     return $this;
 }
Пример #3
0
 /**
  * Loads all total units.
  *
  * @param integer $mode
  * @return Bengine_Game_Controller_Statistics
  */
 protected function loadTotalUnits($mode)
 {
     $select = new Recipe_Database_Select();
     $select->from(array("c" => "construction"));
     $select->attributes(array("c" => array("name"), "s" => array("total" => new Recipe_Database_Expr("SUM(s.quantity)"))));
     $select->join(array("s" => "unit2shipyard"), array("s" => "unitid", "c" => "buildingid"))->group(array("c" => "buildingid"))->where(array("c" => "mode"), $mode)->order(array("c" => "display_order"), "ASC")->order(array("c" => "buildingid"), "ASC");
     $result = $select->getStatement();
     foreach ($result->fetchAll() as $row) {
         $this->unitCount[$mode][$row["name"]] = $row["total"];
     }
     $result->closeCursor();
     return $this;
 }