Page 1 of 1

Explicit, non hierarchy kategory writing-right structure

Posted: Fri Aug 25, 2006 2:07 am
by jules
Hi,

I am actually looking for a possibility to work around the sy9´s writing-right category hierarchy. During the creation of my category structure I found out that a writer of a subcategory has to have writing rights on the higher category as well. For my needs, I would like to do it the other way round, or to give writing rights explicit to (sub)categories without restrictive hierarchy.

Is it possible to do that without massive codemodifications? Have I maybe missed some plugin or configuration to do that?

Following a "graphical" description of what I want to do:

Code: Select all

---------[no category]      wished writers-groups:
 |
 --------main category      - a
  |
  -------first Subcategory  - a,b
  | |
  | -----1. sub             - a,b,c
  | |
  | -----2. sub             - a,b,d
  |   |
  |   ---1. sub-sub         - a,b,c,d,e
  |
  -------second subcategory - a,f

Re: Explicit, non hierarchy kategory writing-right structure

Posted: Fri Aug 25, 2006 12:46 pm
by garvinhicking
Hi!

Well, the basic problem of this is not the permission scheme. In fact you can assign permissions like you did.

The problem is the indented, tree-like display of categories. If you do not have write access to a parent category, how do you display its children in the category dropdown? You can't, actually, because you have no parent to assign it to. You would then need to display the parent category in the dropdown, but then readers would think they could choose that category to write into.

Thus, the only solution that I know would be to display the "missing" categories unindented.

A patch to do this is here; just edit your include/functions.inc.php and replace this function with the code below:

Code: Select all

function serendipity_walkRecursive($ary, $child_name = 'id', $parent_name = 'parent_id', $parentid = 0, $depth = 0) {
    global $serendipity;
    static $_resArray;
    static $_remain;

    if (sizeof($ary) == 0) {
        return array();
    }

    if ($parentid === VIEWMODE_THREADED) {
        $parentid = 0;
    }

    if ($depth == 0) {
        $_resArray = array();
        $_remain   = $ary;
    }

    foreach($ary AS $key => $data) {
        if ($parentid === VIEWMODE_LINEAR || !isset($data[$parent_name]) || $data[$parent_name] == $parentid) {
            $data['depth'] = $depth;
            $_resArray[]   = $data;
            unset($_remain[$key]);
            if ($data[$child_name] && $parentid !== VIEWMODE_LINEAR ) {
                serendipity_walkRecursive($ary, $child_name, $parent_name, $data[$child_name], ($depth+1));
            }
        }
    }

    /* We are inside a recusive child, and we need to break out */
    if ($depth !== 0) {
        return true;
    }
    
    if (count($_remain) > 0) {
        // Remaining items need to be appended
        foreach($_remain AS $key => $data) {
            $data['depth'] = 0;
            $_resArray[]   = $data;
        }
    }

    return $_resArray;
}
HTH,
Garvin

Posted: Fri Aug 25, 2006 6:09 pm
by jules
Garvin!

This is fantastic. I will give it a try as soon as I am at home.

(Question: How can you still develop besides doing that great support here? :D )

Posted: Fri Aug 25, 2006 10:10 pm
by garvinhicking
Hi!

I ask that myself from time to time ;)

Best regards,
Garvin