Add encodeArrayValue | decodeArrayValue helpers
This commit is contained in:
parent
5b8d436c5e
commit
8166c5ad6a
|
|
@ -183,4 +183,24 @@ abstract class ExportModel extends Model
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implodes a single dimension array using pipes (|)
|
||||||
|
* Multi dimensional arrays are not allowed.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function encodeArrayValue($data, $delimeter = '|')
|
||||||
|
{
|
||||||
|
$newData = [];
|
||||||
|
foreach ($data as $value) {
|
||||||
|
if (is_array($value)) {
|
||||||
|
$newData[] = 'Array';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$newData[] = str_replace($delimeter, '\\'.$delimeter, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode($delimeter, $newData);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -129,6 +129,24 @@ abstract class ImportModel extends Model
|
||||||
return $newRow;
|
return $newRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Explodes a string using pipes (|) to a single dimension array
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function decodeArrayValue($value, $delimeter = '|')
|
||||||
|
{
|
||||||
|
if (strpos($value, $delimeter) === false) return $value;
|
||||||
|
|
||||||
|
$data = preg_split('~(?<!\\\)' . preg_quote($delimeter, '~') . '~', $value);
|
||||||
|
$newData = [];
|
||||||
|
|
||||||
|
foreach ($data as $_value) {
|
||||||
|
$newData[] = str_replace('\\'.$delimeter, $delimeter, $_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $newData;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an attached imported file local path, if available.
|
* Returns an attached imported file local path, if available.
|
||||||
* @return string
|
* @return string
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue