DB Dump Working

This commit is contained in:
color.diff=auto
2021-03-24 04:26:51 -06:00
parent 50252def84
commit 7a6d2ace00
12 changed files with 17280 additions and 35 deletions

74
src/D2Database.php Normal file
View File

@@ -0,0 +1,74 @@
<?php
/*
GPLv2 (C) <2021> <HashCasper>
This file is part of D2IM.
D2IM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
D2IM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with D2IM. If not, see <http://www.gnu.org/licenses/>.
*/
class D2Database {
public function __construct() {
PDO_Connect("sqlite:" . DB_FILE);
}
public function createTables($file, $data) {
$tableName = basename($file);
$tableName = strtolower(substr($tableName, 0, -4));
$sql = "CREATE TABLE IF NOT EXISTS `$tableName` (";
foreach ($data[0] as $k => $v) {
if (is_numeric($v)) {
$dataType = "INT";
} else {
$dataType = "VARCHAR(255)";
}
$sql .= "`$k` $dataType NOT NULL,";
}
$sql = rtrim($sql, ",");
$sql .= ")";
$res = PDO_Execute($sql);
}
public function fillsTables($file, $data) {
$tableName = basename($file);
$tableName = strtolower(substr($tableName, 0, -4));
foreach ($data as $d) {
$sql = "INSERT INTO `$tableName` (";
if (!empty($d)) {
foreach ($d as $k => $v) {
$sql .= "`$k`" . ",";
}
}
$sql = rtrim($sql, ",");
$sql .= ") ";
$sql .= "VALUES (";
if (!empty($d)) {
foreach ($d as $k => $v) {
$sql .= '"' . $v . '"' . ",";
}
}
$sql = rtrim($sql, ",");
$sql .= ");";
var_dump($sql);
PDO_Execute($sql);
}
}
}

View File

@@ -1,6 +1,6 @@
<?php
function dd($var) {
function ddump($var) {
echo "<pre>";
var_dump($var);
echo "</pre>";

41
src/D2Gems.php Normal file
View File

@@ -0,0 +1,41 @@
<?php
/*
GPLv2 (C) <2021> <HashCasper>
This file is part of D2IM.
D2IM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
D2IM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with D2IM. If not, see <http://www.gnu.org/licenses/>.
*/
?>
<h2>Gem Maker</h2>
<div class="container">
<div class="form-group row">
<div class="col-2" style="background: #ccd;">
<select class="m-select custom-select" name="code[]" id="" required="required">
<option value="">Misc</option>
<?php
foreach ($misc as $a)
if ($a['spawnable']) {
echo '<option value="' . $a['code'] . '">' . $a['name'] . '</option>';
} else {
echo '<option disabled value="' . $a['code'] . '">' . $a['name'] . '</option>';
}
?>
</select>
</div>
</div>
</div>

View File

@@ -24,13 +24,10 @@ class D2SaveFile {
public $path;
public function save($file, $data) {
$fp = fopen($this->path.DIRECTORY_SEPARATOR.$file, 'a+');
$this->saveBackup($file);
fputcsv($fp, $data, "\t");
$this->saveBackup($file);
fputcsv($fp, $data, "\t");
}

View File

@@ -26,10 +26,10 @@ class D2TxtParser {
public $path = TXT_PATH;
// Files specific to Unique Items
public $db;
public function __construct() {
$this->db = new D2Database();
}
public function parseFile($file) {
@@ -46,10 +46,10 @@ class D2TxtParser {
$allProps[] = $d['code'];
}
$filteredProps = array_diff($allProps, $propsToFilter);
return $filteredProps;
return $filteredProps;
}
public function parseData($file) {
public function parseData($file) {
$file = $this->path . $file;
$rows = array_map(function ($v) {
return str_getcsv($v, "\t");
@@ -58,9 +58,12 @@ class D2TxtParser {
$header = array_shift($rows);
foreach ($rows as $row) {
$data[] = @array_combine($header, $row);
}
}
$this->db->createTables($file, $data);
$this->db->fillsTables($file, $data);
return $data;
}
}
?>

View File

@@ -203,8 +203,8 @@
</div>
<div class="form-group row">
<?php
$html = '';
$html = '';
foreach (range(01, 12) as $p) {
?>
<div class="col-2" style="padding: 15px;margin: 10px 0px; background: #ddd;">

View File

@@ -38,6 +38,9 @@
<li class="nav-item" role="presentation">
<a class="nav-link" id="Set-tab" data-toggle="tab" href="#Set" role="tab" aria-controls="Set" aria-selected="false">SetItems.txt</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="Gem-tab" data-toggle="tab" href="#Gem" role="tab" aria-controls="Set" aria-selected="false">Gems.txt</a>
</li>
</ul>
</div>
<div class="tab-content" id="TabContent">
@@ -47,4 +50,7 @@
<div class="tab-pane fade" id="Set" role="tabpanel" aria-labelledby="Set-tab">
<?php require_once 'D2SM.php'; ?>
</div>
<div class="tab-pane fade" id="Gem" role="tabpanel" aria-labelledby="Gem-tab">
<?php require_once 'D2Gems.php'; ?>
</div>
</div>