Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 101 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions example/pages/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,14 @@ function export5()
->setTitle($defined)
->setContent($defined);

// 建構外部對映表
// 建構外部對映表 - 有異常換行
$listMap = array(
'gender' => array(
array(
'value' => '1',
'text' => '男'
'value' => '1
',
'text' => '男
'
),
array(
'value' => '0',
Expand Down
40 changes: 33 additions & 7 deletions src/config/abstracts/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ abstract class Config
// 模式:簡易(simple)、複雜(complex)、待偵測(detect)
'type' => 'detect',
// 必要欄位,必需有值,提供讀取資料時驗証用 - 有設定,且必要欄位有無資料者,跳出 - 因各版本excel對空列定義不同,可能編輯過列,就會產生沒有結尾的空列
'requiredField' => array()
'requiredField' => array(),
// List Menu 不匹配時的回傳值,預設為空字串
'listMismatchValue' => '',
);

/**
Expand Down Expand Up @@ -183,7 +185,7 @@ public function getOption($optionName = null)
return $this->_options;
} else {
// 指定鍵名
if (! isset($this->_options[$optionName])) {
if (! array_key_exists($optionName, $this->_options)) {
throw new \Exception('Donot have option: ' . $optionName . ' !', 404);
}

Expand Down Expand Up @@ -658,6 +660,9 @@ public function contentFilter(Array & $data)
*/
public function contentParser(Array & $data)
{
// 取得List Menu不匹配時的回傳值
$listMismatchValue = $this->getOption('listMismatchValue');

// 將現有對映表轉成text=>value格式存入暫存
$this->text2ValueMapBuilder();
// 資料範本資料量、key
Expand All @@ -676,11 +681,11 @@ public function contentParser(Array & $data)
$row = array_slice($row, 0, $templateSize);
$row = array_combine($templateKey, $row);

// 執行資料轉換 value <=> text - 單筆資料
$this->valueTextConv($key, $row);

// issue#13 Trim all data when parsing imported data
$row = array_map('trim', $row);

// 執行資料轉換 value <=> text - 單筆資料
$this->valueTextConv($key, $row, $listMismatchValue);
}
}

Expand Down Expand Up @@ -729,8 +734,9 @@ public function contentValidate(Array $row)
* 當次迴圈的Key值
* @param array $row
* 當次迴圈的內容
* @param array $mismatchValue List menu不匹配時回傳值
*/
public function valueTextConv($key, &$row)
public function valueTextConv($key, &$row, $mismatchValue = '')
{
// 遍歷資料,並轉換內容
foreach ($row as $k => &$v) {
Expand All @@ -740,7 +746,7 @@ public function valueTextConv($key, &$row)
}

// 處理資料轉換
$v = isset($this->_cache['valueTextMap'][$k][$v]) ? $this->_cache['valueTextMap'][$k][$v] : '';
$v = isset($this->_cache['valueTextMap'][$k][$v]) ? $this->_cache['valueTextMap'][$k][$v] : $mismatchValue;
}
}

Expand All @@ -755,6 +761,9 @@ public function valueTextConv($key, &$row)
*/
public function value2TextMapBuilder()
{
// 下拉選單內容處理 - 去頭尾空白
$this->trimMap();

// 初始化暫存
$this->_cache['valueTextMap'] = array();

Expand All @@ -768,6 +777,9 @@ public function value2TextMapBuilder()
*/
public function text2ValueMapBuilder()
{
// 下拉選單內容處理 - 去頭尾空白
$this->trimMap();

// 初始化暫存
$this->_cache['valueTextMap'] = array();

Expand All @@ -776,6 +788,20 @@ public function text2ValueMapBuilder()
}
}

/**
* 下拉選單內容處理 - 去頭尾空白
*
* @return void
*/
public function trimMap()
{
foreach ($this->_listMap as &$lists) {
foreach ($lists as &$list) {
$list = array_map('trim', $list);
}
}
}

/**
* **********************************************
* ************** Defined Function **************
Expand Down