add the dataimport-target template,fixed errors in csv import
This commit is contained in:
parent
6eae29d926
commit
469d0bdb20
|
@ -4184,7 +4184,10 @@ class Admin_DataController extends Zend_Controller_Action
|
|||
$file = $this->_getParam('file');
|
||||
|
||||
if(empty($file))
|
||||
$this->view->error = "参数错误";
|
||||
{
|
||||
view::Post($this,"參數錯誤",-1);
|
||||
return true;
|
||||
}
|
||||
|
||||
$fileHandle = new Dataimport\File;
|
||||
$realfile = $fileHandle->getRealName($file);
|
||||
|
@ -4210,8 +4213,6 @@ class Admin_DataController extends Zend_Controller_Action
|
|||
//文件類型>view->error
|
||||
$this->view->Type = $processing->getType();
|
||||
|
||||
view::Dump($processing->getLines(),false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -4235,9 +4236,23 @@ class Admin_DataController extends Zend_Controller_Action
|
|||
return true;
|
||||
}
|
||||
|
||||
//選擇導入目標
|
||||
if($ac == "target")
|
||||
{
|
||||
$this->_helper->viewRenderer('dataimport-target');
|
||||
|
||||
$this->view->file = $file = $this->_getParam('file');
|
||||
|
||||
if(empty($file)){
|
||||
view::Post($this,"參數錯誤",-1);
|
||||
return true;
|
||||
}
|
||||
|
||||
$tableControl = new Visual\DataTableControl;
|
||||
$this->view->schema = $tableControl->readSchema();
|
||||
}
|
||||
|
||||
return true;
|
||||
}//dataimportAction()
|
||||
|
||||
public function doiAction()
|
||||
|
|
|
@ -30,7 +30,7 @@ $this->headTitle()->setSeparator(' - ');
|
|||
|
||||
<h6 id="error-loading"></h6>
|
||||
|
||||
<a href="javascript:void(0);">下一步</a>
|
||||
<a href="javascript:void(0);" id="clt-next" class="btn btn-success disabled">下一步</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
@ -45,6 +45,8 @@ $this->headTitle()->setSeparator(' - ');
|
|||
{
|
||||
if(data.status == true)
|
||||
{
|
||||
$('#clt-next').removeClass('disabled');
|
||||
$('#clt-next').attr('href','/admin/data/dataimport/ac/target?file=<?= $this->file ?>');
|
||||
alert("數據完整性檢查成功,可以進行下一步");
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
$this->headTitle($this->config->title->site);
|
||||
$this->headTitle('后台管理');
|
||||
$this->headTitle()->setSeparator(' - ');
|
||||
?>
|
||||
<div class="row-fluid">
|
||||
<div class="span2">
|
||||
<?= $this->partial('data/left.phtml'); ?>
|
||||
</div>
|
||||
|
||||
<div class="span10">
|
||||
<h3>數據導入<small>選擇導入目標</small></h3>
|
||||
<hr />
|
||||
|
||||
導入文件:<?= $this->file ?>
|
||||
|
||||
<h5>選擇數據庫</h5>
|
||||
<ul class="unstyled">
|
||||
<?php foreach($this->schema as $v){ ?>
|
||||
<li><input type="radio" class="ctl-table-btn" value="<?= $v ?>"> <?= $v ?></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
|
||||
<hr />
|
||||
|
||||
<h5 class="error-alerts" style="display: none;">錯誤消息</h5>
|
||||
<ul id="errors" class="error-alerts" style="display: none;">
|
||||
|
||||
</ul>
|
||||
|
||||
<h6 id="error-loading"></h6>
|
||||
|
||||
<form action="/admin/data/dataimport/ac/table">
|
||||
<input type="hidden" name="file" value="<?= $this->file ?>">
|
||||
<input type="hidden" name="table" value="">
|
||||
<button type="submit" id="ctl-next" class="btn btn-success disabled" disabled>下一步</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$('.ctl-table-btn').click(function(){
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -8,7 +8,7 @@
|
|||
namespace Westdc\Dataimport\Processing;
|
||||
|
||||
use Westdc\Dataimport\ProcessingInterface;
|
||||
use League\Csv\Reader;
|
||||
use Goodby\CSV as CSVOBJ;
|
||||
|
||||
class Csv implements ProcessingInterface{
|
||||
|
||||
|
@ -27,9 +27,15 @@ class Csv implements ProcessingInterface{
|
|||
public function init($file)
|
||||
{
|
||||
$this->source_file = $file;
|
||||
$this->csv_object = Reader::createFromPath($this->source_file);
|
||||
$this->csv_object->setDelimiter(',');
|
||||
$this->csv_object->setEncodingFrom("utf-8");
|
||||
|
||||
$interpreter = new CSVOBJ\Import\Standard\Interpreter;
|
||||
$interpreter->addObserver(function($columns){
|
||||
$this->csv_line_data[] = $columns;
|
||||
});
|
||||
$lexer = new CSVOBJ\Import\Standard\Lexer(new CSVOBJ\Import\Standard\LexerConfig);
|
||||
$lexer->parse($file,$interpreter);
|
||||
|
||||
$this->csv_object = $lexer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,7 +43,7 @@ class Csv implements ProcessingInterface{
|
|||
* @return int
|
||||
*/
|
||||
public function getLineCount(){
|
||||
return count($this->csv_object->fetchAll());
|
||||
return count($this->csv_line_data);
|
||||
}//getLineCount()
|
||||
|
||||
/**
|
||||
|
@ -73,7 +79,7 @@ class Csv implements ProcessingInterface{
|
|||
*/
|
||||
public function getLines()
|
||||
{
|
||||
return $this->csv_object->fetchAll();
|
||||
return $this->csv_line_data;
|
||||
}//getLines()
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,18 @@ class DataTableControl extends Database{
|
|||
parent::__construct();
|
||||
}
|
||||
|
||||
public function readSchema(){
|
||||
$sql = "SELECT distinct(schemaname) FROM pg_tables WHERE tableowner='gis'";
|
||||
$rs = $this->db->query($sql);
|
||||
|
||||
$rows = $rs->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
foreach($rows as $k=>$v)
|
||||
{
|
||||
yield $v['schemaname'];
|
||||
}
|
||||
}
|
||||
|
||||
public function readTables()
|
||||
{
|
||||
$sql = "SELECT schemaname||'.'||tablename as tablename FROM pg_tables WHERE tableowner='gis' ORDER BY tablename ";
|
||||
|
|
Loading…
Reference in New Issue