function save() { if (count($this->dirty)) { $this->set('updated', new SqlFunction('NOW')); } parent::save(); foreach ($this->getFields() as $field) { $a = $field->getAnswer(); if ($this->object_type == 'U' && in_array($field->get('name'), array('name', 'email'))) { continue; } if ($this->object_type == 'O' && in_array($field->get('name'), array('name'))) { continue; } // Set the entry ID here so that $field->getClean() can use the // entry-id if necessary $a->set('entry_id', $this->get('id')); $val = $field->to_database($field->getClean()); if (is_array($val)) { $a->set('value', $val[0]); $a->set('value_id', $val[1]); } else { $a->set('value', $val); } // Don't save answers for presentation-only fields if ($field->hasData() && !$field->isPresentationOnly()) { $a->save(); } } $this->_values = null; }
function save($refetch = false) { if (count($this->dirty)) { $this->set('updated', new SqlFunction('NOW')); } if (isset($this->dirty['notes'])) { $this->notes = Format::sanitize($this->notes); } return parent::save($refetch); }
/** * Save the form entry and all associated answers. * * Returns: * (mixed) FALSE if updated failed, otherwise the number of dirty answers * which were save is returned (which may be ZERO). */ function save($refetch = false) { if (count($this->dirty)) { $this->set('updated', new SqlFunction('NOW')); } if (!parent::save($refetch || count($this->dirty))) { return false; } $dirty = 0; foreach ($this->getAnswers() as $a) { $field = $a->getField(); if ($this->object_type == 'U' && in_array($field->get('name'), array('name', 'email'))) { continue; } if ($this->object_type == 'O' && in_array($field->get('name'), array('name'))) { continue; } // Set the entry ID here so that $field->getClean() can use the // entry-id if necessary $a->set('entry_id', $this->get('id')); try { $field->setForm($this); $val = $field->to_database($field->getClean()); } catch (FieldUnchanged $e) { // Don't update the answer. continue; } if (is_array($val)) { $a->set('value', $val[0]); $a->set('value_id', $val[1]); } else { $a->set('value', $val); } // Don't save answers for presentation-only fields if ($field->hasData() && !$field->isPresentationOnly()) { if ($a->dirty) { $dirty++; } $a->save(); } } $this->_values = null; return $dirty; }