public function create($fields)
{
// If configured to record creation and update times, set them
// here. We set updated_at to the initial creation time so it's
// always set.
if ($this->_setTimestamps) {
$time = time();
$fields['created_at'] = $time;
$fields['updated_at'] = $time;
}
// Filter out any extra fields.
$fields = array_intersect_key($fields, array_flip($this->tableDefinition->getColumnNames()));
if (!$fields) {
throw new Horde_Rdo_Exception('create() requires at least one field value.');
}
$sql = 'INSERT INTO ' . $this->adapter->quoteTableName($this->table);
$keys = array();
$placeholders = array();
$bindParams = array();
foreach ($fields as $field => $value) {
$keys[] = $this->adapter->quoteColumnName($field);
$placeholders[] = '?';
$bindParams[] = $value;
}
$sql .= ' (' . implode(', ', $keys) . ') VALUES (' . implode(', ', $placeholders) . ')';
$id = $this->adapter->insert($sql, $bindParams);
return $this->map(array_merge($fields, array($this->primaryKey => $id)));
}