Changeset 1411293
- Timestamp:
- 05/05/2016 09:11:20 PM (10 years ago)
- Location:
- eve-shipinfo/trunk
- Files:
-
- 6 edited
-
classes/EVEShipInfo.php (modified) (4 diffs)
-
classes/EVEShipInfo/Collection/Ship/Attribute.php (modified) (7 diffs)
-
classes/EVEShipInfo/Plugin.php (modified) (2 diffs)
-
classes/EVEShipInfo/Shortcode.php (modified) (1 diff)
-
data/data.zip (modified) (previous)
-
errorcodes.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
eve-shipinfo/trunk/classes/EVEShipInfo.php
r1411207 r1411293 1196 1196 protected $tables = array( 1197 1197 'meta', 1198 'attributes', 1198 1199 'modules', 1199 1200 'modules_slots', … … 1227 1228 ) 1228 1229 ); 1229 1230 1231 $queries[] = array( 1232 'table' => 'attributes', 1233 'data' => 'attributes', 1234 'fields' => array( 1235 'attributeName=%s', 1236 'attributeID=%d', 1237 'defaultValue=%s', 1238 'displayName=%s', 1239 'stackable=%d', 1240 'highIsGood=%d' 1241 ) 1242 ); 1243 1230 1244 $queries[] = array( 1231 1245 'table' => 'modules_slots', … … 1283 1297 'fields' => array( 1284 1298 'typeID=%d', 1285 'attributeName=%s',1286 1299 'attributeID=%d', 1287 1300 'valueInt=%d', 1288 'valueFloat=%f', 1289 'defaultValue=%s', 1290 'displayName=%s', 1291 'stackable=%d', 1292 'highIsGood=%d' 1301 'valueFloat=%f' 1293 1302 ) 1294 1303 ); … … 1299 1308 $query = "INSERT INTO ".$this->getTableName($def['table'])." SET ".implode(', ', $def['fields']); 1300 1309 $entries = $this->loadDataJSON($def['data']); 1310 1301 1311 foreach($entries as $entry) { 1302 1312 $this->dbQuery($query, $entry); -
eve-shipinfo/trunk/classes/EVEShipInfo/Collection/Ship/Attribute.php
r1411207 r1411293 3 3 class EVEShipInfo_Collection_Ship_Attribute 4 4 { 5 const ERROR_UNKNOWN_ATTRIBUTE = 17001; 6 5 7 protected $rawData; 6 8 … … 22 24 protected $plugin; 23 25 26 protected static $globalData; 27 24 28 public function __construct(EVEShipInfo_Collection_Ship $ship, $name) 25 29 { … … 29 33 $this->name = $name; 30 34 31 $this->rawData = $this->plugin->dbFetch( 32 "SELECT 33 * 34 FROM 35 ".$this->plugin->getTableName('ships_attributes')." 36 WHERE 37 typeID=%d 38 AND 39 attributeName=%s", 40 array( 41 $this->ship->getID(), 42 $name 43 ) 35 if(!$this->register()) { 36 return; 37 } 38 39 $values = $this->plugin->dbFetch( 40 "SELECT 41 * 42 FROM 43 ".$this->plugin->getTableName('ships_attributes')." 44 WHERE 45 typeID=%d 46 AND 47 attributeID=%d", 48 array( 49 $this->ship->getID(), 50 self::$globalData[$name]['attributeID'] 51 ) 44 52 ); 53 54 $this->rawData = array_merge(self::$globalData[$name], $values); 55 } 56 57 protected function register() 58 { 59 if(isset(self::$globalData[$this->name])) { 60 return; 61 } 62 63 $global = $this->plugin->dbFetch( 64 "SELECT 65 * 66 FROM 67 ".$this->plugin->getTableName('attributes')." 68 WHERE 69 attributeName=%s", 70 array( 71 $this->name 72 ) 73 ); 74 75 if(empty($global)) { 76 throw new EVEShipInfo_Exception( 77 'Unknown attribute ['.$this->name.'].', 78 'The attribute ['.$this->name.'] cannot be found in the database.', 79 self::ERROR_UNKNOWN_ATTRIBUTE 80 ); 81 } 82 83 self::$globalData[$this->name] = $global; 45 84 } 46 85 … … 52 91 protected function getProperty($name) 53 92 { 54 if(isset($this->rawData[$name])) {55 return $this->rawData[$name];56 }57 58 return null;93 if(isset($this->rawData[$name])) { 94 return $this->rawData[$name]; 95 } 96 97 return null; 59 98 } 60 99 … … 63 102 public function getUnitName() 64 103 { 65 if(!isset($this->unitName)) {66 // unit names are in english, so to support translations67 // we translate the native strings locally.68 $this->unitName = $this->translateNativeString(69 $this->getProperty('displayName')70 );71 }72 73 return $this->unitName;104 if(!isset($this->unitName)) { 105 // unit names are in english, so to support translations 106 // we translate the native strings locally. 107 $this->unitName = $this->translateNativeString( 108 $this->getProperty('displayName') 109 ); 110 } 111 112 return $this->unitName; 74 113 } 75 114 76 115 public function getCategoryName() 77 116 { 78 return $this->getProperty('categoryName');117 return $this->getProperty('categoryName'); 79 118 } 80 119 81 120 public function getIconID() 82 121 { 83 return $this->getProperty('iconID');122 return $this->getProperty('iconID'); 84 123 } 85 124 86 125 public function getValue($pretty=false) 87 126 { 88 $int = $this->getProperty('valueInt');89 $float = $this->getProperty('valueFloat');90 $value = $int;127 $int = $this->getProperty('valueInt'); 128 $float = $this->getProperty('valueFloat'); 129 $value = $int; 91 130 92 if(strlen($value) < 1) {93 $value = $float;94 }95 96 if($pretty) {97 $tokens = explode('.', $value);98 if(isset($tokens[1])) {99 return number_format($value, 2);100 }101 102 return number_format($value);103 }104 105 return $value;131 if($float > $value) { 132 $value = $float; 133 } 134 135 if($pretty) { 136 $tokens = explode('.', $value); 137 if(isset($tokens[1])) { 138 return number_format($value, 2); 139 } 140 141 return number_format($value); 142 } 143 144 return $value; 106 145 } 107 146 … … 116 155 public function getValuePretty() 117 156 { 118 $result = $this->getValue(true);119 120 $units = $this->getUnitName();121 if(!empty($units)) {122 $result .= ' ' . $units;123 }124 125 return $result;157 $result = $this->getValue(true); 158 159 $units = $this->getUnitName(); 160 if(!empty($units)) { 161 $result .= ' ' . $units; 162 } 163 164 return $result; 126 165 } 127 166 128 167 public function __toString() 129 168 { 130 $value = $this->getValue();131 return $value;169 $value = $this->getValue(); 170 return $value; 132 171 } 133 172 … … 136 175 protected function translateNativeString($string) 137 176 { 138 if(!isset(self::$stringTranslations)) {139 self::$stringTranslations = array(140 'HP' => __('HP', 'eve-shipinfo'),141 'MW' => __('MW', 'eve-shipinfo'),142 'm/sec' => __('M/Sec', 'eve-shipinfo'),143 'tf' => __('TF', 'eve-shipinfo'),144 'm' => __('M', 'eve-shipinfo'),145 's' => __('S', 'eve-shipinfo'),146 'GJ' => __('GJ', 'eve-shipinfo'),147 'mm' => __('MM', 'eve-shipinfo'),148 'm3' => __('M3', 'eve-shipinfo'),149 'Mbit/sec' => __('MB/S', 'eve-shipinfo')150 );151 }152 153 if(isset(self::$stringTranslations[$string])) {154 return self::$stringTranslations[$string];155 }156 157 return $string;177 if(!isset(self::$stringTranslations)) { 178 self::$stringTranslations = array( 179 'HP' => __('HP', 'eve-shipinfo'), 180 'MW' => __('MW', 'eve-shipinfo'), 181 'm/sec' => __('M/Sec', 'eve-shipinfo'), 182 'tf' => __('TF', 'eve-shipinfo'), 183 'm' => __('M', 'eve-shipinfo'), 184 's' => __('S', 'eve-shipinfo'), 185 'GJ' => __('GJ', 'eve-shipinfo'), 186 'mm' => __('MM', 'eve-shipinfo'), 187 'm3' => __('M3', 'eve-shipinfo'), 188 'Mbit/sec' => __('MB/S', 'eve-shipinfo') 189 ); 190 } 191 192 if(isset(self::$stringTranslations[$string])) { 193 return self::$stringTranslations[$string]; 194 } 195 196 return $string; 158 197 } 159 198 } -
eve-shipinfo/trunk/classes/EVEShipInfo/Plugin.php
r1411207 r1411293 212 212 } 213 213 214 public function dbQuery($query, $params=array() )214 public function dbQuery($query, $params=array(), $dump=false) 215 215 { 216 216 global $wpdb; … … 218 218 if(!empty($params)) { 219 219 $query = $wpdb->prepare($query, $params); 220 } 221 222 if($dump) { 223 echo '<pre style="background:#fff;color:#000;padding:17px;">'.print_r($query, true).'</pre>'; 220 224 } 221 225 -
eve-shipinfo/trunk/classes/EVEShipInfo/Shortcode.php
r1202080 r1411293 40 40 $this->attributes = shortcode_atts($this->getDefaultAttributes(), $attributes); 41 41 $this->content = $content; 42 43 $this->process(); 42 43 try 44 { 45 $this->process(); 46 } 47 catch(EVEShipInfo_Exception $e) 48 { 49 $this->content = 'EVEShipinfo Error #'.$e->getCode().' '.$e->getMessage(); 50 } 44 51 45 52 return $this->content; -
eve-shipinfo/trunk/errorcodes.txt
r1236586 r1411293 1 1001 2 1101 3 1201 4 1301 5 1401 6 1501 7 1601 1 17001
Note: See TracChangeset
for help on using the changeset viewer.