Unfinished website for an EVE-online corporation
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

evedb.class.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?PHP
  2. require_once(dirname(dirname(__FILE__)) . '/model/ship.php');
  3. class EveDB {
  4. private $pdo;
  5. private $handlers;
  6. public function __construct($connection = null) {
  7. $this->pdo = new PDO($connection == null ? 'sqlite:' . dirname(__FILE__) . '/inc110-sqlite3-v1.db' : $connection);
  8. $this->handlers = array(
  9. 'items' => new ItemsTableHandler($this->pdo),
  10. 'locations' => new LocationsTableHandler($this->pdo),
  11. 'flags' => new FlagsTableHandler($this->pdo),
  12. );
  13. }
  14. public function __get($type) {
  15. return isset($this->handlers[$type]) ? $this->handlers[$type] : null;
  16. }
  17. }
  18. abstract class BaseHandler {
  19. protected $pdo;
  20. public function __construct($pdo) {
  21. $this->pdo = $pdo;
  22. $this->initStatements();
  23. }
  24. protected abstract function initStatements();
  25. }
  26. class ItemsTableHandler extends BaseHandler {
  27. private $getByIdSmt;
  28. protected function initStatements() {
  29. $columns = 'categoryName, typeID, typeName, invTypes.description';
  30. $joins = 'JOIN invGroups ON (invGroups.groupID = invTypes.groupID) JOIN invCategories ON (invGroups.categoryID = invCategories.categoryID)';
  31. $skeleton = 'SELECT ' . $columns . ' FROM invTypes ' . $joins . ' WHERE';
  32. $this->getByIdSmt = $this->pdo->prepare($skeleton . ' typeID = :id');
  33. }
  34. public function getById($id) {
  35. $this->getByIdSmt->execute(array(':id' => $id));
  36. return $this->getByIdSmt->fetch(PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE);
  37. }
  38. }
  39. class FlagsTableHandler extends BaseHandler {
  40. private $getAllSmt;
  41. private $cache = array();
  42. protected function initStatements() {
  43. $this->getAllSmt = $this->pdo->prepare('SELECT flagId AS id, flagName AS name, flagText AS text FROM invFlags');
  44. }
  45. public function getById($id) {
  46. if (empty($this->cache)) {
  47. $this->getAllSmt->execute();
  48. foreach ($this->getAllSmt->fetchAll(PDO::FETCH_CLASS) as $flag) {
  49. $this->cache[(int) $flag->id] = $flag;
  50. }
  51. }
  52. return $this->cache[(int) $id];
  53. }
  54. }
  55. class LocationsTableHandler extends BaseHandler {
  56. private $getByIdSmt;
  57. protected function initStatements() {
  58. $this->getByIdSmt = $this->pdo->prepare('SELECT categoryName, itemName FROM mapDenormalize JOIN invTypes ON (mapDenormalize.typeID = invTypes.typeID) JOIN invGroups ON (invGroups.groupID = invTypes.groupID) JOIN invCategories ON (invGroups.categoryID = invCategories.categoryID) WHERE itemID = :id');
  59. }
  60. public function getById($id) {
  61. // 66014940 <= locationID <= 66014952 then staStations.stationID = locationID - 6000000
  62. // 66000000 <= locationID <= 66999999 then staStations.stationID = locationID - 6000001
  63. // 67000000 <= locationID <= 67999999 then ConqStations.stationID = locationID - 6000000
  64. // 60014861 <= locationID <= 60014928 then ConqStations.stationID = locationID
  65. // 60000000 <= locationID <= 61000000 then staStations.stationID = locationID
  66. // 61000000 <= locationID then ConqStations.stationID = locationID
  67. // default mapDenormalize.itemID = locationID
  68. $id = (double) $id;
  69. if (66014940 <= $id && $id <= 66014952 || 67000000 <= $id && $id <= 67999999) {
  70. $id -= 6000000;
  71. } else if (66000000 <= $id && $id <= 66999999) {
  72. $id -= 6000001;
  73. }
  74. $this->getByIdSmt->execute(array(':id' => $id));
  75. return $this->getByIdSmt->fetch(PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE);
  76. }
  77. }
  78. ?>