You are here

function library_node_presave in Library 7

Implements hook_presave().

This allows devel_generate to successfully create nodes with an item record for library item types. Collisions in barcode numbers can occur.

File

./library.module, line 1627

Code

function library_node_presave($node) {
  if (isset($node->devel_generate)) {
    $types = library_get_item_types();
    $barcode_use = variable_get('library_item_barcodes', LIBRARY_NO_BARCODES);
    if (in_array($node->type, $types)) {
      $num = rand(1, 4);
      $i = 0;
      $node->library_items = array();
      while ($i <= $num) {
        if ($barcode_use == LIBRARY_BARCODES) {
          $node->library_items[$i]['barcode'] = rand(100000, 9999999);
        }
        $node->library_items[$i]['in_circulation'] = rand(0, 1);
        $i++;
      }
    }
  }
}