From 97a938f119cb6d8cbb4ee208d60841cf8d65fdec Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 25 Aug 2016 18:35:01 -0700 Subject: [PATCH] Method helper to translate piped field_values into a useable array --- app/Models/CustomField.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index fb3f824668..fdf3f26714 100644 --- a/app/Models/CustomField.php +++ b/app/Models/CustomField.php @@ -109,4 +109,27 @@ class CustomField extends Model $this->attributes['format']=$value; } } + + /** + * Format a value string as an array for select boxes and checkboxes. + * + * @author [A. Gianotto] [] + * @since [v3.4] + * @return Array + */ + public function formatFieldValuesAsArray() { + $arr = preg_split("/\\r\\n|\\r|\\n/", $this->field_values); + + for ($x = 0; $x < count($arr); $x++) { + $arr_parts = explode('|', $arr[$x]); + + if (key_exists('1',$arr_parts)) { + $result[$arr_parts[0]] = $arr_parts[1]; + } else { + $result[$arr_parts[0]] = $arr_parts[0]; + } + } + + return $result; + } }