Esempio n. 1
0
 /**
  * Saves the construction data.
  *
  * @param string $name
  * @param string $nameId
  * @param integer $allowOnMoon
  * @param string $desc
  * @param string $fullDesc
  * @param string $prodWhat
  * @param string $prod
  * @param string $consWhat
  * @param string $consumption
  * @param string $special
  * @param string $basicMetal
  * @param string $basicSilicon
  * @param string $basicHydrogen
  * @param string $basicEnergy
  * @param string $chargeMetal
  * @param string $chargeSilicon
  * @param string $chargeHydrogen
  * @param string $chargeEnergy
  *
  * @return Bengine_Game_Controller_Construction_Edit
  */
 protected function saveConstruction($name, $nameId, $allowOnMoon, $desc, $fullDesc, $prodWhat, $prod, $consWhat, $consumption, $special, $basicMetal, $basicSilicon, $basicHydrogen, $basicEnergy, $chargeMetal, $chargeSilicon, $chargeHydrogen, $chargeEnergy)
 {
     Hook::event("EditUnitSave");
     // Fetch production from form
     $prodMetal = "";
     $prodSilicon = "";
     $prodHydrogen = "";
     $prodEnergy = "";
     if ($prodWhat == "metal") {
         $prodMetal = $prod;
     } else {
         if ($prodWhat == "silicon") {
             $prodSilicon = $prod;
         } else {
             if ($prodWhat == "hydrogen") {
                 $prodHydrogen = $prod;
             } else {
                 if ($prodWhat == "energy") {
                     $prodEnergy = $prod;
                 }
             }
         }
     }
     // Fetch consumption from form
     $consMetal = "";
     $consSilicon = "";
     $consHydrogen = "";
     $consEnergy = "";
     if ($consWhat == "metal") {
         $consMetal = $consumption;
     } else {
         if ($consWhat == "silicon") {
             $consSilicon = $consumption;
         } else {
             if ($consWhat == "hydrogen") {
                 $consHydrogen = $consumption;
             } else {
                 if ($consWhat == "energy") {
                     $consEnergy = $consumption;
                 }
             }
         }
     }
     // Now generate the sql query.
     $spec = array("special" => $special, "allow_on_moon" => (int) $allowOnMoon, "basic_metal" => $basicMetal, "basic_silicon" => $basicSilicon, "basic_hydrogen" => $basicHydrogen, "basic_energy" => $basicEnergy, "prod_metal" => $prodMetal, "prod_silicon" => $prodSilicon, "prod_hydrogen" => $prodHydrogen, "prod_energy" => $prodEnergy, "cons_metal" => $consMetal, "cons_silicon" => $consSilicon, "cons_hydrogen" => $consHydrogen, "cons_energy" => $consEnergy, "charge_metal" => $chargeMetal, "charge_silicon" => $chargeSilicon, "charge_hydrogen" => $chargeHydrogen, "charge_energy" => $chargeEnergy);
     Core::getQuery()->update("construction", $spec, "name = ?", array($nameId));
     // Save the name and description
     $languageId = Core::getLang()->getOpt("languageid");
     if (Str::length($name) > 0) {
         $result = Core::getQuery()->select("phrases", "phraseid", "", Core::getDB()->quoteInto("title = ?", $nameId));
         if ($result->rowCount() > 0) {
             Core::getQuery()->update("phrases", array("content" => convertSpecialChars($name)), "title = ?", array($nameId));
         } else {
             Core::getQuery()->insert("phrases", array("languageid" => $languageId, "phrasegroupid" => 4, "title" => $nameId, "content" => convertSpecialChars($name)));
         }
         $result->closeCursor();
     }
     if (Str::length($desc) > 0) {
         $result = Core::getQuery()->select("phrases", "phraseid", "", Core::getDB()->quoteInto("title = ?", $nameId . "_DESC"));
         if ($result->rowCount() > 0) {
             Core::getQuery()->update("phrases", array("content" => convertSpecialChars($desc)), "title = ?", array($nameId . "_DESC"));
         } else {
             Core::getQuery()->insert("phrases", array("languageid" => $languageId, "phrasegroupid" => 4, "title" => $nameId . "_DESC", "content" => convertSpecialChars($desc)));
         }
         $result->closeCursor();
     }
     if (Str::length($fullDesc) > 0) {
         $result = Core::getQuery()->select("phrases", "phraseid", "", Core::getDB()->quoteInto("title = ?", $nameId . "_FULL_DESC"));
         if ($result->rowCount() > 0) {
             Core::getQuery()->update("phrases", array("content" => convertSpecialChars($fullDesc)), "title = ?", array($nameId . "_FULL_DESC"));
         } else {
             Core::getQuery()->insert("phrases", array("languageid" => $languageId, "phrasegroupid" => 4, "title" => $nameId . "_FULL_DESC", "content" => convertSpecialChars($fullDesc)));
         }
         $result->closeCursor();
     }
     // Rebuild language cache
     Core::getLang()->rebuild("info");
     return $this;
 }
Esempio n. 2
0
 /**
  * Saves the entered data.
  *
  * @param integer $unitid
  * @param string $nameId
  * @param string $name
  * @param integer $allowOnMoon
  * @param string $desc
  * @param string $fullDesc
  * @param integer $basicMetal
  * @param integer $basicSilicon
  * @param integer $basicHydrogen
  * @param integer $basicEnergy
  * @param integer $capacity
  * @param integer $speed
  * @param integer $consumption
  * @param integer $attack
  * @param integer $shield
  * @param integer $baseEngine
  * @param integer $extentedEngine
  * @param integer $extentedEngineLevel
  * @param integer $extentedEngineSpeed
  * @param integer $rfDelete
  * @param integer $rfNew
  * @param integer $rfNewValue
  *
  * @return Bengine_Game_Controller_Unit
  */
 protected function saveConstruction($unitid, $nameId, $name, $allowOnMoon, $desc, $fullDesc, $basicMetal, $basicSilicon, $basicHydrogen, $basicEnergy, $capacity, $speed, $consumption, $attack, $shield, $baseEngine, $extentedEngine, $extentedEngineLevel, $extentedEngineSpeed, $rfDelete, $rfNew, $rfNewValue)
 {
     Hook::event("EditUnitSave");
     $languageid = Core::getLang()->getOpt("languageid");
     $spec = array("allow_on_moon" => $allowOnMoon, "basic_metal" => $basicMetal, "basic_silicon" => $basicSilicon, "basic_hydrogen" => $basicHydrogen, "basic_energy" => $basicEnergy);
     Core::getQuery()->update("construction", $spec, "name = ?", array($nameId));
     $spec = array("capicity" => $capacity, "speed" => $speed, "consume" => $consumption, "attack" => $attack, "shield" => $shield);
     Core::getQuery()->update("ship_datasheet", $spec, "unitid = ?", array($unitid));
     Core::getQuery()->update("ship2engine", array("engineid" => $baseEngine), "unitid = ? AND base = ?", array($unitid, 1));
     Core::getQuery()->delete("ship2engine", "unitid = ? AND base = ?", null, null, array($unitid, 0));
     if ($extentedEngineLevel > 0) {
         Core::getQuery()->insert("ship2engine", array("engineid" => $extentedEngine, "unitid" => $unitid, "level" => $extentedEngineLevel, "base_speed" => $extentedEngineSpeed, "base" => 0));
     }
     if (Str::length($name) > 0) {
         $result = Core::getQuery()->select("phrases", "phraseid", "", Core::getDB()->quoteInto("title = ?", $nameId));
         if ($result->rowCount() > 0) {
             Core::getQuery()->update("phrases", array("content" => convertSpecialChars($name)), "title = ?", array($nameId));
         } else {
             Core::getQuery()->insert("phrases", array("languageid" => $languageid, "phrasegroupid" => 4, "title" => $nameId, "content" => convertSpecialChars($name)));
         }
         $result->closeCursor();
     }
     if (Str::length($desc) > 0) {
         $result = Core::getQuery()->select("phrases", "phraseid", "", Core::getDB()->quoteInto("title = ?", $nameId . "_DESC"));
         if ($result->rowCount() > 0) {
             Core::getQuery()->update("phrases", array("content" => convertSpecialChars($desc)), "title = ?", array($nameId . "_DESC"));
         } else {
             Core::getQuery()->insert("phrases", array("languageid" => $languageid, "phrasegroupid" => 4, "title" => $nameId . "_DESC", "content" => convertSpecialChars($desc)));
         }
         $result->closeCursor();
     }
     if (Str::length($fullDesc) > 0) {
         $result = Core::getQuery()->select("phrases", "phraseid", "", Core::getDB()->quoteInto("title = ?", $nameId . "_FULL_DESC"));
         if ($result->rowCount() > 0) {
             Core::getQuery()->update("phrases", array("content" => convertSpecialChars($fullDesc)), "title = ?", array($nameId . "_FULL_DESC"));
         } else {
             Core::getQuery()->insert("phrases", array("languageid" => $languageid, "phrasegroupid" => 4, "title" => $nameId . "_FULL_DESC", "content" => convertSpecialChars($fullDesc)));
         }
         $result->closeCursor();
     }
     Core::getLang()->rebuild("info");
     // Rapidfire
     $result = Core::getQuery()->select("rapidfire", array("target", "value"), "", Core::getDB()->quoteInto("unitid = ?", $this->id));
     foreach ($result->fetchAll() as $row) {
         if (is_array($rfDelete) && in_array($row["target"], $rfDelete)) {
             Core::getQuery()->delete("rapidfire", "unitid = ? AND target = ?", null, null, array($this->id, $row["target"]));
         } else {
             if (Core::getRequest()->getPOST("rf_" . $row["target"]) != $row["value"]) {
                 Core::getQuery()->update("rapidfire", array("value" => Core::getRequest()->getPOST("rf_" . $row["target"])), "unitid = ? AND target = ?", array($this->id, $row["target"]));
             }
         }
     }
     if ($rfNew > 0 && $rfNewValue > 0) {
         Core::getQuery()->delete("rapidfire", "unitid = ? AND target = ?", null, null, array($this->id, $rfNew));
         Core::getQuery()->insert("rapidfire", array("unitid" => $this->id, "target" => $rfNew, "value" => $rfNewValue));
     }
     return $this;
 }