/[drupal]/contributions/modules/og_book/og_book.module
ViewVC logotype

Diff of /contributions/modules/og_book/og_book.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.4, Mon Jan 23 22:41:56 2006 UTC revision 1.4.2.1, Wed Jul 1 04:33:26 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: og_book.module,v 1.3 2006/01/20 22:22:17 weitzman Exp $  /*
3     * Implementation of hook_help.
 /**  
  * @file  
  * Creates a book per organic group  
  */  
   
 /**  
  * Implementation of hook_help().  
4   */   */
5  function og_book_help($section) {  function og_book_help($path, $arg) {
6    switch ($section) {    switch ($path) {
7      case 'admin/modules#description':      case 'admin/modules#description':
8        return t('Gives each organic group its own book.');        return t('Organic group books.');
   }  
 }  
   
 /**  
  * Implementation of hook_nodeapi().  
  *  
  * Automatically creates a corresponding top level book page each time an organic group is added.  
  */  
 function og_book_nodeapi($group_node, $op, $teaser = NULL) {  
   switch ($op) {  
     case 'insert':  
       if ($group_node->type == 'og') {  
         $og_public = og_get_visibility_default();  
         $node = array('title' => $group_node->title. ' '. t('Handbook'),  
                       'uid' => $group_node->uid,  
                       'type' => 'book',  
                       'status' => 1,  
                       'og_groups' => array($group_node->nid => 1),  
                       'og_public' => $og_public,  
                       'log' => t('automatically created for use within the \'%name\' group', array('%name' => $group_node->title)),  
                       'parent' => 0,  
                       );  
         if ($node = node_submit($node)) {  
           node_save($node);  
         }  
         $sql = "INSERT INTO {og_book} (og_nid, book_nid) VALUES (%d, %d)";  
         db_query($sql, $group_node->nid, $node->nid);  
       }  
9        break;        break;
10      case 'delete':      case 'admin/modules#name':
11        if ($node->type == 'og') {        return 'og_book';
         $sql = "DELETE FROM {og_book} WHERE og_nid = %d";  
         db_query($sql, $node->nid);  
       }  
12        break;        break;
13        case 'admin/help#modulename':
14          return t("The Organic group Book module restricts the outline to books within your groups.");
15          break;
16        default: return null;
17    }    }
18  }  }
19    
20  /**  function og_book_form_alter(&$form, &$form_state, &$form_id) {
21   * Only show this group's book in the 'parent' dropdown list on the book form    if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
22   *      if(!user_access('edit any book structre')){
23   * @param string $form_id  
24   * @param array $form        $node = $form['#node'];
25   */        global $user;
26  function og_book_form_alter($form_id, &$form) {  
27    global $og_book_options;        $subs = og_get_subscriptions($user->uid);
28    
29    $group_node = og_get_group_context();        $result = db_query("SELECT b.nid AS bid, oga.group_nid AS gnid from {book} b LEFT JOIN {og_ancestry} oga ON b.nid = oga.nid");
30    if ($form_id == 'book_node_form' && $group_node) {        while($row = db_fetch_array($result)) {
31      og_book_get_options($group_node->nid);        if($row['gnid'] != NULL) {
32      $form['parent'] = array(            if(!$subs[$row['gnid']]) {
33        '#type' => 'select',              unset($form['book']['bid']['#options'][$row['bid']]);
34        '#title' => t('Parent'),            }
35        '#default_value' => ($node->parent ? $node->parent : arg(4)),          }
36        '#options' => $og_book_options,        }
37        '#weight' => -4,  
38        '#description' => t('The parent that this page belongs in.')        $nid = isset($node->nid) ? $node->nid : 'new';
39        );        if (!user_access('create new books') && user_access('create personal books')  && ($nid == 'new' || ($nid != $node->book['original_bid']))) {
40            $form['book']['bid']['#options'] = array($nid  => '<'. t('create new book') .'>') + $form['book']['bid']['#options'];
41          }
42        }
43    }    }
44  }  }
   
 function og_book_get_options($gid) {  
         $root_nid = og_book_get_root($gid);  
   book_recurse($root_nid, 9, 'og_book_pre', 'og_book_post');  
 }  
   
 function og_book_get_root($gid) {  
   $sql = "SELECT book_nid FROM {og_book} WHERE og_nid = %d";  
   return db_result(db_query($sql, $gid));  
 }  
   
   
 /**  
  * A useless callback which prevents default book renderer from being called (see book_recurse())  
  *  
  * @return unknown  
  */  
 function og_book_post() {  
   return NULL;  
 }  
   
 /**  
  * A callback for book_recurse() when called from og_book_form_alter(). Track  
  * all returned nodes and build an 'options' array for the select box  
  *  
  * @param unknown_type $node  
  * @param unknown_type $depth  
  * @param unknown_type $nid  
  */  
 function og_book_pre($node, $depth, $nid = NULL) {  
   global $og_book_options;  
   static $pedigree;  
   
   $pedigree[$nid]['parent'] = $node->parent;  
   $pedigree[$nid]['depth'] = $pedigree[$node->parent]['depth']+1;  
   $og_book_options[$node->nid] = str_repeat('--', $pedigree[$nid]['depth']-1). $node->title;  
 }  
45    ~

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.4.2.1

  ViewVC Help
Powered by ViewVC 1.1.2