Plugin Directory

Changeset 1411293


Ignore:
Timestamp:
05/05/2016 09:11:20 PM (10 years ago)
Author:
AeonOfTime
Message:

Moved attributes to separate table.

Location:
eve-shipinfo/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • eve-shipinfo/trunk/classes/EVEShipInfo.php

    r1411207 r1411293  
    11961196    protected $tables = array(
    11971197        'meta',
     1198        'attributes',
    11981199        'modules',
    11991200        'modules_slots',
     
    12271228            )
    12281229        );
    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         
    12301244        $queries[] = array(
    12311245            'table' => 'modules_slots',
     
    12831297                'fields' => array(
    12841298                    'typeID=%d',
    1285                     'attributeName=%s',
    12861299                    'attributeID=%d',
    12871300                    'valueInt=%d',
    1288                     'valueFloat=%f',
    1289                     'defaultValue=%s',
    1290                     'displayName=%s',
    1291                     'stackable=%d',
    1292                     'highIsGood=%d'
     1301                    'valueFloat=%f'
    12931302                )
    12941303            );
     
    12991308            $query = "INSERT INTO ".$this->getTableName($def['table'])." SET ".implode(', ', $def['fields']);
    13001309            $entries = $this->loadDataJSON($def['data']);
     1310           
    13011311            foreach($entries as $entry) {
    13021312                $this->dbQuery($query, $entry);
  • eve-shipinfo/trunk/classes/EVEShipInfo/Collection/Ship/Attribute.php

    r1411207 r1411293  
    33class EVEShipInfo_Collection_Ship_Attribute
    44{
     5    const ERROR_UNKNOWN_ATTRIBUTE = 17001;
     6   
    57    protected $rawData;
    68   
     
    2224    protected $plugin;
    2325   
     26    protected static $globalData;
     27   
    2428    public function __construct(EVEShipInfo_Collection_Ship $ship, $name)
    2529    {
     
    2933        $this->name = $name;
    3034       
    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            )
    4452        );
     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;
    4584    }
    4685   
     
    5291    protected function getProperty($name)
    5392    {
    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;
    5998    }
    6099   
     
    63102    public function getUnitName()
    64103    {
    65         if(!isset($this->unitName)) {
    66             // unit names are in english, so to support translations
    67             // 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;
    74113    }
    75114   
    76115    public function getCategoryName()
    77116    {
    78         return $this->getProperty('categoryName');
     117        return $this->getProperty('categoryName');
    79118    }
    80119   
    81120    public function getIconID()
    82121    {
    83         return $this->getProperty('iconID');
     122        return $this->getProperty('iconID');
    84123    }
    85124   
    86125    public function getValue($pretty=false)
    87126    {
    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;
    91130
    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;
    106145    }
    107146   
     
    116155    public function getValuePretty()
    117156    {
    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;
    126165    }
    127166   
    128167    public function __toString()
    129168    {
    130         $value = $this->getValue();
    131         return $value;
     169        $value = $this->getValue();
     170        return $value;
    132171    }
    133172   
     
    136175    protected function translateNativeString($string)
    137176    {
    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;
    158197    }
    159198}
  • eve-shipinfo/trunk/classes/EVEShipInfo/Plugin.php

    r1411207 r1411293  
    212212    }
    213213
    214     public function dbQuery($query, $params=array())
     214    public function dbQuery($query, $params=array(), $dump=false)
    215215    {
    216216        global $wpdb;
     
    218218        if(!empty($params)) {
    219219            $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>';
    220224        }
    221225       
  • eve-shipinfo/trunk/classes/EVEShipInfo/Shortcode.php

    r1202080 r1411293  
    4040        $this->attributes = shortcode_atts($this->getDefaultAttributes(), $attributes);
    4141        $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        }
    4451       
    4552        return $this->content;
  • eve-shipinfo/trunk/errorcodes.txt

    r1236586 r1411293  
    1 1001
    2 1101
    3 1201
    4 1301
    5 1401
    6 1501
    7 1601
     117001
Note: See TracChangeset for help on using the changeset viewer.