Bug #7247
Tx_Formhandler_View_Form and wrong $level in getValueMarkers
| Status: | Closed | Start date: | 2010-04-14 | |
|---|---|---|---|---|
| Priority: | Should have | Due date: | ||
| Assignee: | Reinhard Führicht | % Done: | 0% |
|
| Category: | View | |||
| Target version: | Beta 5 (v0.9.8) | |||
| Votes: | 0 |
Description
First calling a Tx_Formhandler_Finisher_DB
after this calling Tx_Formhandler_Finisher_Mail.
Tx_Formhandler_Finisher_DB sets an array into gp Vars.
Tx_Formhandler_View_Form producing wrong value_markers after this
because $level is not reset in foreach().
class Tx_Formhandler_View_Form{
protected function getValueMarkers($values, $level = 0, $prefix = 'value_') {
#debugster($values);
$markers = array();
if (is_array($values)) {
foreach($values as $k => $v) {
$currPrefix = $prefix;
###########NEED a reset of level here##############
// Otherwise all entries after an array also get a |
$level = 0;
if($level === 0) {
$currPrefix .= $k;
} else {
$currPrefix .= '|' . $k;
}
if (is_array($v)) {
$level = $level + 1;
$markers = array_merge($markers, $this->getValueMarkers($v, $level, $currPrefix));
$v = implode(',', $v);
}
$v = trim($v);
$markers['###' . $currPrefix . '###'] = $v;
$markers['###' . strtoupper($currPrefix) . '###'] = $v;
}
}
debugster($markers);
return $markers;
}
History
Updated by Carsten Bleicker about 3 years ago
protected function getValueMarkers($values, $level = 0, $prefix = 'value_') {
// using internal level not func_arg
$local_level = $level;
$markers = array();
if (is_array($values)) {
foreach($values as $k => $v) {
$currPrefix = $prefix;
if($local_level === 0) {
$currPrefix .= $k;
} else {
$currPrefix .= '|' . $k;
}
if (is_array($v)) {
$level = $local_level + 1;
$markers = array_merge($markers, $this->getValueMarkers($v, $level, $currPrefix));
$v = implode(',', $v);
}
$v = trim($v);
$markers['###' . $currPrefix . '###'] = $v;
$markers['###' . strtoupper($currPrefix) . '###'] = $v;
}
}
return $markers;
}Updated by Reinhard Führicht about 3 years ago
- Category set to View
- Status changed from New to Needs Feedback
- Assignee set to Reinhard Führicht
- Target version set to Beta 5 (v0.9.8)
If I understood correctly it should be enough to just remove $level as func_arg completely and use $level as local variable only.
Right?
protected function getValueMarkers($values, $prefix = 'value_') {
$markers = array();
if (is_array($values)) {
foreach($values as $k => $v) {
$level = 0;
$currPrefix = $prefix;
if($level === 0) {
$currPrefix .= $k;
} else {
$currPrefix .= '|' . $k;
}
if (is_array($v)) {
$level = $level + 1;
$markers = array_merge($markers, $this->getValueMarkers($v, $currPrefix));
$v = implode(',', $v);
}
$v = trim($v);
$markers['###' . $currPrefix . '###'] = $v;
$markers['###' . strtoupper($currPrefix) . '###'] = $v;
}
}
return $markers;
}
Updated by Carsten Bleicker about 3 years ago
Reinhard Führicht wrote:
If I understood correctly it should be enough to just remove $level as func_arg completely and use $level as local variable only. Right?
[...]
not remove, but
// $level = $level+1;
$markers = array_merge($markers, $this->getValueMarkers($v, $level+1, $currPrefix));
this should be enough
Updated by Reinhard Führicht about 3 years ago
I just fixed #7448. I think this should fix this issue too.
Could you please double check before I close this issue?
The changes are simple:
Notice the $level-- after the recursive call.
protected function getValueMarkers($values, $level = 0, $prefix = 'value_') {
$markers = array();
if (is_array($values)) {
foreach($values as $k => $v) {
$currPrefix = $prefix;
if($level === 0) {
$currPrefix .= $k;
} else {
$currPrefix .= '|' . $k;
}
if (is_array($v)) {
$level++;
$markers = array_merge($markers, $this->getValueMarkers($v, $level, $currPrefix));
$v = implode(',', $v);
$level--;
}
$v = trim($v);
$markers['###' . $currPrefix . '###'] = $v;
$markers['###' . strtoupper($currPrefix) . '###'] = $v;
}
}
return $markers;
}
Updated by Reinhard Führicht almost 3 years ago
- Status changed from Needs Feedback to Closed