From 7b503a05f1fcab78a8acb65f995a7b6b4ecbec4e Mon Sep 17 00:00:00 2001 From: Damien <damien.burel@maarch.org> Date: Tue, 22 Jan 2019 16:22:47 +0100 Subject: [PATCH] FEAT #9284 Export Date type --- .../resource/controllers/ExportController.php | 6 ++--- src/core/models/CoreConfigModel.php | 22 ++++++++++++++----- src/core/models/TextFormatModel.php | 17 +++++--------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/app/resource/controllers/ExportController.php b/src/app/resource/controllers/ExportController.php index 826301c8b0c..32da5089936 100644 --- a/src/app/resource/controllers/ExportController.php +++ b/src/app/resource/controllers/ExportController.php @@ -24,6 +24,7 @@ use Resource\models\ResourceListModel; use Respect\Validation\Validator; use Slim\Http\Request; use Slim\Http\Response; +use SrcCore\models\TextFormatModel; use SrcCore\models\ValidatorModel; use Tag\models\TagModel; use User\models\UserModel; @@ -222,9 +223,8 @@ class ExportController $csvContent[] = ExportController::getSignatureDates(['resId' => $resource['res_id']]); } } else { - if (strpos($value['value'], 'date') !== false && !empty($resource[$value['value']])) { - $date = new \DateTime($resource[$value['value']]); - $csvContent[] = $date->format('d-m-Y H:i'); + if (strpos($value['value'], 'date') !== false) { + $csvContent[] = TextFormatModel::formatDate($resource[$value['value']]); } else { $csvContent[] = $resource[$value['value']]; } diff --git a/src/core/models/CoreConfigModel.php b/src/core/models/CoreConfigModel.php index e492e797ba3..6d86881cf69 100755 --- a/src/core/models/CoreConfigModel.php +++ b/src/core/models/CoreConfigModel.php @@ -15,13 +15,19 @@ namespace SrcCore\models; -//This model is not customizable class CoreConfigModel { public static function getCustomId() { + static $customId = null; + + if ($customId !== null) { + return $customId; + } + if (!file_exists('custom/custom.xml') || empty($_SERVER['SCRIPT_NAME']) || empty($_SERVER['SERVER_ADDR'])) { - return ''; + $customId = ''; + return $customId; } $explodeUrl = explode('/', $_SERVER['SCRIPT_NAME']); @@ -39,15 +45,19 @@ class CoreConfigModel $xmlfile = simplexml_load_file('custom/custom.xml'); foreach ($xmlfile->custom as $value) { if (!empty($value->path) && $value->path == $path) { - return (string)$value->custom_id; + $customId = (string)$value->custom_id; + return $customId; } elseif ($value->ip == $_SERVER['SERVER_ADDR']) { - return (string)$value->custom_id; + $customId = (string)$value->custom_id; + return $customId; } elseif ($value->external_domain == $_SERVER['HTTP_HOST'] || $value->domain == $_SERVER['HTTP_HOST']) { - return (string)$value->custom_id; + $customId = (string)$value->custom_id; + return $customId; } } - return ''; + $customId = ''; + return $customId; } public static function getApplicationName() diff --git a/src/core/models/TextFormatModel.php b/src/core/models/TextFormatModel.php index bdb197dac6e..96b3086fb47 100755 --- a/src/core/models/TextFormatModel.php +++ b/src/core/models/TextFormatModel.php @@ -33,20 +33,13 @@ class TextFormatModel public static function formatDate($date) { - $last_date = ''; - - if (!empty($date)) { - if (strpos($date, " ")) { - $date_ex = explode(" ", $date); - $the_date = explode("-", $date_ex[0]); - $last_date = $the_date[2]."-".$the_date[1]."-".$the_date[0]; - } else { - $the_date = explode("-", $date); - $last_date = $the_date[2]."-".$the_date[1]."-".$the_date[0]; - } + if (empty($date)) { + return ''; } - return $last_date; + $date = new \DateTime($date); + + return $date->format('d-m-Y H:i'); } public static function removeAccent(array $aArgs) -- GitLab