diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 10419a2099c651e33265d443ccc4dc5ca788e292..a60cf4fd8d9920743ca196303036af3e5eb0ad53 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -1265,13 +1265,14 @@ class DynamicFormEntryAnswer extends VerySimpleModel { } function asVar() { - return (is_object($this->getValue())) - ? $this->getValue() : $this->toString(); + return $this->getField()->asVar( + $this->get('value'), $this->get('value_id') + ); } function getVar($tag) { - if (is_object($this->getValue()) && method_exists($this->getValue(), 'getVar')) - return $this->getValue()->getVar($tag); + if (is_object($var = $this->asVar()) && method_exists($var, 'getVar')) + return $var->getVar($tag); } function __toString() { @@ -1372,6 +1373,15 @@ class SelectionField extends FormField { return $value; } + function asVar($value, $id=false) { + $values = $this->to_php($value, $id); + if (is_array($values)) { + return new PlaceholderList($this->getList()->getAllItems() + ->filter(array('id__in' => array_keys($values))) + ); + } + } + function hasSubFields() { return $this->getList()->getForm(); } diff --git a/include/class.list.php b/include/class.list.php index 5a1092ea1597b94880ce749335ce01e7a8934c8d..950efdb6bc78d585ce65eede5aab5fc03d52ccf5 100644 --- a/include/class.list.php +++ b/include/class.list.php @@ -737,7 +737,7 @@ class DynamicListItem extends VerySimpleModel implements CustomListItem { $name = mb_strtolower($name); foreach ($this->getConfigurationForm()->getFields() as $field) { if (mb_strtolower($field->get('name')) == $name) - return $config[$field->get('id')]; + return $field->asVar($config[$field->get('id')]); } } diff --git a/include/class.ticket.php b/include/class.ticket.php index 98f29976495429535feb60b6d4f138ac925d34ef..dc2d831e1c27fc742eabf4b9416766bdc61d0224 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -294,8 +294,8 @@ implements RestrictedAccess, Threadable, TemplateVariable { if (!$this->_answers) { foreach (DynamicFormEntry::forTicket($this->getId(), true) as $form) { foreach ($form->getAnswers() as $answer) { - $tag = mb_strtolower($answer->getField()->get('name')) - ?: 'field.' . $answer->getField()->get('id'); + $tag = mb_strtolower($answer->field->name) + ?: 'field.' . $answer->field->id; $this->_answers[$tag] = $answer; } } diff --git a/include/class.variable.php b/include/class.variable.php index 051f9f6a5290eb60135fe1f28d525ffe4c0bf697..55fac7a2c41a35a17608a9466d72626fa165fca0 100644 --- a/include/class.variable.php +++ b/include/class.variable.php @@ -212,6 +212,44 @@ class VariableReplacer { } } +class PlaceholderList +/* implements TemplateVariable */ { + var $items; + + function __construct($items) { + $this->items = $items; + } + + function asVar() { + $items = array(); + foreach ($this->items as $I) { + if (method_exists($I, 'asVar')) { + $items[] = $I->asVar(); + } + else { + $items[] = (string) $I; + } + } + return implode(',', $items); + } + + function getVar($tag) { + $items = array(); + foreach ($this->items as $I) { + if (is_object($I) && method_exists($I, 'get'.ucfirst($tag))) { + $items[] = call_user_func(array($I, 'get'.ucfirst($tag))); + } + elseif (method_exists($I, 'getVar')) { + $items[] = $I->getVar($tag); + } + } + if (count($items) == 1) { + return $items[0]; + } + return new static($items); + } +} + interface TemplateVariable { // function asVar(); — not absolutely required // function getVar($name); — not absolutely required