You are here

function library_node_insert in Library 7

Implements hook_node_insert().

As a new node is being inserted into the database, we need to do our own database inserts.

File

./library.module, line 645

Code

function library_node_insert($node) {
  if (variable_get('library_' . $node->type, LIBRARY_ITEM_NOT_IN_LIBRARY) == LIBRARY_ITEM_IN_LIBRARY) {
    $items = $node->library_items;
    if ($items) {
      foreach ($items as $key => $item) {
        if (!isset($item['delete']) || isset($item['delete']) && $item['delete'] != 1) {

          // Notice that we are ignoring any revision information
          // using $node->nid.
          $nid = db_insert('library')
            ->fields(array(
            'nid' => $node->nid,
            'barcode' => isset($item['barcode']) ? check_plain($item['barcode'] . '') : '',
            'in_circulation' => $item['in_circulation'],
            'library_status' => LIBRARY_ITEM_AVAILABLE,
            'notes' => check_plain($item['notes'] . ''),
            'created' => REQUEST_TIME,
          ))
            ->execute();
        }
      }
    }
  }
}