Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1207622
in-portal
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Nov 9, 1:11 AM
Size
2 KB
Mime Type
text/x-diff
Expires
Tue, Nov 11, 1:11 AM (7 h, 7 m)
Engine
blob
Format
Raw Data
Handle
788826
Attached To
rINP In-Portal
in-portal
View Options
Index: branches/RC/core/kernel/utility/formatters/options_formatter.php
===================================================================
--- branches/RC/core/kernel/utility/formatters/options_formatter.php (revision 10094)
+++ branches/RC/core/kernel/utility/formatters/options_formatter.php (revision 10095)
@@ -1,48 +1,72 @@
<?php
class kOptionsFormatter extends kFormatter {
function Format($value, $field_name, &$object, $format=null)
{
- if ( is_null($value) ) return '';
+ if ( is_null($value) ) {
+ return '';
+ }
- $options = $object->GetFieldOptions($field_name);
+ $field_options = $object->GetFieldOptions($field_name);
+ if (!array_key_exists('options', $field_options) || !is_array($field_options['options'])) {
+ trigger_error('Options not defined for <strong>'.$object->Prefix.'</strong> field <strong>'.$field_name.'</strong>', E_USER_WARNING);
+ return $value;
+ }
+
+ $options = $field_options['options'];
+ $use_phrases = array_key_exists('use_phrases', $field_options) ? $field_options['use_phrases'] : false;
+
+ if (strpos($value, '|') !== false) {
+ // multiple checkboxes OR multiselect
+ $values = explode('|', substr($value, 1, -1) );
+ $labels = Array ();
+ foreach ($values as $value) {
+ $label = $this->formatOption($value, $options, $use_phrases);
+ if ($label) {
+ $labels[] = $label;
+ }
+ }
+
+ return implode($format, $labels);
+ }
+ else {
+ return $this->formatOption($value, $options, $use_phrases);
+ }
+ }
- $label = getArrayValue($options['options'], $value);
+ function formatOption($value, $options, $use_phrases = true)
+ {
+ $label = getArrayValue($options, $value);
if ($label !== false) {
// option_id found in options array
- if (getArrayValue($options, 'use_phrases')) {
- return $this->Application->Phrase($label);
- }
- else {
- return $label;
- }
+ return $use_phrases ? $this->Application->Phrase($label) : $label;
}
else {
// option_id not found
return "$value" == "0" ? '' : $value;
}
}
function Parse($value, $field_name, &$object)
{
if ($value == '') return NULL;
$options = $object->GetFieldOptions($field_name);
$use_phrases = getArrayValue($options, 'use_phrases');
$found = false;
foreach ($options['options'] as $option_key => $option_value) {
if ($use_phrases) {
$option_value = $this->Application->Phrase($option_value);
}
if ($option_value == $value) {
$found = true;
break;
}
}
return $found ? $option_key : $value;
}
}
\ No newline at end of file
Property changes on: branches/RC/core/kernel/utility/formatters/options_formatter.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.1.32.2
\ No newline at end of property
+1.1.32.3
\ No newline at end of property
Event Timeline
Log In to Comment