Files
OMS/app/omecsv/lib/io/io.php
2025-12-28 23:13:25 +08:00

71 lines
1.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Copyright © ShopeX http://www.shopex.cn. All rights reserved.
* See LICENSE file for license details.
*/
class omecsv_io_io{
var $charset = null;
var $limitRow = 20000;
public function __construct(){
if(!setlocale(LC_ALL, 'zh_CN.gbk')){
setlocale(LC_ALL, "chs");
}
$this->charset = kernel::single('base_charset');
}
public function getTitle(&$cols){
$title = array();
foreach( $cols as $col => $val ){
if( !$val['deny_export'] )
$title[$col] = $val['label'].'('.$col.')';
}
return $title;
}
public function init( &$model ){
$model->charset = $this->charset;
$model->io = $this;
$this->model->$model;
}
/**
* @param String $inputFileName 导入文件名
* @param Array $contents 数量
* @return Void
**/
public function fgethandle($inputFileName,&$contents){
$path = pathinfo($inputFileName);
$excel = new \Vtiful\Kernel\Excel(['path' => $path['dirname']]);
$excel->openFile($path['basename'])
->openSheet();
$row = $excel->nextRow();
if(!is_array($row)) {
throw new exception('Don\'t find import title');
}
$contents = $excel->setType(array_pad([], count($row), \Vtiful\Kernel\Excel::TYPE_STRING))
->getSheetData();
$contents = array_merge([0 => $row], $contents);
}
public function prepared_import( $appId,$mdl ){
$this->model = app::get($appId)->model($mdl);
$this->model->ioObj = $this;
if( method_exists( $this->model,'prepared_import_csv' ) ){
$this->model->prepared_import_csv();
}
return;
}
public function finish_import(){
if( method_exists( $this->model,'finish_import_csv' ) ){
$this->model->finish_import_csv();
}
}
}