You are here

function panels_book_parent_context in Panels 6.2

Same name and namespace in other branches
  1. 5.2 relationships/book_parent.inc \panels_book_parent_context()

Return a new context based on an existing context

1 string reference to 'panels_book_parent_context'
panels_book_parent_panels_relationships in relationships/book_parent.inc
@file relationships/book_parent.inc

File

relationships/book_parent.inc, line 26
relationships/book_parent.inc

Code

function panels_book_parent_context($context = NULL, $conf) {

  // If unset it wants a generic, unfilled context, which is just NULL
  if (empty($context->data)) {
    return panels_context_create_empty('node');
  }
  if (isset($context->data->parent)) {
    if ($conf['type'] == 'top') {

      // Search through the book tree to load the top level.
      $result = array(
        'nid' => $context->data->nid,
        'vid' => $context->data->vid,
        'parent' => $context->data->parent,
      );
      while (!empty($result['parent'])) {
        $result = db_fetch_array(db_query("SELECT * FROM {book} b INNER JOIN {node} n ON b.vid = n.nid WHERE b.nid = %d", $result['parent']));
      }
      $nid = $result['nid'];
    }
    else {

      // Just load the parent book.
      $nid = $context->data->parent;
    }
    if (!empty($nid)) {

      // load the node
      $node = node_load($nid);

      // Generate the context.
      return panels_context_create('node', $node);
    }
  }
}