Download & Extend

hierarchical bulk edit for 'book' nodes

Project:Coherent Access
Version:5.x-1.1
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

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

Comments

#1

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

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 ;)

#3

Status:active» closed (fixed)

i don't use coh. access any more. so just getting rid of the old issues.

#4

If anyone's interested, I'm attaching a small module (not yet thoroughly tested) that lets you assign permissions to an entire book's nodes when editing the root node.

This is for Drupal 6 btw.

AttachmentSize
coherent_access_book-18aug2010-janusman.zip 3.39 KB

#5

Improved version of module in #4, for Drupal 6.

From README.TXT

INSTALLATION
============
* You need at least the Book and Coherent Access modules enabled.
* Optionally, you can use the Book Manager contrib module (see below).
* Install like other drupal modules.
* You have to permissions to desired user roles:

  If you only use the core book module, assign "create new books" and
  "add content to books".

  If you use the Book Manager contrib module, you can opt to use that module's
  "add content to personal books" and "create personal books" instead.

* There are [currently] no admin options nor permissions.

USAGE
=====
All nodetypes controlled by Coherent Access, that are part of book hierarchies,
will automatically recieve grants.

EXAMPLE
=======
Say you have a book hierarchy consisting of:

    node/1
      node/2
      node/3
        node/4

If you go to node/1/edit (and have edit permissions), and this node type has been
enabled in Coherent Acess, you will see the normal "Shared editing" fieldset.

If you add user1 and user2 to be editors, and then hit save, then all nodes in
the book hierarchy (1,2,3,4) will also be editable by user1 and user2.

TODO
====
* Buggy/weird use case:
    - Book root node is not owned by current user
    - Book root node is not private (viewable by all)
    - You are not viewer nor editor to that book
    - You create a child node
        mark it "private"
        and assign it to that book
    - After saving, the child node is assigned to the book where you specified,
      but you can't view the node ("Access denied"). Also, the book's owner
      probably didn't want you to put stuff in there either.

    If you do the same but mark your new node non-"private", then you will be
    able to see the node, and also edit it. The problem would only be you
    putting stuff into places you were not invited to =)

  This happens either with the core book module or with the Book Manager module.

  Possible solution: use an after_build form function to (?) hide the option
  from the book selector.

AttachmentSize
coherent_access_book-23aug2010.zip 4.95 KB
nobody click here