From e09256c3db5a7a081223c7dbeb6ed0ebb6489cfb Mon Sep 17 00:00:00 2001 From: Sergey Zhidkov Date: Wed, 23 Oct 2019 19:06:25 +0300 Subject: [PATCH] Added the output format for values - "options". Analogous to "boolean", only any text or numeric values can act as a source value (often flags are stored in the database). The format allows you to specify different outputs depending on the value. options: search.On the search|network.In networks Look at this as an associative array in which the key is separated from the value by a dot. Array elements are separated by a vertical line. --- .../Revisionable/FieldFormatter.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Venturecraft/Revisionable/FieldFormatter.php b/src/Venturecraft/Revisionable/FieldFormatter.php index b9572c34..3cf89d88 100644 --- a/src/Venturecraft/Revisionable/FieldFormatter.php +++ b/src/Venturecraft/Revisionable/FieldFormatter.php @@ -117,4 +117,29 @@ public static function datetime($value, $format = 'Y-m-d H:i:s') return $datetime->format($format); } + + /** + * Format options + * + * @param string $value + * @param string $format + * @return string + */ + public static function options($value, $format) + { + $options = explode('|', $format); + + $result = []; + + foreach ($options as $option) { + $transform = explode('.', $option); + $result[$transform[0]] = $transform[1]; + } + + if (isset($result[$value])) { + return $result[$value]; + } + + return 'undefined'; + } }