book_parent.inc

Go to the documentation of this file.
00001 <?php
00002 // $Id: book_parent.inc,v 1.1.2.5 2008/05/27 20:21:14 sdboyer Exp $
00003 
00004 
00005 /**
00006  * @file relationships/book_parent.inc
00007  *
00008  * Plugin to provide an relationship handler for book parent
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  * Return a new context based on an existing context
00026  */
00027 function panels_book_parent_context($context = NULL, $conf) {
00028   // If unset it wants a generic, unfilled context, which is just NULL
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       // Search through the book tree to load the top level.
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       // Just load the parent book.
00044       $nid = $context->data->parent;
00045     }
00046 
00047     if (!empty($nid)) {
00048       // load the node
00049       $node = node_load($nid);
00050       // Generate the context.
00051       return panels_context_create('node', $node);
00052     }
00053   }
00054 }
00055 
00056 /**
00057  * Settings form for the relationship
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 

Generated on Thu Sep 9 05:00:15 2010 for Panels 2 by  doxygen 1.5.6