mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-14 09:44:55 +02:00
Use $db->exec where appropriate
May bring some performance boost (little, but still)
This commit is contained in:
@@ -16,21 +16,21 @@ class Weapons {
|
||||
public static function loadFromXML($show = false)
|
||||
{
|
||||
global $config, $db;
|
||||
|
||||
|
||||
try {
|
||||
$db->query("DELETE FROM `myaac_weapons`;");
|
||||
$db->exec("DELETE FROM `myaac_weapons`;");
|
||||
} catch (PDOException $error) {
|
||||
}
|
||||
|
||||
|
||||
$file_path = $config['data_path'] . 'weapons/weapons.xml';
|
||||
if (!file_exists($file_path)) {
|
||||
self::$error = 'Cannot load file ' . $file_path;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$xml = new DOMDocument;
|
||||
$xml->load($file_path);
|
||||
|
||||
|
||||
foreach ($xml->getElementsByTagName('wand') as $weapon) {
|
||||
self::parseNode($weapon, $show);
|
||||
}
|
||||
@@ -40,18 +40,18 @@ class Weapons {
|
||||
foreach ($xml->getElementsByTagName('distance') as $weapon) {
|
||||
self::parseNode($weapon, $show);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static function parseNode($node, $show = false) {
|
||||
global $config, $db;
|
||||
|
||||
|
||||
$id = (int)$node->getAttribute('id');
|
||||
$vocations_ids = array_flip($config['vocations']);
|
||||
$level = (int)$node->getAttribute('level');
|
||||
$maglevel = (int)$node->getAttribute('maglevel');
|
||||
|
||||
|
||||
$vocations = array();
|
||||
foreach($node->getElementsByTagName('vocation') as $vocation) {
|
||||
$show = $vocation->getAttribute('showInDescription');
|
||||
@@ -60,10 +60,10 @@ class Weapons {
|
||||
else {
|
||||
$voc_id = $vocations_ids[$vocation->getAttribute('name')];
|
||||
}
|
||||
|
||||
|
||||
$vocations[$voc_id] = strlen($show) == 0 || $show != '0';
|
||||
}
|
||||
|
||||
|
||||
$exist = $db->query('SELECT `id` FROM `' . TABLE_PREFIX . 'weapons` WHERE `id` = ' . $id);
|
||||
if($exist->rowCount() > 0) {
|
||||
if($show) {
|
||||
@@ -74,7 +74,7 @@ class Weapons {
|
||||
$db->insert(TABLE_PREFIX . 'weapons', array('id' => $id, 'level' => $level, 'maglevel' => $maglevel, 'vocations' => json_encode($vocations)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function getError() {
|
||||
return self::$error;
|
||||
}
|
||||
|
Reference in New Issue
Block a user