public function update($object, $fields = null)
{
if ($object instanceof Horde_Rdo_Base) {
$key = $this->primaryKey;
$id = $object->{$key};
$fields = iterator_to_array($object);
if (!$id) {
// Object doesn't exist yet; create it instead.
$o = $this->create($fields);
$this->mapFields($object, iterator_to_array($o));
return 1;
}
} else {
$id = $object;
}
// If configured to record update time, set it here.
if ($this->_setTimestamps) {
$fields['updated_at'] = time();
}
// Filter out any extra fields.
$fields = array_intersect_key($fields, array_flip($this->tableDefinition->getColumnNames()));
if (!$fields) {
// Nothing to change.
return 0;
}
$sql = 'UPDATE ' . $this->adapter->quoteTableName($this->table) . ' SET';
$bindParams = array();
foreach ($fields as $field => $value) {
$sql .= ' ' . $this->adapter->quoteColumnName($field) . ' = ?,';
$bindParams[] = $value;
}
$sql = substr($sql, 0, -1) . ' WHERE ' . $this->primaryKey . ' = ?';
$bindParams[] = $id;
return $this->adapter->update($sql, $bindParams);
}