public function testSave() { $loc = new Location(); $loc->setBuildingID(1); $loc->setRoom(9999); $loc->save(); $this->assertTrue($loc->getID() != NULL); $fetched = new Location(); $fetched->fetch($loc->getID()); $this->assertEquals($fetched->getID(), $loc->getID()); $this->assertEquals($fetched->getBuildingID(), $loc->getBuildingID()); $this->assertEquals($fetched->getRoom(), $loc->getRoom()); //delete from DB for cleanup //TODO -- replace with proper delete method $sql = "DELETE FROM `locations` WHERE id=?"; $sql = $this->db->prepareQuery($sql, $loc->getID()); $this->db->query($sql); }
<?php require 'models/config.php'; $loc = new Location(); $loc->setBuildingID(10); $loc->save(); echo $loc->getID();
/** * Really add the kill. * @param integer $id If set, use the given id to post this kill. * @return integer */ protected function realadd($id = null) { if ($this->timestamp == "" || !$this->getVictim()->getID() || !$this->victimship->getName() || !$this->solarsystem->getID() || !$this->victimallianceid || !$this->victimcorpid || !$this->getFBPilotID() || !$this->getHash(false, false)) { return 0; } // TODO: Redo accounting for ammo (see kill_detail). // // Check slot counts. // $locations = array(); // foreach ($this->droppeditems_ as $dest) { // $locations[$dest->getLocationID()] += $dest->getQuantity(); // } // foreach ($this->destroyeditems_ as $dest) { // $locations[$dest->getLocationID()] += $dest->getQuantity(); // } // $dogma = Cacheable::factory('dogma', $this->victimship->getID()); // $lowcount = (int)$dogma->attrib['lowSlots']['value']; // $medcount = (int)$dogma->attrib['medSlots']['value']; // $hicount = (int)$dogma->attrib['hiSlots']['value']; // // Is there anything flyable that has no rig slots? // $rigcount = (int)($dogma->attrib['rigSlots']['value'] ? // $dogma->attrib['rigSlots']['value'] : 3); // $subcount = 5; // if ($lowcount // && ($locations[1] > $hicount // || $locations[2] > $medcount // || $locations[3] > $lowcount // || $locations[5] > $rigcount) // ) { // return 0; // } else if ((!$lowcount && $locations[7]) // && ($locations[7] > $subcount // || $locations[5] > $rigcount) // ) { // return 0; // } if ($id == null) { $qid = 'null'; } else { $qid = $id; } if (!$this->dmgtaken) { $this->dmgtaken = 0; } if (is_null($this->xCoordinate)) { $this->xCoordinate = 0; } if (is_null($this->yCoordinate)) { $this->yCoordinate = 0; } if (is_null($this->zCoordinate)) { $this->zCoordinate = 0; } $mysqlTimestamp = toMysqlDateTime($this->timestamp); $qry = DBFactory::getDBQuery(); $sql = "INSERT INTO kb3_kills\n (kll_id , kll_timestamp , kll_victim_id , kll_all_id , kll_crp_id , kll_ship_id , kll_system_id , kll_fb_plt_id , kll_points , kll_dmgtaken, kll_external_id, kll_isk_loss, kll_x, kll_y, kll_z, kll_location)\n VALUES (" . $qid . ",\n '" . $mysqlTimestamp . "',\n " . $this->victimid . ",\n " . $this->victimallianceid . ",\n " . $this->victimcorpid . ",\n " . $this->victimship->getID() . ",\n " . $this->solarsystem->getID() . ",\n " . $this->getFBPilotID() . ",\n " . $this->calculateKillPoints() . ",\n " . $this->dmgtaken . ", "; if ($this->externalid) { $sql .= $this->externalid . ", "; } else { $sql .= "NULL, "; } $sql .= $this->getISKLoss() . ",\n " . $this->xCoordinate . ",\n " . $this->yCoordinate . ",\n " . $this->zCoordinate . ","; if (!is_null($this->getNearestCelestial())) { $sql .= $this->nearestCelestial->getID(); } else { $sql .= "NULL"; } $sql .= " )"; $qry->autocommit(false); if (!$qry->execute($sql)) { return $this->rollback($qry); } if ($id) { $this->id = $id; } else { $this->id = $qry->getInsertID(); } if (!$this->id) { return $this->rollback($qry); } // involved $order = 0; $invall = array(); $invcrp = array(); $involveddsql = 'insert into kb3_inv_detail (ind_kll_id, ind_timestamp, ind_plt_id, ind_sec_status, ind_all_id, ind_crp_id, ind_shp_id, ind_wep_id, ind_order, ind_dmgdone ) values '; $involvedasql = 'insert into kb3_inv_all (ina_kll_id, ina_all_id, ina_timestamp) values '; $involvedcsql = 'insert into kb3_inv_crp (inc_kll_id, inc_crp_id, inc_timestamp) values '; $notfirstd = false; $notfirsta = false; $notfirstc = false; // Make sure involved parties are ordered by damage done. usort($this->involvedparties_, array('Kill', 'involvedComparator')); foreach ($this->involvedparties_ as $inv) { $ship = $inv->getShip(); $weapon = $inv->getWeapon(); if (!$inv->getPilotID() || !$inv->getAllianceID() || !$inv->getCorpID() || !$ship->getName() || !$weapon->getID()) { return $this->rollback(); } if ($notfirstd) { $involveddsql .= ", "; } $involveddsql .= "( " . $this->getID() . ", '" . $mysqlTimestamp . "', " . $inv->getPilotID() . ", '" . $inv->getSecStatus() . "', " . $inv->getAllianceID() . ", " . $inv->getCorpID() . ", " . $ship->getID() . ", " . $weapon->getID() . ", " . $order++ . ", " . $inv->getDamageDone() . ")"; $notfirstd = true; if (!in_array($inv->getAllianceID(), $invall)) { if ($notfirsta) { $involvedasql .= ", "; } $involvedasql .= "( " . $this->getID() . ", " . $inv->getAllianceID() . ", '" . $mysqlTimestamp . "')"; $notfirsta = true; $invall[] = $inv->getAllianceID(); } if (!in_array($inv->getCorpID(), $invcrp)) { if ($notfirstc) { $involvedcsql .= ", "; } $involvedcsql .= "( " . $this->getID() . ", " . $inv->getCorpID() . ", '" . $mysqlTimestamp . "')"; $notfirstc = true; $invcrp[] = $inv->getCorpID(); } } if ($notfirstd && !$qry->execute($involveddsql)) { return $this->rollback($qry); } if ($notfirsta && !$qry->execute($involvedasql)) { return $this->rollback($qry); } if ($notfirstc && !$qry->execute($involvedcsql)) { return $this->rollback($qry); } // destroyed $notfirstitd = false; $itdsql = "insert into kb3_items_destroyed (itd_kll_id, itd_itm_id, itd_quantity, itd_itl_id, itd_singleton) values "; foreach ($this->destroyeditems_ as $dest) { $item = $dest->getItem(); $loc_id = $dest->getLocationID(); if (!is_numeric($this->getID()) || !is_numeric($item->getID()) || !is_numeric($dest->getQuantity()) || !is_numeric($loc_id) || !is_numeric($dest->getSingleton())) { trigger_error('error with destroyed item.', E_USER_WARNING); var_dump($dest); exit; continue; } if ($notfirstitd) { $itdsql .= ", "; } $itdsql .= "( " . $this->getID() . ", " . $item->getID() . ", " . $dest->getQuantity() . ", " . $loc_id . ", " . $dest->getSingleton() . " )"; $notfirstitd = true; } if ($notfirstitd && !$qry->execute($itdsql)) { return $this->rollback($qry); } // dropped $notfirstitd = false; $itdsql = "insert into kb3_items_dropped (itd_kll_id, itd_itm_id, itd_quantity, itd_itl_id, itd_singleton) values "; foreach ($this->droppeditems_ as $dest) { $item = $dest->getItem(); $loc_id = $dest->getLocationID(); if (!is_numeric($this->getID()) || !is_numeric($item->getID()) || !is_numeric($dest->getQuantity()) || !is_numeric($loc_id) || !is_numeric($dest->getSingleton())) { trigger_error('error with dropped item.', E_USER_WARNING); var_dump($dest); exit; continue; } if ($notfirstitd) { $itdsql .= ", "; } $itdsql .= "( " . $this->getID() . ", " . $item->getID() . ", " . $dest->getQuantity() . ", " . $loc_id . ", " . $dest->getSingleton() . " )"; $notfirstitd = true; } if ($notfirstitd && !$qry->execute($itdsql)) { return $this->rollback($qry); } // try calculate CREST hash if (!$this->crestHash) { $this->crestHash = $this->calculateCrestHash(); } $sql = "INSERT INTO kb3_mails ( `kll_id`, `kll_timestamp`, `kll_external_id`, `kll_hash`, `kll_trust`, `kll_modified_time`, `kll_crest_hash`)" . "VALUES(" . $this->getID() . ", '" . $this->getTimeStamp() . "', "; if ($this->externalid) { $sql .= $this->externalid . ", "; } else { $sql .= "NULL, "; } $sql .= "'" . $qry->escape($this->getHash(false, false)) . "', 0, UTC_TIMESTAMP(), "; // add CREST hash if ($this->crestHash) { $sql .= "'{$this->crestHash}'"; } else { $sql .= "NULL"; } $sql .= ")"; if (!@$qry->execute($sql)) { return $this->rollback($qry); } //Update cache tables. summaryCache::addKill($this); $qry->autocommit(true); // call the event that we added this mail event::call('killmail_added', $this); cache::notifyKillAdded(); return $this->id; }
private function setUpLocation() { $location = new Location(); $buildingID = Location::lookupBuildingID($this->request['buildingName']); if ($buildingID == false) { //building not found return -1; } $location->setBuildingID($buildingID); //handle reports with no room or blank room set if (isset($this->request['room']) && strtolower($this->request['room']) != 'null' && $this->request['room'] != '') { $location->setRoom($this->request['room']); } $location->save(); //creates new location if necessary. sets id return $location->getID(); }
/** * Creates a location and returns the new location as returned from the * API. * * @param Google\MyBusiness\Location $location * @param Google\MyBusiness\Account $account = null * @param boolean $dryRun = false */ public function createLocation(Location $location, Account $account = null, $dryRun = false) { $ownerAccountID = $location->getOwnerAccountID(); if (strlen($ownerAccountID)) { $account = new Account(); $account->setID($ownerAccountID); } elseif ($account) { self::_validateID($account); } else { $account = $this->_getCachedAccount(); } if ($location->getID() !== null) { throw new InvalidArgumentException('A new location may not already contain an ID.'); } /* Even if the creation of new locations is disabled, we'll still allow dry runs. */ if (!GOOGLE_MYBUSINESS_API_ALLOW_NEW_LOCATIONS && !$dryRun) { throw new RuntimeException('Cannot create new locations unless the ' . 'GOOGLE_MYBUSINESS_API_ALLOW_NEW_LOCATIONS setting is ' . 'defined as true.'); } $requestBody = array('location' => $location->toREST(), 'languageCode' => $location->getLanguageCode(), 'validateOnly' => $dryRun, 'requestId' => $location->getHash()); $request = new APIRequest($account->getName() . '/locations'); $request->setPayload(json_encode($requestBody)); $this->_parseCallback = '_parseLocationResponse'; return $this->_makeRequest($request); }