Explicit, non hierarchy kategory writing-right structure

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
jules
Regular
Posts: 7
Joined: Tue Aug 22, 2006 8:18 pm

Explicit, non hierarchy kategory writing-right structure

Post 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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Explicit, non hierarchy kategory writing-right structure

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
jules
Regular
Posts: 7
Joined: Tue Aug 22, 2006 8:18 pm

Post 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 )
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

I ask that myself from time to time ;)

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply