function _mostpopular_save in Drupal Most Popular 7
4 calls to _mostpopular_save()
File
- ./
mostpopular.module, line 282 - The main file for the Most Popular module.
Code
function _mostpopular_save($type, &$object) {
if (!is_object($object)) {
$object = (object) $object;
}
// Get information about the table
$table = "mostpopular_{$type}";
$schema = drupal_get_schema($table);
// Find the object's ID
foreach ($schema['fields'] as $key => $field) {
if ($field['type'] == 'serial') {
$id = $key;
}
elseif (!empty($field['serialize'])) {
$data = $key;
}
}
// Create a data element if necessary
if (isset($data) && !isset($object->{$data})) {
$object->{$data} = array();
}
// Now, invoke the callbacks and save the object
module_invoke_all("{$table}_presave", $object);
if (!empty($object->{$id})) {
drupal_write_record($table, $object, array(
$id,
));
$status = 'update';
}
else {
drupal_write_record($table, $object);
$status = 'insert';
}
module_invoke_all("{$table}_{$status}", $object);
}