diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 7bb040814714eeaa7b6f4400ef84d3e98391cccf..07454958430468ebbd63583d543c447d8defcabc 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -951,15 +951,11 @@ class DynamicFormEntry extends VerySimpleModel { } function setAnswer($name, $value, $id=false) { - foreach ($this->getAnswers() as $ans) { + + if ($ans=$this->getAnswer($name)) { $f = $ans->getField(); - if ($f->isStorable() && $f->get('name') == $name) { - $f->reset(); - $ans->set('value', $value); - if ($id !== false) - $ans->set('value_id', $id); - break; - } + if ($f->isStorable()) + $ans->setValue($value, $id); } } @@ -1359,6 +1355,14 @@ class DynamicFormEntryAnswer extends VerySimpleModel { return $this->_value; } + function setValue($value, $id=false) { + $this->getField()->reset(); + $this->_value = null; + $this->set('value', $value); + if ($id !== false) + $this->set('value_id', $id); + } + function getLocal($tag) { return $this->field->getLocal($tag); } diff --git a/include/class.orm.php b/include/class.orm.php index 3e7dc64dfaab83eebc7b583cf522fd48e8463ea8..a928f222c9d3a7a84e5ecdd054630e33602c63f7 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -1468,6 +1468,13 @@ implements IteratorAggregate, Countable, ArrayAccess { } } + function reset() { + $this->eoi = false; + $this->cache = array(); + // XXX: Should the inner be recreated to refetch? + $this->inner->rewind(); + } + function asArray() { $this->fillTo(PHP_INT_MAX); return $this->getCache(); @@ -1908,11 +1915,6 @@ extends ModelResultSet { $object->set($field, null); } - function reset() { - $this->cache = array(); - unset($this->resource); - } - /** * Slight edit to the standard iteration method which will skip deleted * items. diff --git a/include/class.ticket.php b/include/class.ticket.php index d126259da8b1dbb6604b8ab085c3b5ee066395bb..2afbe818f318ea9a54abdccdcf11db8acec8420b 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -3373,11 +3373,9 @@ implements RestrictedAccess, Threadable { // Save the (common) dynamic form // Ensure we have a subject $subject = $form->getAnswer('subject'); - if ($subject && !$subject->getValue()) { - if ($topic) { - $form->setAnswer('subject', $topic->getFullName()); - } - } + if ($subject && !$subject->getValue() && $topic) + $subject->setValue($topic->getFullName()); + $form->setTicketId($ticket->getId()); $form->save();