You are here

function headerimage_node_update in Header image 7

Implementation of hook_node_update().

File

./headerimage.module, line 613
headerimage.module Conditionally display an node in a block.

Code

function headerimage_node_update($node) {
  if (!empty($node->type) && in_array($node->type, variable_get('headerimage_node_type', array()), true)) {
    $conditions = headerimage_node_conditions($node);

    // Check if entry already exists
    $query = db_select('headerimage', 'h')
      ->condition('h.nid', $node->nid);
    $count = $query
      ->countQuery()
      ->execute()
      ->fetchField();
    if ($count) {
      db_update('headerimage')
        ->fields(array(
        'block' => $node->headerimage_block,
        'weight' => $node->headerimage_weight,
        'conditions' => serialize($conditions),
      ))
        ->condition('nid', $node->nid)
        ->execute();
    }
    else {
      db_insert('headerimage')
        ->fields(array(
        'nid' => $node->nid,
        'block' => $node->headerimage_block,
        'weight' => $node->headerimage_weight,
        'conditions' => serialize($conditions),
      ))
        ->execute();
    }
  }
}