Esempio n. 1
0
 /**
  * Loads all Station names from DB to PHP
  *
  * @return void
  */
 protected static function loadNames()
 {
     //lookup SDE class
     $sdeClass = Config::getIveeClassName('SDE');
     $res = $sdeClass::instance()->query("SELECT stationID, stationName \n            FROM staStations;");
     $namesToIds = array();
     while ($row = $res->fetch_assoc()) {
         $namesToIds[$row['stationName']] = (int) $row['stationID'];
     }
     static::$instancePool->setNamesToIds($namesToIds);
 }
Esempio n. 2
0
 /**
  * Loads all SolarSystem names from DB to PHP.
  *
  * @return void
  */
 protected static function loadNames()
 {
     //lookup SDE class
     $sdeClass = Config::getIveeClassName('SDE');
     $res = $sdeClass::instance()->query("SELECT solarSystemID, solarSystemName\n            FROM mapSolarSystems;");
     $namesToIds = [];
     while ($row = $res->fetch_assoc()) {
         $namesToIds[$row['solarSystemName']] = (int) $row['solarSystemID'];
     }
     static::$instancePool->setNamesToKeys(static::getClassHierarchyKeyPrefix() . 'Names', $namesToIds);
 }
Esempio n. 3
0
 /**
  * Returns a name for a specific station service.
  *
  * @param int $serviceId to get the name for
  *
  * @return string
  */
 public static function getServiceName($serviceId)
 {
     if (!isset(static::$services)) {
         $key = static::getClassHierarchyKeyPrefix() . 'services';
         try {
             $serv = static::$instancePool->getItem($key);
             if ($serv instanceof CacheableArray) {
                 static::$services = $serv->data;
             } else {
                 static::throwException('IveeCoreException');
             }
         } catch (Exceptions\KeyNotFoundInCacheException $e) {
             static::$services = [];
             $sdeClass = Config::getIveeClassName('SDE');
             $sde = $sdeClass::instance();
             $res = $sde->query('SELECT * FROM staServices;');
             if ($res->num_rows > 0) {
                 while ($row = $res->fetch_assoc()) {
                     static::$services[(int) $row['serviceID']] = $row['serviceName'];
                 }
             }
             $cacheableArrayClass = Config::getIveeClassName('CacheableArray');
             $cacheArray = new $cacheableArrayClass($key, time() + 24 * 3600);
             $cacheArray->data = static::$services;
             static::$instancePool->setItem($cacheArray);
         }
     }
     return static::$services[$serviceId];
 }
 /**
  * Retuns a GlobalPriceData object. Tries caches and instantiates new objects if necessary.
  *
  * @param int $typeId of requested market data typeId
  * @param int $maxPriceDataAge maximum global price data age.
  *
  * @return \iveeCore\GlobalPriceData
  * @throws \iveeCore\Exceptions\NoPriceDataAvailableException if there is no price data available for the typeId
  */
 public static function getById($typeId, $maxPriceDataAge = null)
 {
     if (is_null($maxPriceDataAge)) {
         $maxPriceDataAge = Config::getMaxPriceDataAge();
     }
     if (!isset(static::$instancePool)) {
         static::init();
     }
     try {
         return static::$instancePool->getItem(static::getClassHierarchyKeyPrefix() . (int) $typeId);
     } catch (KeyNotFoundInCacheException $e) {
         //go to DB
         $typeClass = Config::getIveeClassName(static::getClassNick());
         $type = new $typeClass((int) $typeId, $maxPriceDataAge);
         //store object in instance pool
         static::$instancePool->setItem($type);
         return $type;
     }
 }
Esempio n. 5
0
 /**
  * Loads all type names from DB to PHP
  *
  * @return void
  */
 protected static function loadNames()
 {
     //lookup SDE class
     $sdeClass = Config::getIveeClassName('SDE');
     $res = $sdeClass::instance()->query("SELECT typeID, typeName\n            FROM invTypes\n            WHERE published = 1;");
     $namesToIds = array();
     while ($row = $res->fetch_assoc()) {
         $namesToIds[$row['typeName']] = (int) $row['typeID'];
     }
     self::$instancePool->setNamesToIds($namesToIds);
 }
Esempio n. 6
0
 /**
  * Loads all type names from DB to PHP.
  *
  * @return void
  */
 protected static function loadNames()
 {
     //lookup SDE class
     $sdeClass = Config::getIveeClassName('SDE');
     $res = $sdeClass::instance()->query("SELECT typeID, typeName\n            FROM invTypes\n            WHERE marketGroupID IS NOT NULL OR published = 1;");
     $namesToIds = [];
     while ($row = $res->fetch_assoc()) {
         $namesToIds[$row['typeName']] = (int) $row['typeID'];
     }
     self::$instancePool->setNamesToKeys(static::getClassHierarchyKeyPrefix() . 'Names', $namesToIds);
 }
Esempio n. 7
0
 /**
  * Main function for getting MarketHistory objects. Tries caches, DB and goes to CREST if necessary.
  *
  * @param int $typeId of type
  * @param int $regionId of the region. If none passed, default is looked up.
  * @param int $maxPriceDataAge for the maximum acceptable market data age. null for unlimited.
  * @param bool $cache whether this object should be cached. Note that it can be quite large, so chose carefully.
  *
  * @return \iveeCore\MarketHistory
  * @throws \iveeCore\Exceptions\NotOnMarketException if requested type is not on market
  * @throws \iveeCore\Exceptions\NoPriceDataAvailableException if no region market data is found
  */
 public static function getByIdAndRegion($typeId, $regionId = null, $maxPriceDataAge = null, $cache = true)
 {
     //setup instance pool if needed
     if (!isset(static::$instancePool)) {
         static::init();
     }
     //get default market regionId if none passed
     if (is_null($regionId)) {
         $regionId = Config::getDefaultMarketRegionId();
     }
     //try instance pool and cache
     try {
         $mh = static::$instancePool->getItem(static::getClassHierarchyKeyPrefix() . (int) $regionId . '_' . (int) $typeId);
         if (!$mh->isTooOld($maxPriceDataAge)) {
             return $mh;
         }
     } catch (KeyNotFoundInCacheException $e) {
         //empty as we are using Exceptions for flow control here
     }
     $mhClass = Config::getIveeClassName(static::getClassNick());
     //try DB
     try {
         $mh = new $mhClass($typeId, $regionId);
         //use it only if its not too old or unlimited
         if (!$mh->isTooOld($maxPriceDataAge)) {
             static::$instancePool->setItem($mh);
             return $mh;
         }
     } catch (NoPriceDataAvailableException $e) {
         //empty as we are using Exceptions for flow control here
     }
     if (is_null(static::$crestMarketProcessor)) {
         $crestMarketProcessorClass = Config::getIveeClassName('CrestMarketProcessor');
         static::$crestMarketProcessor = new $crestMarketProcessorClass();
     }
     //fetch data from CREST and update DB
     //we don't cache the CREST call because we already cache this object
     static::$crestMarketProcessor->getNewestHistoryData($typeId, $regionId, false);
     //instantiate new MarketHistory fetching data from DB
     $mh = new $mhClass($typeId, $regionId);
     //store object in instance pool and cache
     if ($cache) {
         static::$instancePool->setItem($mh);
     }
     return $mh;
 }