/** * Populates an element model based on a query result. * * @param array $row * @return array */ public function populateElementModel($row, $normalize = false) { $entry = PlainForm_EntryModel::populateModel($row); if ($normalize) { $entry = $entry->_normalizeDataForElementsTable(); } return $entry; }
/** * Save the form entry element. * @param PlainForm_EntryModel $entry [description] * @return [type] [description] */ public function saveFormEntry(PlainForm_EntryModel $entry) { $entryRecord = new PlainForm_EntryRecord(); // Set attributes $entryRecord->formId = $entry->formId; $entryRecord->data = $entry->data; $entryRecord->ip = $entry->ip; $entryRecord->validate(); $entry->addErrors($entryRecord->getErrors()); if (!$entry->hasErrors()) { $transaction = craft()->db->getCurrentTransaction() === null ? craft()->db->beginTransaction() : null; try { if (craft()->elements->saveElement($entry)) { $entryRecord->id = $entry->id; $entryRecord->save(false); if ($transaction !== null) { $transaction->commit(); } return $entryRecord->id; } else { return false; } } catch (\Exception $e) { if ($transaction !== null) { $transaction->rollback(); } throw $e; } return true; } else { return false; } }