Commit 6187b5ae authored by Carsten  Rose's avatar Carsten Rose
Browse files

DataImport: Outdated - will me migrated to PhpSpreadsheet.

parent 0aed1bfe
Pipeline #678 passed with stage
in 1 minute and 32 seconds
......@@ -80,7 +80,7 @@ bootstrap: .npmpackages .plantuml_install .virtual_env
basic: .npmpackages .virtual_env
npm update
grunt default
cd extension/Resources/Private; composer update
cd extension/Resources/Private; composer update; rm -rf .github bin docs samples .g* .s* .t* C* c* m* p*
.plantuml_install: .support_plantuml
wget --no-check-certificate -O support/plantuml/plantuml.jar 'https://downloads.sourceforge.net/project/plantuml/plantuml.jar'
......
......@@ -10,32 +10,14 @@ namespace qfq;
use qfq;
//use qfq\Report;
//require_once(__DIR__ . '/store/Store.php');
//require_once(__DIR__ . '/store/FillStoreForm.php');
//require_once(__DIR__ . '/store/Session.php');
require_once(__DIR__ . '/../Constants.php');
require_once(__DIR__ . '/../../../Resources/Private/Classes/PHPExcel/IOFactory.php');
//require_once(__DIR__ . '/Save.php');
//require_once(__DIR__ . '/helper/KeyValueStringParser.php');
//require_once(__DIR__ . '/helper/HelperFormElement.php');
//require_once(__DIR__ . '/exceptions/UserFormException.php');
//require_once(__DIR__ . '/exceptions/CodeException.php');
//require_once(__DIR__ . '/exceptions/DbException.php');
//require_once(__DIR__ . '/exceptions/ErrorHandler.php');
//require_once(__DIR__ . '/../../../Resources/Private/Classes/PHPExcel/IOFactory.php');
require_once(__DIR__ . '/../database/Database.php');
//require_once(__DIR__ . '/database/DatabaseUpdate.php');
//require_once(__DIR__ . '/Evaluate.php');
//require_once(__DIR__ . '/BuildFormPlain.php');
//require_once(__DIR__ . '/BuildFormTable.php');
//require_once(__DIR__ . '/BuildFormBootstrap.php');
//require_once(__DIR__ . '/report/Report.php');
//require_once(__DIR__ . '/BodytextParser.php');
//require_once(__DIR__ . '/Delete.php');
//require_once(__DIR__ . '/form/FormAction.php');
//require_once(__DIR__ . '/form/Dirty.php');
/**
* Class DataImport
* @package qfq
*/
class DataImport {
/**
......@@ -43,18 +25,31 @@ class DataImport {
*/
private $db = null;
/**
* DataImport constructor.
* @param Database $db
*/
public function __construct(Database $db) {
$this->db = $db;
}
/**
* @param $filename
* @param $table
* @param string $region
* @param string $mode
* @return string
* @throws CodeException
* @throws DbException
*/
public function process($filename, $table, $region = IMPORT_REGION_DEFAULT, $mode = IMPORT_MODE_REPLACE) {
// echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory to identify the format<br />';
$objPHPExcel = \PHPExcel_IOFactory::load($filename);
// $objPHPExcel = \PHPExcel_IOFactory::load($filename);
$table = IMPORT_PREFIX . $table;
$columnDefinition = $this->prepareTable($objPHPExcel);
// $columnDefinition = $this->prepareTable($objPHPExcel);
$this->db->createTable($table, $columnDefinition, $mode);
......@@ -63,61 +58,61 @@ class DataImport {
return '';
}
/**
* @param \PHPExcel_IOFactory $objPHPExcel
* @return array
*/
private function prepareTable(\PHPExcel $objPHPExcel) {
$columnDefinition = array();
for ($ii = 0; $ii < 10; $ii++) {
$columnDefinition[] = [CHR(65 + $ii), 'varchar(255)'];
}
return $columnDefinition;
}
private function importRows(\PHPExcel $objPHPExcel) {
$highestRow = 0;
$highestColumnIndex = 0;
$worksheet = null;
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
$worksheetTitle = $worksheet->getTitle();
$highestRow = $worksheet->getHighestRow(); // e.g. 10
$highestColumn = $worksheet->getHighestColumn(); // e.g 'F'
$highestColumnIndex = \PHPExcel_Cell::columnIndexFromString($highestColumn);
$nrColumns = ord($highestColumn) - 64;
// echo "<br>The worksheet " . $worksheetTitle . " has ";
// echo $nrColumns . ' columns (A-' . $highestColumn . ') ';
// echo ' and ' . $highestRow . ' row.';
// echo '<br>Data: <table border="1"><tr>';
for ($row = 1; $row <= $highestRow; ++$row) {
echo '<tr>';
for ($col = 0; $col < $highestColumnIndex; ++$col) {
$cell = $worksheet->getCellByColumnAndRow($col, $row);
$val = $cell->getValue();
$dataType = \PHPExcel_Cell_DataType::dataTypeForValue($val);
echo '<td>' . $val . '<br>(Typ ' . $dataType . ')</td>';
}
echo '</tr>';
}
echo '</table>';
}
for ($row = 2; $row <= $highestRow; ++$row) {
$val = array();
for ($col = 0; $col < $highestColumnIndex; ++$col) {
$cell = $worksheet->getCellByColumnAndRow($col, $row);
$val[] = $cell->getValue();
}
$Connection = "INSERT INTO `users` (name, family, type) VALUES ('" . $val[1] . "','" . $val[2] . "','" . $val[3] . "')";
}
}
// /**
// * @param \PHPExcel_IOFactory $objPHPExcel
// * @return array
// */
// private function prepareTable(\PHPExcel $objPHPExcel) {
//
// $columnDefinition = array();
//
// for ($ii = 0; $ii < 10; $ii++) {
// $columnDefinition[] = [CHR(65 + $ii), 'varchar(255)'];
// }
//
// return $columnDefinition;
// }
//
// private function importRows(\PHPExcel $objPHPExcel) {
// $highestRow = 0;
// $highestColumnIndex = 0;
// $worksheet = null;
//
// foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
// $worksheetTitle = $worksheet->getTitle();
// $highestRow = $worksheet->getHighestRow(); // e.g. 10
// $highestColumn = $worksheet->getHighestColumn(); // e.g 'F'
// $highestColumnIndex = \PHPExcel_Cell::columnIndexFromString($highestColumn);
// $nrColumns = ord($highestColumn) - 64;
//// echo "<br>The worksheet " . $worksheetTitle . " has ";
//// echo $nrColumns . ' columns (A-' . $highestColumn . ') ';
//// echo ' and ' . $highestRow . ' row.';
//// echo '<br>Data: <table border="1"><tr>';
// for ($row = 1; $row <= $highestRow; ++$row) {
// echo '<tr>';
// for ($col = 0; $col < $highestColumnIndex; ++$col) {
// $cell = $worksheet->getCellByColumnAndRow($col, $row);
// $val = $cell->getValue();
// $dataType = \PHPExcel_Cell_DataType::dataTypeForValue($val);
// echo '<td>' . $val . '<br>(Typ ' . $dataType . ')</td>';
// }
// echo '</tr>';
// }
// echo '</table>';
// }
//
// for ($row = 2; $row <= $highestRow; ++$row) {
// $val = array();
// for ($col = 0; $col < $highestColumnIndex; ++$col) {
// $cell = $worksheet->getCellByColumnAndRow($col, $row);
// $val[] = $cell->getValue();
// }
//
// $Connection = "INSERT INTO `users` (name, family, type) VALUES ('" . $val[1] . "','" . $val[2] . "','" . $val[3] . "')";
// }
//
// }
//
//
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment