hierarchical bulk edit for 'book' nodes

freddyseubert - April 2, 2009 - 11:38
Project:Coherent Access
Version:5.x-1.1
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Hello everyone!

I am building a community where several professors and assistant professors are able to edit their lecture notes (standard book nodes). Coherent access provides the mentioned ability and works like a charm. There is only one thing I am missing:

A kind of mass edit mode for the complete hierarchy of a book.

Example: Prof. A creates a lecture note over half a year. There are now 50 book-nodes built. After that time, he decides to grant his new assistant prof. the rights to edit his lecture nodes. Without the bulk edit mode, he has to edit the coherent access rights of 50 nodes (which is quite a lot of work). With the bulk edit mode he would just edit the main node, activate a checkbox "complete hierarchy", chose the desired user name, click "Add Editor" and have a nice day ;)

So any help is appreciated, thanks in advance,

Freddy

#1

freddyseubert - April 3, 2009 - 10:24

And in addition to that: the mentioned mass edit ability would be also nice to have in the viewers section. So that a prof. can easily add students to the viewers list of a complete book structure..

#2

freddyseubert - April 6, 2009 - 11:25

So I think it's up to me... :/

In the beginning we introduce a global variable like

<?php
global $hierarchicalEdit;
?>

Then we need a form element like a checkbox:

<?php
   
// show checkbox for bulk edit the complete hierarchy
   
$form['shared_editing']['hierarchical'] = array(
     
'#type' => 'checkbox',
     
'#title' => t('Complete hierarchy (book nodes)'),
     
'#description' => t('Bulk mode for book nodes.'),
     
'#default_value' => FALSE,
    );
?>

I'll put this between the "$form['shared_editing']['private']" and "$form['shared_editing']['edit']" elements.

In the function coherent_access_form_after_build we add the following line quite in the beginning:

<?php
 
global $hierarchicalEdit;
 
// for bulk editing book nodes in hierarchy
 
if ($form['shared_editing']['hierarchical']['#value']) {
   
$hierarchicalEdit = TRUE;
  } else {
   
$hierarchicalEdit = FALSE;
  }
?>

Next, we need a function that returns all nid of nodes in the hierarchy with the edited node as parent (or grandparent and so on)...

I think this should do this?!

<?php
// return an array of nid with the edited node as parent (or grandparent and so on) OR just the node id if bulk mode not selected
function coherent_access_hierarchical_edit($node_id) {
  global
$hierarchicalEdit;
 
$collectedNIDs[] = $node_id;
  if(
$hierarchicalEdit){
    while(
book_next(end($collectedNIDs))){
     
$collectedNIDs[] = book_next(end($collectedNIDs));
    }
  }
  return
$collectedNIDs;
}
?>

Done. Then we have to edit the function coherent_access_nodeapi... In the first line we write

<?php
global $hierarchicalEdit;
?>
and where it says
<?php
case 'update':
?>
we write

<?php
if($hierarchicalEdit) {
           
$nodeIDs = coherent_access_hierarchical_edit($node->nid);
            foreach(
$nodeIDs as $myID){
               
$gids = coherent_access_get_gids($myID);
               
$filler = array_fill(0, count($gids), '%d');
               
$result = db_query('SELECT cau.uid, cag.mode FROM {coherent_access_user} cau LEFT JOIN {coherent_access_gid} cag ON cau.gid = cag.gid WHERE cag.gid IN('. implode(',', $gids) .')');
               
$existing = array();
                while (
$row = db_fetch_array($result)) {
                 
$existing[$row['uid']] = $row['mode'];
                }
               
db_query('DELETE FROM {coherent_access_user} WHERE gid IN('. implode(',', $gids) .')');
            }
        }
?>

But even if this looks quite correct to me, it is NOT working :/ Any suggestions? Pleeeaaaase help me ;)

 
 

Drupal is a registered trademark of Dries Buytaert.