book_parent.inc
Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 function panels_book_parent_panels_relationships() {
00012 $args['book_parent'] = array(
00013 'title' => t("Book parent"),
00014 'keyword' => 'book_parent',
00015 'description' => t('Adds a book parent from a node context.'),
00016 'required context' => new panels_required_context(t('Node'), 'node'),
00017 'context' => 'panels_book_parent_context',
00018 'settings form' => 'panels_book_parent_settings_form',
00019 'settings form validate' => 'panels_book_parent_settings_form_validate',
00020 );
00021 return $args;
00022 }
00023
00024
00025
00026
00027 function panels_book_parent_context($context = NULL, $conf) {
00028
00029 if (empty($context->data)) {
00030 return panels_context_create_empty('node');
00031 }
00032
00033 if (isset($context->data->parent)) {
00034 if ($conf['type'] == 'top') {
00035
00036 $result = array('nid' => $context->data->nid, 'vid' => $context->data->vid, 'parent' => $context->data->parent);
00037 while (!empty($result['parent'])) {
00038 $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']));
00039 }
00040 $nid = $result['nid'];
00041 }
00042 else {
00043
00044 $nid = $context->data->parent;
00045 }
00046
00047 if (!empty($nid)) {
00048
00049 $node = node_load($nid);
00050
00051 return panels_context_create('node', $node);
00052 }
00053 }
00054 }
00055
00056
00057
00058
00059 function panels_book_parent_settings_form($conf) {
00060 $form['type'] = array(
00061 '#type' => 'select',
00062 '#title' => t('Relationship type'),
00063 '#options' => array('parent' => t('Immediate parent'), 'top' => t('Top level book')),
00064 '#default_value' => $conf['type'],
00065 );
00066
00067 return $form;
00068 }
00069