You are here

function _mostpopular_save in Drupal Most Popular 7

4 calls to _mostpopular_save()
mostpopular_blocks_admin_form_submit in ./mostpopular.blocks.inc
mostpopular_block_save in ./mostpopular.module
Implements hook_block_save().
mostpopular_interval_save in ./mostpopular.module
mostpopular_service_save in ./mostpopular.module

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);
}