mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Method helper to translate piped field_values into a useable array
This commit is contained in:
parent
308fcf96de
commit
97a938f119
|
@ -109,4 +109,27 @@ class CustomField extends Model
|
||||||
$this->attributes['format']=$value;
|
$this->attributes['format']=$value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a value string as an array for select boxes and checkboxes.
|
||||||
|
*
|
||||||
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue