From 64e343dd386f06bba16c3cd23aebe1d2af91c001 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Fri, 14 Jun 2024 19:57:50 +0400 Subject: [PATCH] modifs.mineures sans commentaires --- nur_src/v/bs3/Bs3IconManager.php | 3 ++ src/A.php | 51 ++++++++++++++++++++++++++++++-- src/file/csv/AbstractReader.php | 11 +++++-- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/nur_src/v/bs3/Bs3IconManager.php b/nur_src/v/bs3/Bs3IconManager.php index 0465df0..a81cbbd 100644 --- a/nur_src/v/bs3/Bs3IconManager.php +++ b/nur_src/v/bs3/Bs3IconManager.php @@ -15,6 +15,7 @@ class Bs3IconManager implements IIconManager { "config" => "cog", "save" => "floppy-disk", "download" => "download-alt", + "upload" => "cloud-upload", "new_window", "mail" => "enveloppe", "search", @@ -84,6 +85,7 @@ EOT; 'config' => 'cog', 'save' => 'floppy-disk', 'download' => 'download-alt', + 'upload' => 'cloud-upload', 'new_window' => 'new-window', 'mail' => 'enveloppe', 'search' => 'search', @@ -138,6 +140,7 @@ EOT; const CONFIG = /*autogen*/['']; const SAVE = /*autogen*/['']; const DOWNLOAD = /*autogen*/['']; + const UPLOAD = /*autogen*/['']; const NEW_WINDOW = /*autogen*/['']; const MAIL = /*autogen*/['']; const SEARCH = /*autogen*/['']; diff --git a/src/A.php b/src/A.php index 225f668..a610fa5 100644 --- a/src/A.php +++ b/src/A.php @@ -64,7 +64,7 @@ class A { $dest = cl::mpselect($dest, $merge, $pkeys); } - static final function append_nn(?array &$dest, $value, $key=null) { + static final function set_nn(?array &$dest, $key, $value) { if ($value !== null) { if ($key === null) $dest[] = $value; else $dest[$key] = $value; @@ -72,7 +72,11 @@ class A { return $value; } - static final function append_nz(?array &$dest, $value, $key=null) { + static final function append_nn(?array &$dest, $value, $key=null) { + return self::set_nn($dest, $key, $value); + } + + static final function set_nz(?array &$dest, $key, $value) { if ($value !== null && $value !== false) { if ($key === null) $dest[] = $value; else $dest[$key] = $value; @@ -80,6 +84,10 @@ class A { return $value; } + static final function append_nz(?array &$dest, $value, $key=null) { + return self::set_nz($dest, $key, $value); + } + static final function prepend_nn(?array &$dest, $value) { if ($value !== null) { if ($dest === null) $dest = []; @@ -95,4 +103,43 @@ class A { } return $value; } + + static final function replace_nx(?array &$dest, $key, $value) { + if ($dest !== null && !array_key_exists($key, $dest)) { + return $dest[$key] = $value; + } else { + return $dest[$key] ?? null; + } + } + + static final function replace_n(?array &$dest, $key, $value) { + $pvalue = $dest[$key] ?? null; + if ($pvalue === null) $dest[$key] = $value; + return $pvalue; + } + + static final function replace_z(?array &$dest, $key, $value) { + $pvalue = $dest[$key] ?? null; + if ($pvalue === null || $pvalue === false) $dest[$key] = $value; + return $pvalue; + } + + static final function pop(?array $dest, $key, $default=null) { + if ($dest === null) return $default; + if ($key === null) return array_pop($dest); + $value = $dest[$key] ?? $default; + unset($dest[$key]); + return $value; + } + + static final function popx(?array $dest, ?array $keys): array { + $values = []; + if ($dest === null) return $values; + if ($keys === null) return $values; + foreach ($keys as $key) { + $values[$key] = self::pop($dest, $key); + } + return $values; + } + } diff --git a/src/file/csv/AbstractReader.php b/src/file/csv/AbstractReader.php index 82bd29d..7ef5237 100644 --- a/src/file/csv/AbstractReader.php +++ b/src/file/csv/AbstractReader.php @@ -18,6 +18,7 @@ abstract class AbstractReader implements IReader { $this->schema = $params["schema"] ?? static::SCHEMA; $this->headers = $params["headers"] ?? static::HEADERS; $this->input = $params["input"] ?? static::INPUT; + $this->parseEmptyAsNull = boolval($params["empty_as_null"] ?? true); } protected ?array $schema; @@ -26,6 +27,8 @@ abstract class AbstractReader implements IReader { protected $input; + protected bool $parseEmptyAsNull; + protected int $isrc = 0, $idest = 0; protected function cook(array &$row): bool { @@ -45,10 +48,14 @@ abstract class AbstractReader implements IReader { } protected function verifixCol(&$col): void { - # conversion Date et DateTime - if (DateTime::isa_datetime($col, true)) { + if ($col === "" && $this->parseEmptyAsNull) { + # valeur vide --> null + $col = null; + } elseif (DateTime::isa_datetime($col, true)) { + # datetime $col = new DateTime($col); } elseif (DateTime::isa_date($col, true)) { + # date $col = new Date($col); } }